]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add LzmaCustomDecompressLib based on the LZMA SDK 4.65 which was
authorjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 1 May 2009 00:28:19 +0000 (00:28 +0000)
committerjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 1 May 2009 00:28:19 +0000 (00:28 +0000)
placed in the public domain on 2009-02-03. The LZMA SDK
4.65 was released at the http://www.7-zip.org/sdk.html
website.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8227 6f19259b-4bc3-4df7-8a09-765794883524

22 files changed:
IntelFrameworkModulePkg/Include/Guid/LzmaDecompress.h [new file with mode: 0644]
IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec
IntelFrameworkModulePkg/IntelFrameworkModulePkg.dsc
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Dxe/LzmaCustomDecompressLib.inf [new file with mode: 0644]
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Dxe/LzmaDxeMemory.c [new file with mode: 0644]
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/GuidedSectionExtraction.c [new file with mode: 0644]
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LZMA-SDK-README.txt [new file with mode: 0644]
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompress.c [new file with mode: 0644]
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompress.h [new file with mode: 0644]
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Pei/LzmaCustomDecompressLib.inf [new file with mode: 0644]
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Pei/LzmaPeiMemory.c [new file with mode: 0644]
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/7zVersion.h [new file with mode: 0644]
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/CpuArch.h [new file with mode: 0644]
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzFind.c [new file with mode: 0644]
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzFind.h [new file with mode: 0644]
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzHash.h [new file with mode: 0644]
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzmaDec.c [new file with mode: 0644]
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzmaDec.h [new file with mode: 0644]
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Types.h [new file with mode: 0644]
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/history.txt [new file with mode: 0644]
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/lzma.txt [new file with mode: 0644]
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/UefiLzma.h [new file with mode: 0644]

diff --git a/IntelFrameworkModulePkg/Include/Guid/LzmaDecompress.h b/IntelFrameworkModulePkg/Include/Guid/LzmaDecompress.h
new file mode 100644 (file)
index 0000000..b64d036
--- /dev/null
@@ -0,0 +1,30 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2007, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+\r
+  LzmaDecompress.h\r
+\r
+Abstract:\r
+\r
+  Lzma Custom decompress algorithm Guid definitions\r
+\r
+--*/\r
+\r
+#ifndef __LZMA_DECOMPRESS_GUID_H__\r
+#define __LZMA_DECOMPRESS_GUID_H__\r
+\r
+#define LZMA_CUSTOM_DECOMPRESS_GUID  \\r
+  { 0xEE4E5898, 0x3914, 0x4259, { 0x9D, 0x6E, 0xDC, 0x7B, 0xD7, 0x94, 0x03, 0xCF } }\r
+\r
+extern GUID gLzmaCustomDecompressGuid;\r
+\r
+#endif\r
index 16c8c912a4568f26509ff4552c328451262a602f..80c9f4e564a6e85ab6d43fe0dbaa0b64ca3668e6 100644 (file)
@@ -51,6 +51,9 @@
   ## Include/Guid/CustomDecompress.h\r
   gTianoCustomDecompressGuid     = { 0xA31280AD, 0x481E, 0x41B6, { 0x95, 0xE8, 0x12, 0x7F, 0x4C, 0x98, 0x47, 0x79 }}\r
   \r
   ## Include/Guid/CustomDecompress.h\r
   gTianoCustomDecompressGuid     = { 0xA31280AD, 0x481E, 0x41B6, { 0x95, 0xE8, 0x12, 0x7F, 0x4C, 0x98, 0x47, 0x79 }}\r
   \r
+  ## Include/Guid/LzmaDecompress.h\r
+  gLzmaCustomDecompressGuid      = { 0xEE4E5898, 0x3914, 0x4259, { 0x9D, 0x6E, 0xDC, 0x7B, 0xD7, 0x94, 0x03, 0xCF }}\r
+\r
   ## Guid specify the default BMP logo file.\r
   ## Include/Guid/Logo.h\r
   gEfiDefaultBmpLogoGuid         = { 0x7BB28B99, 0x61BB, 0x11D5, { 0x9A, 0x5D, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0x4D }}\r
   ## Guid specify the default BMP logo file.\r
   ## Include/Guid/Logo.h\r
   gEfiDefaultBmpLogoGuid         = { 0x7BB28B99, 0x61BB, 0x11D5, { 0x9A, 0x5D, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0x4D }}\r
index 0867a30b8f59beb777f0063ceacadf829b6db095..a5ed7ec06138d0cad25ed0b5cc328f1cd05f5e09 100644 (file)
 \r
 [Components.common]\r
   IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.inf\r
 \r
 [Components.common]\r
   IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.inf\r
+  IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Pei/LzmaCustomDecompressLib.inf\r
+  IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Dxe/LzmaCustomDecompressLib.inf\r
   IntelFrameworkModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf\r
   IntelFrameworkModulePkg/Library/PciIncompatibleDeviceSupportLib/PciIncompatibleDeviceSupportLib.inf\r
   IntelFrameworkModulePkg/Library/PeiS3Lib/PeiS3Lib.inf\r
   IntelFrameworkModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf\r
   IntelFrameworkModulePkg/Library/PciIncompatibleDeviceSupportLib/PciIncompatibleDeviceSupportLib.inf\r
   IntelFrameworkModulePkg/Library/PeiS3Lib/PeiS3Lib.inf\r
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Dxe/LzmaCustomDecompressLib.inf b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Dxe/LzmaCustomDecompressLib.inf
new file mode 100644 (file)
index 0000000..cfeed7c
--- /dev/null
@@ -0,0 +1,55 @@
+#/** @file\r
+# LZMA GUIDed Section Extraction Protocol Library\r
+#\r
+# Uefi Decompression library instance\r
+# Copyright (c) 2006, 2009, Intel Corporation.\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = LzmaDxeDecompressLib\r
+  FILE_GUID                      = 35194660-7421-44ad-9636-e44885f092d1\r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = BASE\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  CONSTRUCTOR                    = LzmaDecompressLibConstructor\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources.common]\r
+  LzmaDxeMemory.c\r
+  ../LzmaDecompress.c\r
+  ../Sdk/C/LzFind.c\r
+  ../Sdk/C/LzmaDec.c\r
+  ../GuidedSectionExtraction.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec\r
+\r
+[Guids]\r
+  gLzmaCustomDecompressGuid \r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  DebugLib\r
+  BaseMemoryLib\r
+  MemoryAllocationLib\r
+  ExtractGuidedSectionLib\r
+\r
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Dxe/LzmaDxeMemory.c b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Dxe/LzmaDxeMemory.c
new file mode 100644 (file)
index 0000000..2973306
--- /dev/null
@@ -0,0 +1,47 @@
+/** @file\r
+  LZMA Memory Allocation for DXE\r
+\r
+  Copyright (c) 2006 - 2009, Intel Corporation<BR>\r
+  All rights reserved. This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Uefi.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include "Sdk/C/Types.h"\r
+\r
+STATIC\r
+VOID *\r
+SzAlloc(\r
+  void *p,\r
+  size_t size\r
+  )\r
+{\r
+  void *np;\r
+  p = p;\r
+  np = AllocatePool(size);\r
+  return np;\r
+}\r
+\r
+STATIC\r
+VOID\r
+SzFree(\r
+  void *p,\r
+  void *address\r
+  )\r
+{\r
+  p = p;\r
+  if (address != NULL) {\r
+    FreePool(address);\r
+  }\r
+}\r
+\r
+ISzAlloc g_Alloc = { SzAlloc, SzFree };\r
+\r
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/GuidedSectionExtraction.c b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/GuidedSectionExtraction.c
new file mode 100644 (file)
index 0000000..2444f31
--- /dev/null
@@ -0,0 +1,177 @@
+/** @file\r
+  LZMA Decompress GUIDed Section Extraction Library\r
+\r
+  Copyright (c) 2006 - 2009, Intel Corporation<BR>\r
+  All rights reserved. This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Uefi.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/ExtractGuidedSectionLib.h>\r
+#include <Pi/PiFirmwareFile.h>\r
+#include <Guid/LzmaDecompress.h>\r
+\r
+#include "LzmaDecompress.h"\r
+\r
+\r
+STATIC\r
+RETURN_STATUS\r
+EFIAPI\r
+LzmaGuidedSectionGetCompressedLocation (\r
+  IN  CONST VOID  *InputSection,\r
+  OUT VOID        **LmzaCompressedData,\r
+  OUT UINT32      *LmzaCompressedDataSize   OPTIONAL\r
+  )\r
+{\r
+  if (!CompareGuid (\r
+        &gLzmaCustomDecompressGuid, \r
+        &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
+    return RETURN_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Retrieve the size and attribute of the input section data.\r
+  //\r
+  *LmzaCompressedData =\r
+    (VOID*) (\r
+        (UINT8 *) InputSection +\r
+        ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset\r
+      );\r
+  if (LmzaCompressedDataSize != NULL) {\r
+    *LmzaCompressedDataSize =\r
+      (UINT32)(\r
+        (\r
+          (*(UINT32 *) (((EFI_COMMON_SECTION_HEADER *) InputSection)->Size)) &\r
+          0x00ffffff\r
+        ) -\r
+        ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset\r
+      );\r
+  }\r
+\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  The implementation of 'GetInfo' for Guided Section\r
+  Extraction of LZMA compression.\r
+\r
+  @param  InputSection          Buffer containing the input GUIDed section to be processed. \r
+  @param  OutputBufferSize      The size of OutputBuffer.\r
+  @param  ScratchBufferSize     The size of ScratchBuffer.\r
+  @param  SectionAttribute      The attribute of the input guided section.\r
+\r
+  @retval RETURN_SUCCESS            The size of destination buffer and the size of scratch buffer are successull retrieved.\r
+  @retval RETURN_INVALID_PARAMETER  The source data is corrupted, or\r
+                                    The GUID in InputSection does not match this instance guid.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+LzmaGuidedSectionGetInfo (\r
+  IN  CONST VOID  *InputSection,\r
+  OUT UINT32      *OutputBufferSize,\r
+  OUT UINT32      *ScratchBufferSize,\r
+  OUT UINT16      *SectionAttribute\r
+  )\r
+{\r
+  RETURN_STATUS Status;\r
+  VOID          *LzmaInput;\r
+  UINT32        LzmaInputSize;\r
+\r
+  Status = LzmaGuidedSectionGetCompressedLocation(\r
+    InputSection,\r
+    &LzmaInput,\r
+    &LzmaInputSize\r
+    );\r
+  if (RETURN_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  *SectionAttribute = ((EFI_GUID_DEFINED_SECTION *) InputSection)->Attributes;\r
+\r
+  return LzmaUefiDecompressGetInfo (\r
+    LzmaInput,\r
+    LzmaInputSize,\r
+    OutputBufferSize,\r
+    ScratchBufferSize\r
+    );\r
+}\r
+\r
+/**\r
+  The implementation of Guided Section Extraction\r
+  for LZMA compression.\r
+\r
+  @param  InputSection          Buffer containing the input GUIDed section to be processed. \r
+  @param  OutputBuffer          OutputBuffer to point to the start of the section's contents.\r
+                                if guided data is not prcessed. Otherwise,\r
+                                OutputBuffer to contain the output data, which is allocated by the caller.\r
+  @param  ScratchBuffer         A pointer to a caller-allocated buffer for function internal use. \r
+  @param  AuthenticationStatus  A pointer to a caller-allocated UINT32 that indicates the\r
+                                authentication status of the output buffer. \r
+\r
+  @retval RETURN_SUCCESS            Decompression is successfull\r
+  @retval RETURN_INVALID_PARAMETER  The source data is corrupted, or\r
+                                    The GUID in InputSection does not match this instance guid.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+LzmaGuidedSectionExtraction (\r
+  IN CONST  VOID    *InputSection,\r
+  OUT       VOID    **OutputBuffer,\r
+  IN        VOID    *ScratchBuffer,        OPTIONAL\r
+  OUT       UINT32  *AuthenticationStatus\r
+  )\r
+{\r
+  RETURN_STATUS Status;\r
+  VOID          *LzmaInput;\r
+\r
+  Status = LzmaGuidedSectionGetCompressedLocation(\r
+    InputSection,\r
+    &LzmaInput,\r
+    NULL\r
+    );\r
+  if (RETURN_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Authentication is set to Zero, which may be ignored.\r
+  //\r
+  *AuthenticationStatus = 0;\r
+\r
+  return LzmaUefiDecompress (\r
+    LzmaInput,\r
+    *OutputBuffer,\r
+    ScratchBuffer\r
+    );\r
+}\r
+\r
+\r
+/**\r
+  Register LzmaDecompress handler.\r
+\r
+  @retval  RETURN_SUCCESS            Register successfully.\r
+  @retval  RETURN_OUT_OF_RESOURCES   No enough memory to store this handler.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+LzmaDecompressLibConstructor (\r
+  )\r
+{\r
+  return ExtractGuidedSectionRegisterHandlers (\r
+          &gLzmaCustomDecompressGuid,\r
+          LzmaGuidedSectionGetInfo,\r
+          LzmaGuidedSectionExtraction\r
+          );      \r
+}\r
+\r
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LZMA-SDK-README.txt b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LZMA-SDK-README.txt
new file mode 100644 (file)
index 0000000..e05b3bb
--- /dev/null
@@ -0,0 +1,4 @@
+LzmaCustomDecompressLib is based on the LZMA SDK 4.65.\r
+LZMA SDK 4.65 was placed in the public domain on\r
+2009-02-03.  It was released on the\r
+http://www.7-zip.org/sdk.html website.
\ No newline at end of file
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompress.c b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompress.c
new file mode 100644 (file)
index 0000000..f172982
--- /dev/null
@@ -0,0 +1,144 @@
+/** @file\r
+  LZMA Decompress routines for edk2\r
+\r
+  Portions based on LZMA SDK 4.65:\r
+    LzmaUtil.c -- Test application for LZMA compression\r
+    2008-11-23 : Igor Pavlov : Public domain\r
+\r
+  Copyright (c) 2006 - 2009, Intel Corporation<BR>\r
+  All rights reserved. This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Uefi.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiDecompressLib.h>\r
+#include <Library/ExtractGuidedSectionLib.h>\r
+#include <Guid/LzmaDecompress.h>\r
+\r
+#include "Sdk/C/Types.h"\r
+#include "Sdk/C/7zVersion.h"\r
+#include "Sdk/C/LzmaDec.h"\r
+\r
+extern ISzAlloc g_Alloc;\r
+\r
+#define LZMA_HEADER_SIZE (LZMA_PROPS_SIZE + 8)\r
+\r
+STATIC\r
+UINT64\r
+GetDecodedSizeOfBuf(\r
+  UINT8 *encodedData\r
+  )\r
+{\r
+  UINT64 DecodedSize;\r
+  INTN   Index;\r
+\r
+  /* Parse header */\r
+  DecodedSize = 0;\r
+  for (Index = LZMA_PROPS_SIZE + 7; Index >= LZMA_PROPS_SIZE; Index--)\r
+    DecodedSize = LShiftU64(DecodedSize, 8) + encodedData[Index];\r
+\r
+  return DecodedSize;\r
+}\r
+\r
+//\r
+// LZMA functions and data as defined in local LzmaDecompress.h\r
+//\r
+\r
+STATIC CONST VOID  *mSourceLastUsedWithGetInfo;\r
+STATIC UINT32      mSizeOfLastSource;\r
+STATIC UINT32      mDecompressedSizeForLastSource;\r
+\r
+/**\r
+  The internal implementation of *_DECOMPRESS_PROTOCOL.GetInfo().\r
+  \r
+  @param Source           The source buffer containing the compressed data.\r
+  @param SourceSize       The size of source buffer\r
+  @param DestinationSize  The size of destination buffer.\r
+  @param ScratchSize      The size of scratch buffer.\r
+\r
+  @retval RETURN_SUCCESS           - The size of destination buffer and the size of scratch buffer are successull retrieved.\r
+  @retval RETURN_INVALID_PARAMETER - The source data is corrupted\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+LzmaUefiDecompressGetInfo (\r
+  IN  CONST VOID  *Source,\r
+  IN  UINT32      SourceSize,\r
+  OUT UINT32      *DestinationSize,\r
+  OUT UINT32      *ScratchSize\r
+  )\r
+{\r
+  UInt64  DecodedSize;\r
+\r
+  ASSERT(SourceSize >= LZMA_HEADER_SIZE);\r
+\r
+  DecodedSize = GetDecodedSizeOfBuf((UINT8*)Source);\r
+\r
+  mSourceLastUsedWithGetInfo = Source;\r
+  mSizeOfLastSource = SourceSize;\r
+  mDecompressedSizeForLastSource = (UInt32)DecodedSize;\r
+  *DestinationSize = mDecompressedSizeForLastSource;\r
+  *ScratchSize = 0x10;\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  The internal implementation of *_DECOMPRESS_PROTOCOL.Decompress().\r
+  \r
+  @param Source          - The source buffer containing the compressed data.\r
+  @param Destination     - The destination buffer to store the decompressed data\r
+  @param Scratch         - The buffer used internally by the decompress routine. This  buffer is needed to store intermediate data.\r
+\r
+  @retval RETURN_SUCCESS           - Decompression is successfull\r
+  @retval RETURN_INVALID_PARAMETER - The source data is corrupted  \r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+LzmaUefiDecompress (\r
+  IN CONST VOID  *Source,\r
+  IN OUT VOID    *Destination,\r
+  IN OUT VOID    *Scratch\r
+  )\r
+{\r
+  SRes        lzmaResult;\r
+  ELzmaStatus status;\r
+  SizeT       decodedBufSize;\r
+  SizeT       encodedDataSize;\r
+\r
+  if (Source != mSourceLastUsedWithGetInfo) {\r
+    return RETURN_INVALID_PARAMETER;\r
+  }\r
+\r
+  decodedBufSize = (SizeT)mDecompressedSizeForLastSource;\r
+  encodedDataSize = (SizeT)(mSizeOfLastSource - LZMA_HEADER_SIZE);\r
+\r
+  lzmaResult = LzmaDecode(\r
+    Destination,\r
+    &decodedBufSize,\r
+    (Byte*)((UINT8*)Source + LZMA_HEADER_SIZE),\r
+    &encodedDataSize,\r
+    Source,\r
+    LZMA_PROPS_SIZE,\r
+    LZMA_FINISH_END,\r
+    &status,\r
+    &g_Alloc\r
+    );\r
+\r
+  if (lzmaResult == SZ_OK) {\r
+    return RETURN_SUCCESS;\r
+  } else {\r
+    return RETURN_INVALID_PARAMETER;\r
+  }\r
+}\r
+\r
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompress.h b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompress.h
new file mode 100644 (file)
index 0000000..fbf645e
--- /dev/null
@@ -0,0 +1,57 @@
+/** @file\r
+  LZMA Decompress Library header file\r
+\r
+  Copyright (c) 2006 - 2009, Intel Corporation<BR>\r
+  All rights reserved. This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __LZMADECOMPRESS_H__\r
+#define __LZMADECOMPRESS_H__\r
+\r
+/**\r
+  The internal implementation of *_DECOMPRESS_PROTOCOL.GetInfo().\r
+  \r
+  @param Source           The source buffer containing the compressed data.\r
+  @param SourceSize       The size of source buffer\r
+  @param DestinationSize  The size of destination buffer.\r
+  @param ScratchSize      The size of scratch buffer.\r
+\r
+  @retval RETURN_SUCCESS           - The size of destination buffer and the size of scratch buffer are successull retrieved.\r
+  @retval RETURN_INVALID_PARAMETER - The source data is corrupted\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+LzmaUefiDecompressGetInfo (\r
+  IN  CONST VOID  *Source,\r
+  IN  UINT32      SourceSize,\r
+  OUT UINT32      *DestinationSize,\r
+  OUT UINT32      *ScratchSize\r
+  );\r
+\r
+/**\r
+  The internal implementation of *_DECOMPRESS_PROTOCOL.Decompress().\r
+  \r
+  @param Source          - The source buffer containing the compressed data.\r
+  @param Destination     - The destination buffer to store the decompressed data\r
+  @param Scratch         - The buffer used internally by the decompress routine. This  buffer is needed to store intermediate data.\r
+\r
+  @retval RETURN_SUCCESS           - Decompression is successfull\r
+  @retval RETURN_INVALID_PARAMETER - The source data is corrupted  \r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+LzmaUefiDecompress (\r
+  IN CONST VOID  *Source,\r
+  IN OUT VOID    *Destination,\r
+  IN OUT VOID    *Scratch\r
+  );\r
+\r
+#endif // __LZMADECOMPRESS_H__\r
+\r
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Pei/LzmaCustomDecompressLib.inf b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Pei/LzmaCustomDecompressLib.inf
new file mode 100644 (file)
index 0000000..a9b347b
--- /dev/null
@@ -0,0 +1,55 @@
+#/** @file\r
+# LZMA GUIDed Section Extraction Protocol Library\r
+#\r
+# Uefi Decompression library instance\r
+# Copyright (c) 2006, 2009, Intel Corporation.\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = LzmaPeiDecompressLib\r
+  FILE_GUID                      = 6725ae86-6ed1-43bd-aeec-0517c0749d70\r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = BASE\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  CONSTRUCTOR                    = LzmaDecompressLibConstructor\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources.common]\r
+  LzmaPeiMemory.c\r
+  ../LzmaDecompress.c\r
+  ../Sdk/C/LzFind.c\r
+  ../Sdk/C/LzmaDec.c\r
+  ../GuidedSectionExtraction.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec\r
+\r
+[Guids]\r
+  gLzmaCustomDecompressGuid \r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  DebugLib\r
+  BaseMemoryLib\r
+  MemoryAllocationLib\r
+  ExtractGuidedSectionLib\r
+\r
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Pei/LzmaPeiMemory.c b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Pei/LzmaPeiMemory.c
new file mode 100644 (file)
index 0000000..a6824f1
--- /dev/null
@@ -0,0 +1,54 @@
+/** @file\r
+  LZMA Memory Allocation for PEI\r
+\r
+  AllocatePool does not work for large blocks during PEI, so we must\r
+  use AllocatePages.\r
+\r
+  Copyright (c) 2006 - 2009, Intel Corporation<BR>\r
+  All rights reserved. This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Uefi.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include "Sdk/C/Types.h"\r
+\r
+STATIC\r
+VOID *\r
+SzAlloc(\r
+  void *p,\r
+  size_t size\r
+  )\r
+{\r
+  void *np;\r
+  p = p;\r
+  if (size > EFI_PAGE_SIZE) {\r
+    np = AllocatePages(EFI_SIZE_TO_PAGES(size));\r
+  } else {\r
+    np = AllocatePool(size);\r
+  }\r
+  return np;\r
+}\r
+\r
+STATIC\r
+VOID\r
+SzFree(\r
+  void *p,\r
+  void *address\r
+  )\r
+{\r
+  p = p;\r
+  if (address != NULL) {\r
+    FreePool(address);\r
+  }\r
+}\r
+\r
+ISzAlloc g_Alloc = { SzAlloc, SzFree };\r
+\r
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/7zVersion.h b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/7zVersion.h
new file mode 100644 (file)
index 0000000..5a6bcad
--- /dev/null
@@ -0,0 +1,7 @@
+#define MY_VER_MAJOR 4\r
+#define MY_VER_MINOR 65\r
+#define MY_VER_BUILD 0\r
+#define MY_VERSION "4.65"\r
+#define MY_DATE "2009-02-03"\r
+#define MY_COPYRIGHT ": Igor Pavlov : Public domain"\r
+#define MY_VERSION_COPYRIGHT_DATE MY_VERSION " " MY_COPYRIGHT " : " MY_DATE\r
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/CpuArch.h b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/CpuArch.h
new file mode 100644 (file)
index 0000000..006361f
--- /dev/null
@@ -0,0 +1,69 @@
+/* CpuArch.h\r
+2008-08-05\r
+Igor Pavlov\r
+Public domain */\r
+\r
+#ifndef __CPUARCH_H\r
+#define __CPUARCH_H\r
+\r
+/*\r
+LITTLE_ENDIAN_UNALIGN means:\r
+  1) CPU is LITTLE_ENDIAN\r
+  2) it's allowed to make unaligned memory accesses\r
+if LITTLE_ENDIAN_UNALIGN is not defined, it means that we don't know\r
+about these properties of platform.\r
+*/\r
+\r
+#if defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || defined(__i386__) || defined(__x86_64__)\r
+#define LITTLE_ENDIAN_UNALIGN\r
+#endif\r
+\r
+#ifdef LITTLE_ENDIAN_UNALIGN\r
+\r
+#define GetUi16(p) (*(const UInt16 *)(p))\r
+#define GetUi32(p) (*(const UInt32 *)(p))\r
+#define GetUi64(p) (*(const UInt64 *)(p))\r
+#define SetUi32(p, d) *(UInt32 *)(p) = (d);\r
+\r
+#else\r
+\r
+#define GetUi16(p) (((const Byte *)(p))[0] | ((UInt16)((const Byte *)(p))[1] << 8))\r
+\r
+#define GetUi32(p) ( \\r
+             ((const Byte *)(p))[0]        | \\r
+    ((UInt32)((const Byte *)(p))[1] <<  8) | \\r
+    ((UInt32)((const Byte *)(p))[2] << 16) | \\r
+    ((UInt32)((const Byte *)(p))[3] << 24))\r
+\r
+#define GetUi64(p) (GetUi32(p) | ((UInt64)GetUi32(((const Byte *)(p)) + 4) << 32))\r
+\r
+#define SetUi32(p, d) { UInt32 _x_ = (d); \\r
+    ((Byte *)(p))[0] = (Byte)_x_; \\r
+    ((Byte *)(p))[1] = (Byte)(_x_ >> 8); \\r
+    ((Byte *)(p))[2] = (Byte)(_x_ >> 16); \\r
+    ((Byte *)(p))[3] = (Byte)(_x_ >> 24); }\r
+\r
+#endif\r
+\r
+#if defined(LITTLE_ENDIAN_UNALIGN) && defined(_WIN64) && (_MSC_VER >= 1300)\r
+\r
+#pragma intrinsic(_byteswap_ulong)\r
+#pragma intrinsic(_byteswap_uint64)\r
+#define GetBe32(p) _byteswap_ulong(*(const UInt32 *)(const Byte *)(p))\r
+#define GetBe64(p) _byteswap_uint64(*(const UInt64 *)(const Byte *)(p))\r
+\r
+#else\r
+\r
+#define GetBe32(p) ( \\r
+    ((UInt32)((const Byte *)(p))[0] << 24) | \\r
+    ((UInt32)((const Byte *)(p))[1] << 16) | \\r
+    ((UInt32)((const Byte *)(p))[2] <<  8) | \\r
+             ((const Byte *)(p))[3] )\r
+\r
+#define GetBe64(p) (((UInt64)GetBe32(p) << 32) | GetBe32(((const Byte *)(p)) + 4))\r
+\r
+#endif\r
+\r
+#define GetBe16(p) (((UInt16)((const Byte *)(p))[0] << 8) | ((const Byte *)(p))[1])\r
+\r
+#endif\r
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzFind.c b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzFind.c
new file mode 100644 (file)
index 0000000..7b2cd74
--- /dev/null
@@ -0,0 +1,770 @@
+/** @file\r
+  LzFind.c\r
+\r
+  Based on LZMA SDK 4.65:\r
+    LzFind.c -- Match finder for LZ algorithms\r
+    2008-10-04 : Igor Pavlov : Public domain\r
+\r
+  Copyright (c) 2009, Intel Corporation<BR>\r
+  All rights reserved. This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef EFIAPI\r
+\r
+#include <string.h>\r
+\r
+#endif // !EFIAPI\r
+\r
+#include "LzFind.h"\r
+#include "LzHash.h"\r
+\r
+#define kEmptyHashValue 0\r
+#define kMaxValForNormalize ((UInt32)0xFFFFFFFF)\r
+#define kNormalizeStepMin (1 << 10) /* it must be power of 2 */\r
+#define kNormalizeMask (~(kNormalizeStepMin - 1))\r
+#define kMaxHistorySize ((UInt32)3 << 30)\r
+\r
+#define kStartMaxLen 3\r
+\r
+static void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)\r
+{\r
+  if (!p->directInput)\r
+  {\r
+    alloc->Free(alloc, p->bufferBase);\r
+    p->bufferBase = 0;\r
+  }\r
+}\r
+\r
+/* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */\r
+\r
+static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc)\r
+{\r
+  UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;\r
+  if (p->directInput)\r
+  {\r
+    p->blockSize = blockSize;\r
+    return 1;\r
+  }\r
+  if (p->bufferBase == 0 || p->blockSize != blockSize)\r
+  {\r
+    LzInWindow_Free(p, alloc);\r
+    p->blockSize = blockSize;\r
+    p->bufferBase = (Byte *)alloc->Alloc(alloc, (size_t)blockSize);\r
+  }\r
+  return (p->bufferBase != 0);\r
+}\r
+\r
+Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }\r
+Byte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; }\r
+\r
+UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }\r
+\r
+void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)\r
+{\r
+  p->posLimit -= subValue;\r
+  p->pos -= subValue;\r
+  p->streamPos -= subValue;\r
+}\r
+\r
+static void MatchFinder_ReadBlock(CMatchFinder *p)\r
+{\r
+  if (p->streamEndWasReached || p->result != SZ_OK)\r
+    return;\r
+  for (;;)\r
+  {\r
+    Byte *dest = p->buffer + (p->streamPos - p->pos);\r
+    size_t size = (p->bufferBase + p->blockSize - dest);\r
+    if (size == 0)\r
+      return;\r
+    p->result = p->stream->Read(p->stream, dest, &size);\r
+    if (p->result != SZ_OK)\r
+      return;\r
+    if (size == 0)\r
+    {\r
+      p->streamEndWasReached = 1;\r
+      return;\r
+    }\r
+    p->streamPos += (UInt32)size;\r
+    if (p->streamPos - p->pos > p->keepSizeAfter)\r
+      return;\r
+  }\r
+}\r
+\r
+void MatchFinder_MoveBlock(CMatchFinder *p)\r
+{\r
+  memmove(p->bufferBase,\r
+    p->buffer - p->keepSizeBefore,\r
+    (size_t)(p->streamPos - p->pos + p->keepSizeBefore));\r
+  p->buffer = p->bufferBase + p->keepSizeBefore;\r
+}\r
+\r
+int MatchFinder_NeedMove(CMatchFinder *p)\r
+{\r
+  /* if (p->streamEndWasReached) return 0; */\r
+  return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter);\r
+}\r
+\r
+void MatchFinder_ReadIfRequired(CMatchFinder *p)\r
+{\r
+  if (p->streamEndWasReached)\r
+    return;\r
+  if (p->keepSizeAfter >= p->streamPos - p->pos)\r
+    MatchFinder_ReadBlock(p);\r
+}\r
+\r
+static void MatchFinder_CheckAndMoveAndRead(CMatchFinder *p)\r
+{\r
+  if (MatchFinder_NeedMove(p))\r
+    MatchFinder_MoveBlock(p);\r
+  MatchFinder_ReadBlock(p);\r
+}\r
+\r
+static void MatchFinder_SetDefaultSettings(CMatchFinder *p)\r
+{\r
+  p->cutValue = 32;\r
+  p->btMode = 1;\r
+  p->numHashBytes = 4;\r
+  /* p->skipModeBits = 0; */\r
+  p->directInput = 0;\r
+  p->bigHash = 0;\r
+}\r
+\r
+#define kCrcPoly 0xEDB88320\r
+\r
+void MatchFinder_Construct(CMatchFinder *p)\r
+{\r
+  UInt32 i;\r
+  p->bufferBase = 0;\r
+  p->directInput = 0;\r
+  p->hash = 0;\r
+  MatchFinder_SetDefaultSettings(p);\r
+\r
+  for (i = 0; i < 256; i++)\r
+  {\r
+    UInt32 r = i;\r
+    int j;\r
+    for (j = 0; j < 8; j++)\r
+      r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));\r
+    p->crc[i] = r;\r
+  }\r
+}\r
+\r
+static void MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAlloc *alloc)\r
+{\r
+  alloc->Free(alloc, p->hash);\r
+  p->hash = 0;\r
+}\r
+\r
+void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc)\r
+{\r
+  MatchFinder_FreeThisClassMemory(p, alloc);\r
+  LzInWindow_Free(p, alloc);\r
+}\r
+\r
+static CLzRef* AllocRefs(UInt32 num, ISzAlloc *alloc)\r
+{\r
+  size_t sizeInBytes = (size_t)num * sizeof(CLzRef);\r
+  if (sizeInBytes / sizeof(CLzRef) != num)\r
+    return 0;\r
+  return (CLzRef *)alloc->Alloc(alloc, sizeInBytes);\r
+}\r
+\r
+int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,\r
+    UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,\r
+    ISzAlloc *alloc)\r
+{\r
+  UInt32 sizeReserv;\r
+  if (historySize > kMaxHistorySize)\r
+  {\r
+    MatchFinder_Free(p, alloc);\r
+    return 0;\r
+  }\r
+  sizeReserv = historySize >> 1;\r
+  if (historySize > ((UInt32)2 << 30))\r
+    sizeReserv = historySize >> 2;\r
+  sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19);\r
+\r
+  p->keepSizeBefore = historySize + keepAddBufferBefore + 1;\r
+  p->keepSizeAfter = matchMaxLen + keepAddBufferAfter;\r
+  /* we need one additional byte, since we use MoveBlock after pos++ and before dictionary using */\r
+  if (LzInWindow_Create(p, sizeReserv, alloc))\r
+  {\r
+    UInt32 newCyclicBufferSize = (historySize /* >> p->skipModeBits */) + 1;\r
+    UInt32 hs;\r
+    p->matchMaxLen = matchMaxLen;\r
+    {\r
+      p->fixedHashSize = 0;\r
+      if (p->numHashBytes == 2)\r
+        hs = (1 << 16) - 1;\r
+      else\r
+      {\r
+        hs = historySize - 1;\r
+        hs |= (hs >> 1);\r
+        hs |= (hs >> 2);\r
+        hs |= (hs >> 4);\r
+        hs |= (hs >> 8);\r
+        hs >>= 1;\r
+        /* hs >>= p->skipModeBits; */\r
+        hs |= 0xFFFF; /* don't change it! It's required for Deflate */\r
+        if (hs > (1 << 24))\r
+        {\r
+          if (p->numHashBytes == 3)\r
+            hs = (1 << 24) - 1;\r
+          else\r
+            hs >>= 1;\r
+        }\r
+      }\r
+      p->hashMask = hs;\r
+      hs++;\r
+      if (p->numHashBytes > 2) p->fixedHashSize += kHash2Size;\r
+      if (p->numHashBytes > 3) p->fixedHashSize += kHash3Size;\r
+      if (p->numHashBytes > 4) p->fixedHashSize += kHash4Size;\r
+      hs += p->fixedHashSize;\r
+    }\r
+\r
+    {\r
+      UInt32 prevSize = p->hashSizeSum + p->numSons;\r
+      UInt32 newSize;\r
+      p->historySize = historySize;\r
+      p->hashSizeSum = hs;\r
+      p->cyclicBufferSize = newCyclicBufferSize;\r
+      p->numSons = (p->btMode ? newCyclicBufferSize * 2 : newCyclicBufferSize);\r
+      newSize = p->hashSizeSum + p->numSons;\r
+      if (p->hash != 0 && prevSize == newSize)\r
+        return 1;\r
+      MatchFinder_FreeThisClassMemory(p, alloc);\r
+      p->hash = AllocRefs(newSize, alloc);\r
+      if (p->hash != 0)\r
+      {\r
+        p->son = p->hash + p->hashSizeSum;\r
+        return 1;\r
+      }\r
+    }\r
+  }\r
+  MatchFinder_Free(p, alloc);\r
+  return 0;\r
+}\r
+\r
+static void MatchFinder_SetLimits(CMatchFinder *p)\r
+{\r
+  UInt32 limit = kMaxValForNormalize - p->pos;\r
+  UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos;\r
+  if (limit2 < limit)\r
+    limit = limit2;\r
+  limit2 = p->streamPos - p->pos;\r
+  if (limit2 <= p->keepSizeAfter)\r
+  {\r
+    if (limit2 > 0)\r
+      limit2 = 1;\r
+  }\r
+  else\r
+    limit2 -= p->keepSizeAfter;\r
+  if (limit2 < limit)\r
+    limit = limit2;\r
+  {\r
+    UInt32 lenLimit = p->streamPos - p->pos;\r
+    if (lenLimit > p->matchMaxLen)\r
+      lenLimit = p->matchMaxLen;\r
+    p->lenLimit = lenLimit;\r
+  }\r
+  p->posLimit = p->pos + limit;\r
+}\r
+\r
+void MatchFinder_Init(CMatchFinder *p)\r
+{\r
+  UInt32 i;\r
+  for (i = 0; i < p->hashSizeSum; i++)\r
+    p->hash[i] = kEmptyHashValue;\r
+  p->cyclicBufferPos = 0;\r
+  p->buffer = p->bufferBase;\r
+  p->pos = p->streamPos = p->cyclicBufferSize;\r
+  p->result = SZ_OK;\r
+  p->streamEndWasReached = 0;\r
+  MatchFinder_ReadBlock(p);\r
+  MatchFinder_SetLimits(p);\r
+}\r
+\r
+static UInt32 MatchFinder_GetSubValue(CMatchFinder *p)\r
+{\r
+  return (p->pos - p->historySize - 1) & kNormalizeMask;\r
+}\r
+\r
+void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)\r
+{\r
+  UInt32 i;\r
+  for (i = 0; i < numItems; i++)\r
+  {\r
+    UInt32 value = items[i];\r
+    if (value <= subValue)\r
+      value = kEmptyHashValue;\r
+    else\r
+      value -= subValue;\r
+    items[i] = value;\r
+  }\r
+}\r
+\r
+static void MatchFinder_Normalize(CMatchFinder *p)\r
+{\r
+  UInt32 subValue = MatchFinder_GetSubValue(p);\r
+  MatchFinder_Normalize3(subValue, p->hash, p->hashSizeSum + p->numSons);\r
+  MatchFinder_ReduceOffsets(p, subValue);\r
+}\r
+\r
+static void MatchFinder_CheckLimits(CMatchFinder *p)\r
+{\r
+  if (p->pos == kMaxValForNormalize)\r
+    MatchFinder_Normalize(p);\r
+  if (!p->streamEndWasReached && p->keepSizeAfter == p->streamPos - p->pos)\r
+    MatchFinder_CheckAndMoveAndRead(p);\r
+  if (p->cyclicBufferPos == p->cyclicBufferSize)\r
+    p->cyclicBufferPos = 0;\r
+  MatchFinder_SetLimits(p);\r
+}\r
+\r
+static UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,\r
+    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,\r
+    UInt32 *distances, UInt32 maxLen)\r
+{\r
+  son[_cyclicBufferPos] = curMatch;\r
+  for (;;)\r
+  {\r
+    UInt32 delta = pos - curMatch;\r
+    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r
+      return distances;\r
+    {\r
+      const Byte *pb = cur - delta;\r
+      curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];\r
+      if (pb[maxLen] == cur[maxLen] && *pb == *cur)\r
+      {\r
+        UInt32 len = 0;\r
+        while (++len != lenLimit)\r
+          if (pb[len] != cur[len])\r
+            break;\r
+        if (maxLen < len)\r
+        {\r
+          *distances++ = maxLen = len;\r
+          *distances++ = delta - 1;\r
+          if (len == lenLimit)\r
+            return distances;\r
+        }\r
+      }\r
+    }\r
+  }\r
+}\r
+\r
+UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,\r
+    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,\r
+    UInt32 *distances, UInt32 maxLen)\r
+{\r
+  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r
+  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\r
+  UInt32 len0 = 0, len1 = 0;\r
+  for (;;)\r
+  {\r
+    UInt32 delta = pos - curMatch;\r
+    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r
+    {\r
+      *ptr0 = *ptr1 = kEmptyHashValue;\r
+      return distances;\r
+    }\r
+    {\r
+      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r
+      const Byte *pb = cur - delta;\r
+      UInt32 len = (len0 < len1 ? len0 : len1);\r
+      if (pb[len] == cur[len])\r
+      {\r
+        if (++len != lenLimit && pb[len] == cur[len])\r
+          while (++len != lenLimit)\r
+            if (pb[len] != cur[len])\r
+              break;\r
+        if (maxLen < len)\r
+        {\r
+          *distances++ = maxLen = len;\r
+          *distances++ = delta - 1;\r
+          if (len == lenLimit)\r
+          {\r
+            *ptr1 = pair[0];\r
+            *ptr0 = pair[1];\r
+            return distances;\r
+          }\r
+        }\r
+      }\r
+      if (pb[len] < cur[len])\r
+      {\r
+        *ptr1 = curMatch;\r
+        ptr1 = pair + 1;\r
+        curMatch = *ptr1;\r
+        len1 = len;\r
+      }\r
+      else\r
+      {\r
+        *ptr0 = curMatch;\r
+        ptr0 = pair;\r
+        curMatch = *ptr0;\r
+        len0 = len;\r
+      }\r
+    }\r
+  }\r
+}\r
+\r
+static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,\r
+    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue)\r
+{\r
+  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r
+  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\r
+  UInt32 len0 = 0, len1 = 0;\r
+  for (;;)\r
+  {\r
+    UInt32 delta = pos - curMatch;\r
+    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r
+    {\r
+      *ptr0 = *ptr1 = kEmptyHashValue;\r
+      return;\r
+    }\r
+    {\r
+      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r
+      const Byte *pb = cur - delta;\r
+      UInt32 len = (len0 < len1 ? len0 : len1);\r
+      if (pb[len] == cur[len])\r
+      {\r
+        while (++len != lenLimit)\r
+          if (pb[len] != cur[len])\r
+            break;\r
+        {\r
+          if (len == lenLimit)\r
+          {\r
+            *ptr1 = pair[0];\r
+            *ptr0 = pair[1];\r
+            return;\r
+          }\r
+        }\r
+      }\r
+      if (pb[len] < cur[len])\r
+      {\r
+        *ptr1 = curMatch;\r
+        ptr1 = pair + 1;\r
+        curMatch = *ptr1;\r
+        len1 = len;\r
+      }\r
+      else\r
+      {\r
+        *ptr0 = curMatch;\r
+        ptr0 = pair;\r
+        curMatch = *ptr0;\r
+        len0 = len;\r
+      }\r
+    }\r
+  }\r
+}\r
+\r
+#define MOVE_POS \\r
+  ++p->cyclicBufferPos; \\r
+  p->buffer++; \\r
+  if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p);\r
+\r
+#define MOVE_POS_RET MOVE_POS return offset;\r
+\r
+static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }\r
+\r
+#define GET_MATCHES_HEADER2(minLen, ret_op) \\r
+  UInt32 lenLimit; UInt32 hashValue; const Byte *cur; UInt32 curMatch; \\r
+  lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \\r
+  cur = p->buffer;\r
+\r
+#define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return 0)\r
+#define SKIP_HEADER(minLen)        GET_MATCHES_HEADER2(minLen, continue)\r
+\r
+#define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue\r
+\r
+#define GET_MATCHES_FOOTER(offset, maxLen) \\r
+  offset = (UInt32)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \\r
+  distances + offset, maxLen) - distances); MOVE_POS_RET;\r
+\r
+#define SKIP_FOOTER \\r
+  SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;\r
+\r
+static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
+{\r
+  UInt32 offset;\r
+  GET_MATCHES_HEADER(2)\r
+  HASH2_CALC;\r
+  curMatch = p->hash[hashValue];\r
+  p->hash[hashValue] = p->pos;\r
+  offset = 0;\r
+  GET_MATCHES_FOOTER(offset, 1)\r
+}\r
+\r
+UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
+{\r
+  UInt32 offset;\r
+  GET_MATCHES_HEADER(3)\r
+  HASH_ZIP_CALC;\r
+  curMatch = p->hash[hashValue];\r
+  p->hash[hashValue] = p->pos;\r
+  offset = 0;\r
+  GET_MATCHES_FOOTER(offset, 2)\r
+}\r
+\r
+static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
+{\r
+  UInt32 hash2Value, delta2, maxLen, offset;\r
+  GET_MATCHES_HEADER(3)\r
+\r
+  HASH3_CALC;\r
+\r
+  delta2 = p->pos - p->hash[hash2Value];\r
+  curMatch = p->hash[kFix3HashSize + hashValue];\r
+  \r
+  p->hash[hash2Value] =\r
+  p->hash[kFix3HashSize + hashValue] = p->pos;\r
+\r
+\r
+  maxLen = 2;\r
+  offset = 0;\r
+  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r
+  {\r
+    for (; maxLen != lenLimit; maxLen++)\r
+      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r
+        break;\r
+    distances[0] = maxLen;\r
+    distances[1] = delta2 - 1;\r
+    offset = 2;\r
+    if (maxLen == lenLimit)\r
+    {\r
+      SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));\r
+      MOVE_POS_RET;\r
+    }\r
+  }\r
+  GET_MATCHES_FOOTER(offset, maxLen)\r
+}\r
+\r
+static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
+{\r
+  UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;\r
+  GET_MATCHES_HEADER(4)\r
+\r
+  HASH4_CALC;\r
+\r
+  delta2 = p->pos - p->hash[                hash2Value];\r
+  delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];\r
+  curMatch = p->hash[kFix4HashSize + hashValue];\r
+  \r
+  p->hash[                hash2Value] =\r
+  p->hash[kFix3HashSize + hash3Value] =\r
+  p->hash[kFix4HashSize + hashValue] = p->pos;\r
+\r
+  maxLen = 1;\r
+  offset = 0;\r
+  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r
+  {\r
+    distances[0] = maxLen = 2;\r
+    distances[1] = delta2 - 1;\r
+    offset = 2;\r
+  }\r
+  if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)\r
+  {\r
+    maxLen = 3;\r
+    distances[offset + 1] = delta3 - 1;\r
+    offset += 2;\r
+    delta2 = delta3;\r
+  }\r
+  if (offset != 0)\r
+  {\r
+    for (; maxLen != lenLimit; maxLen++)\r
+      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r
+        break;\r
+    distances[offset - 2] = maxLen;\r
+    if (maxLen == lenLimit)\r
+    {\r
+      SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));\r
+      MOVE_POS_RET;\r
+    }\r
+  }\r
+  if (maxLen < 3)\r
+    maxLen = 3;\r
+  GET_MATCHES_FOOTER(offset, maxLen)\r
+}\r
+\r
+static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
+{\r
+  UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;\r
+  GET_MATCHES_HEADER(4)\r
+\r
+  HASH4_CALC;\r
+\r
+  delta2 = p->pos - p->hash[                hash2Value];\r
+  delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];\r
+  curMatch = p->hash[kFix4HashSize + hashValue];\r
+\r
+  p->hash[                hash2Value] =\r
+  p->hash[kFix3HashSize + hash3Value] =\r
+  p->hash[kFix4HashSize + hashValue] = p->pos;\r
+\r
+  maxLen = 1;\r
+  offset = 0;\r
+  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r
+  {\r
+    distances[0] = maxLen = 2;\r
+    distances[1] = delta2 - 1;\r
+    offset = 2;\r
+  }\r
+  if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)\r
+  {\r
+    maxLen = 3;\r
+    distances[offset + 1] = delta3 - 1;\r
+    offset += 2;\r
+    delta2 = delta3;\r
+  }\r
+  if (offset != 0)\r
+  {\r
+    for (; maxLen != lenLimit; maxLen++)\r
+      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r
+        break;\r
+    distances[offset - 2] = maxLen;\r
+    if (maxLen == lenLimit)\r
+    {\r
+      p->son[p->cyclicBufferPos] = curMatch;\r
+      MOVE_POS_RET;\r
+    }\r
+  }\r
+  if (maxLen < 3)\r
+    maxLen = 3;\r
+  offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),\r
+    distances + offset, maxLen) - (distances));\r
+  MOVE_POS_RET\r
+}\r
+\r
+UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
+{\r
+  UInt32 offset;\r
+  GET_MATCHES_HEADER(3)\r
+  HASH_ZIP_CALC;\r
+  curMatch = p->hash[hashValue];\r
+  p->hash[hashValue] = p->pos;\r
+  offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),\r
+    distances, 2) - (distances));\r
+  MOVE_POS_RET\r
+}\r
+\r
+static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r
+{\r
+  do\r
+  {\r
+    SKIP_HEADER(2)\r
+    HASH2_CALC;\r
+    curMatch = p->hash[hashValue];\r
+    p->hash[hashValue] = p->pos;\r
+    SKIP_FOOTER\r
+  }\r
+  while (--num != 0);\r
+}\r
+\r
+void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r
+{\r
+  do\r
+  {\r
+    SKIP_HEADER(3)\r
+    HASH_ZIP_CALC;\r
+    curMatch = p->hash[hashValue];\r
+    p->hash[hashValue] = p->pos;\r
+    SKIP_FOOTER\r
+  }\r
+  while (--num != 0);\r
+}\r
+\r
+static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r
+{\r
+  do\r
+  {\r
+    UInt32 hash2Value;\r
+    SKIP_HEADER(3)\r
+    HASH3_CALC;\r
+    curMatch = p->hash[kFix3HashSize + hashValue];\r
+    p->hash[hash2Value] =\r
+    p->hash[kFix3HashSize + hashValue] = p->pos;\r
+    SKIP_FOOTER\r
+  }\r
+  while (--num != 0);\r
+}\r
+\r
+static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r
+{\r
+  do\r
+  {\r
+    UInt32 hash2Value, hash3Value;\r
+    SKIP_HEADER(4)\r
+    HASH4_CALC;\r
+    curMatch = p->hash[kFix4HashSize + hashValue];\r
+    p->hash[                hash2Value] =\r
+    p->hash[kFix3HashSize + hash3Value] = p->pos;\r
+    p->hash[kFix4HashSize + hashValue] = p->pos;\r
+    SKIP_FOOTER\r
+  }\r
+  while (--num != 0);\r
+}\r
+\r
+static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r
+{\r
+  do\r
+  {\r
+    UInt32 hash2Value, hash3Value;\r
+    SKIP_HEADER(4)\r
+    HASH4_CALC;\r
+    curMatch = p->hash[kFix4HashSize + hashValue];\r
+    p->hash[                hash2Value] =\r
+    p->hash[kFix3HashSize + hash3Value] =\r
+    p->hash[kFix4HashSize + hashValue] = p->pos;\r
+    p->son[p->cyclicBufferPos] = curMatch;\r
+    MOVE_POS\r
+  }\r
+  while (--num != 0);\r
+}\r
+\r
+void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r
+{\r
+  do\r
+  {\r
+    SKIP_HEADER(3)\r
+    HASH_ZIP_CALC;\r
+    curMatch = p->hash[hashValue];\r
+    p->hash[hashValue] = p->pos;\r
+    p->son[p->cyclicBufferPos] = curMatch;\r
+    MOVE_POS\r
+  }\r
+  while (--num != 0);\r
+}\r
+\r
+void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)\r
+{\r
+  vTable->Init = (Mf_Init_Func)MatchFinder_Init;\r
+  vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinder_GetIndexByte;\r
+  vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNumAvailableBytes;\r
+  vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_GetPointerToCurrentPos;\r
+  if (!p->btMode)\r
+  {\r
+    vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;\r
+    vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;\r
+  }\r
+  else if (p->numHashBytes == 2)\r
+  {\r
+    vTable->GetMatches = (Mf_GetMatches_Func)Bt2_MatchFinder_GetMatches;\r
+    vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip;\r
+  }\r
+  else if (p->numHashBytes == 3)\r
+  {\r
+    vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches;\r
+    vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip;\r
+  }\r
+  else\r
+  {\r
+    vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;\r
+    vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;\r
+  }\r
+}\r
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzFind.h b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzFind.h
new file mode 100644 (file)
index 0000000..423d67e
--- /dev/null
@@ -0,0 +1,107 @@
+/* LzFind.h -- Match finder for LZ algorithms\r
+2008-10-04 : Igor Pavlov : Public domain */\r
+\r
+#ifndef __LZFIND_H\r
+#define __LZFIND_H\r
+\r
+#include "Types.h"\r
+\r
+typedef UInt32 CLzRef;\r
+\r
+typedef struct _CMatchFinder\r
+{\r
+  Byte *buffer;\r
+  UInt32 pos;\r
+  UInt32 posLimit;\r
+  UInt32 streamPos;\r
+  UInt32 lenLimit;\r
+\r
+  UInt32 cyclicBufferPos;\r
+  UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */\r
+\r
+  UInt32 matchMaxLen;\r
+  CLzRef *hash;\r
+  CLzRef *son;\r
+  UInt32 hashMask;\r
+  UInt32 cutValue;\r
+\r
+  Byte *bufferBase;\r
+  ISeqInStream *stream;\r
+  int streamEndWasReached;\r
+\r
+  UInt32 blockSize;\r
+  UInt32 keepSizeBefore;\r
+  UInt32 keepSizeAfter;\r
+\r
+  UInt32 numHashBytes;\r
+  int directInput;\r
+  int btMode;\r
+  /* int skipModeBits; */\r
+  int bigHash;\r
+  UInt32 historySize;\r
+  UInt32 fixedHashSize;\r
+  UInt32 hashSizeSum;\r
+  UInt32 numSons;\r
+  SRes result;\r
+  UInt32 crc[256];\r
+} CMatchFinder;\r
+\r
+#define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)\r
+#define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(Int32)(index)])\r
+\r
+#define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)\r
+\r
+int MatchFinder_NeedMove(CMatchFinder *p);\r
+Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);\r
+void MatchFinder_MoveBlock(CMatchFinder *p);\r
+void MatchFinder_ReadIfRequired(CMatchFinder *p);\r
+\r
+void MatchFinder_Construct(CMatchFinder *p);\r
+\r
+/* Conditions:\r
+     historySize <= 3 GB\r
+     keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB\r
+*/\r
+int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,\r
+    UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,\r
+    ISzAlloc *alloc);\r
+void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);\r
+void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems);\r
+void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);\r
+\r
+UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,\r
+    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,\r
+    UInt32 *distances, UInt32 maxLen);\r
+\r
+/*\r
+Conditions:\r
+  Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.\r
+  Mf_GetPointerToCurrentPos_Func's result must be used only before any other function\r
+*/\r
+\r
+typedef void (*Mf_Init_Func)(void *object);\r
+typedef Byte (*Mf_GetIndexByte_Func)(void *object, Int32 index);\r
+typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object);\r
+typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object);\r
+typedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances);\r
+typedef void (*Mf_Skip_Func)(void *object, UInt32);\r
+\r
+typedef struct _IMatchFinder\r
+{\r
+  Mf_Init_Func Init;\r
+  Mf_GetIndexByte_Func GetIndexByte;\r
+  Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;\r
+  Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;\r
+  Mf_GetMatches_Func GetMatches;\r
+  Mf_Skip_Func Skip;\r
+} IMatchFinder;\r
+\r
+void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);\r
+\r
+void MatchFinder_Init(CMatchFinder *p);\r
+UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);\r
+UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);\r
+void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);\r
+void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);\r
+\r
+#endif\r
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzHash.h b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzHash.h
new file mode 100644 (file)
index 0000000..c923417
--- /dev/null
@@ -0,0 +1,54 @@
+/* LzHash.h -- HASH functions for LZ algorithms\r
+2008-10-04 : Igor Pavlov : Public domain */\r
+\r
+#ifndef __LZHASH_H\r
+#define __LZHASH_H\r
+\r
+#define kHash2Size (1 << 10)\r
+#define kHash3Size (1 << 16)\r
+#define kHash4Size (1 << 20)\r
+\r
+#define kFix3HashSize (kHash2Size)\r
+#define kFix4HashSize (kHash2Size + kHash3Size)\r
+#define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)\r
+\r
+#define HASH2_CALC hashValue = cur[0] | ((UInt32)cur[1] << 8);\r
+\r
+#define HASH3_CALC { \\r
+  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\r
+  hash2Value = temp & (kHash2Size - 1); \\r
+  hashValue = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; }\r
+\r
+#define HASH4_CALC { \\r
+  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\r
+  hash2Value = temp & (kHash2Size - 1); \\r
+  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\r
+  hashValue = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & p->hashMask; }\r
+\r
+#define HASH5_CALC { \\r
+  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\r
+  hash2Value = temp & (kHash2Size - 1); \\r
+  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\r
+  hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)); \\r
+  hashValue = (hash4Value ^ (p->crc[cur[4]] << 3)) & p->hashMask; \\r
+  hash4Value &= (kHash4Size - 1); }\r
+\r
+/* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */\r
+#define HASH_ZIP_CALC hashValue = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;\r
+\r
+\r
+#define MT_HASH2_CALC \\r
+  hash2Value = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1);\r
+\r
+#define MT_HASH3_CALC { \\r
+  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\r
+  hash2Value = temp & (kHash2Size - 1); \\r
+  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }\r
+\r
+#define MT_HASH4_CALC { \\r
+  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\r
+  hash2Value = temp & (kHash2Size - 1); \\r
+  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\r
+  hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); }\r
+\r
+#endif\r
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzmaDec.c b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzmaDec.c
new file mode 100644 (file)
index 0000000..4ca018b
--- /dev/null
@@ -0,0 +1,1026 @@
+/** @file\r
+  LzmaDec.c\r
+\r
+  Based on LZMA SDK 4.65:\r
+    LzmaDec.c -- LZMA Decoder\r
+    2008-11-06 : Igor Pavlov : Public domain\r
+\r
+  Copyright (c) 2009, Intel Corporation<BR>\r
+  All rights reserved. This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "LzmaDec.h"\r
+\r
+#ifndef EFIAPI\r
+\r
+#include <string.h>\r
+\r
+#endif // !EFIAPI\r
+\r
+#define kNumTopBits 24\r
+#define kTopValue ((UInt32)1 << kNumTopBits)\r
+\r
+#define kNumBitModelTotalBits 11\r
+#define kBitModelTotal (1 << kNumBitModelTotalBits)\r
+#define kNumMoveBits 5\r
+\r
+#define RC_INIT_SIZE 5\r
+\r
+#define NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | (*buf++); }\r
+\r
+#define IF_BIT_0(p) ttt = *(p); NORMALIZE; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)\r
+#define UPDATE_0(p) range = bound; *(p) = (CLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));\r
+#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CLzmaProb)(ttt - (ttt >> kNumMoveBits));\r
+#define GET_BIT2(p, i, A0, A1) IF_BIT_0(p) \\r
+  { UPDATE_0(p); i = (i + i); A0; } else \\r
+  { UPDATE_1(p); i = (i + i) + 1; A1; }\r
+#define GET_BIT(p, i) GET_BIT2(p, i, ; , ;)\r
+\r
+#define TREE_GET_BIT(probs, i) { GET_BIT((probs + i), i); }\r
+#define TREE_DECODE(probs, limit, i) \\r
+  { i = 1; do { TREE_GET_BIT(probs, i); } while (i < limit); i -= limit; }\r
+\r
+/* #define _LZMA_SIZE_OPT */\r
+\r
+#ifdef _LZMA_SIZE_OPT\r
+#define TREE_6_DECODE(probs, i) TREE_DECODE(probs, (1 << 6), i)\r
+#else\r
+#define TREE_6_DECODE(probs, i) \\r
+  { i = 1; \\r
+  TREE_GET_BIT(probs, i); \\r
+  TREE_GET_BIT(probs, i); \\r
+  TREE_GET_BIT(probs, i); \\r
+  TREE_GET_BIT(probs, i); \\r
+  TREE_GET_BIT(probs, i); \\r
+  TREE_GET_BIT(probs, i); \\r
+  i -= 0x40; }\r
+#endif\r
+\r
+#define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_ERROR; range <<= 8; code = (code << 8) | (*buf++); }\r
+\r
+#define IF_BIT_0_CHECK(p) ttt = *(p); NORMALIZE_CHECK; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)\r
+#define UPDATE_0_CHECK range = bound;\r
+#define UPDATE_1_CHECK range -= bound; code -= bound;\r
+#define GET_BIT2_CHECK(p, i, A0, A1) IF_BIT_0_CHECK(p) \\r
+  { UPDATE_0_CHECK; i = (i + i); A0; } else \\r
+  { UPDATE_1_CHECK; i = (i + i) + 1; A1; }\r
+#define GET_BIT_CHECK(p, i) GET_BIT2_CHECK(p, i, ; , ;)\r
+#define TREE_DECODE_CHECK(probs, limit, i) \\r
+  { i = 1; do { GET_BIT_CHECK(probs + i, i) } while (i < limit); i -= limit; }\r
+\r
+\r
+#define kNumPosBitsMax 4\r
+#define kNumPosStatesMax (1 << kNumPosBitsMax)\r
+\r
+#define kLenNumLowBits 3\r
+#define kLenNumLowSymbols (1 << kLenNumLowBits)\r
+#define kLenNumMidBits 3\r
+#define kLenNumMidSymbols (1 << kLenNumMidBits)\r
+#define kLenNumHighBits 8\r
+#define kLenNumHighSymbols (1 << kLenNumHighBits)\r
+\r
+#define LenChoice 0\r
+#define LenChoice2 (LenChoice + 1)\r
+#define LenLow (LenChoice2 + 1)\r
+#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))\r
+#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))\r
+#define kNumLenProbs (LenHigh + kLenNumHighSymbols)\r
+\r
+\r
+#define kNumStates 12\r
+#define kNumLitStates 7\r
+\r
+#define kStartPosModelIndex 4\r
+#define kEndPosModelIndex 14\r
+#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r
+\r
+#define kNumPosSlotBits 6\r
+#define kNumLenToPosStates 4\r
+\r
+#define kNumAlignBits 4\r
+#define kAlignTableSize (1 << kNumAlignBits)\r
+\r
+#define kMatchMinLen 2\r
+#define kMatchSpecLenStart (kMatchMinLen + kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols)\r
+\r
+#define IsMatch 0\r
+#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))\r
+#define IsRepG0 (IsRep + kNumStates)\r
+#define IsRepG1 (IsRepG0 + kNumStates)\r
+#define IsRepG2 (IsRepG1 + kNumStates)\r
+#define IsRep0Long (IsRepG2 + kNumStates)\r
+#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))\r
+#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))\r
+#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)\r
+#define LenCoder (Align + kAlignTableSize)\r
+#define RepLenCoder (LenCoder + kNumLenProbs)\r
+#define Literal (RepLenCoder + kNumLenProbs)\r
+\r
+#define LZMA_BASE_SIZE 1846\r
+#define LZMA_LIT_SIZE 768\r
+\r
+#define LzmaProps_GetNumProbs(p) ((UInt32)LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((p)->lc + (p)->lp)))\r
+\r
+#if Literal != LZMA_BASE_SIZE\r
+StopCompilingDueBUG\r
+#endif\r
+\r
+static const Byte kLiteralNextStates[kNumStates * 2] =\r
+{\r
+  0, 0, 0, 0, 1, 2, 3,  4,  5,  6,  4,  5,\r
+  7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10\r
+};\r
+\r
+#define LZMA_DIC_MIN (1 << 12)\r
+\r
+/* First LZMA-symbol is always decoded.\r
+And it decodes new LZMA-symbols while (buf < bufLimit), but "buf" is without last normalization\r
+Out:\r
+  Result:\r
+    SZ_OK - OK\r
+    SZ_ERROR_DATA - Error\r
+  p->remainLen:\r
+    < kMatchSpecLenStart : normal remain\r
+    = kMatchSpecLenStart : finished\r
+    = kMatchSpecLenStart + 1 : Flush marker\r
+    = kMatchSpecLenStart + 2 : State Init Marker\r
+*/\r
+\r
+static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte *bufLimit)\r
+{\r
+  CLzmaProb *probs = p->probs;\r
+\r
+  unsigned state = p->state;\r
+  UInt32 rep0 = p->reps[0], rep1 = p->reps[1], rep2 = p->reps[2], rep3 = p->reps[3];\r
+  unsigned pbMask = ((unsigned)1 << (p->prop.pb)) - 1;\r
+  unsigned lpMask = ((unsigned)1 << (p->prop.lp)) - 1;\r
+  unsigned lc = p->prop.lc;\r
+\r
+  Byte *dic = p->dic;\r
+  SizeT dicBufSize = p->dicBufSize;\r
+  SizeT dicPos = p->dicPos;\r
+  \r
+  UInt32 processedPos = p->processedPos;\r
+  UInt32 checkDicSize = p->checkDicSize;\r
+  unsigned len = 0;\r
+\r
+  const Byte *buf = p->buf;\r
+  UInt32 range = p->range;\r
+  UInt32 code = p->code;\r
+\r
+  do\r
+  {\r
+    CLzmaProb *prob;\r
+    UInt32 bound;\r
+    unsigned ttt;\r
+    unsigned posState = processedPos & pbMask;\r
+\r
+    prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;\r
+    IF_BIT_0(prob)\r
+    {\r
+      unsigned symbol;\r
+      UPDATE_0(prob);\r
+      prob = probs + Literal;\r
+      if (checkDicSize != 0 || processedPos != 0)\r
+        prob += (LZMA_LIT_SIZE * (((processedPos & lpMask) << lc) +\r
+        (dic[(dicPos == 0 ? dicBufSize : dicPos) - 1] >> (8 - lc))));\r
+\r
+      if (state < kNumLitStates)\r
+      {\r
+        symbol = 1;\r
+        do { GET_BIT(prob + symbol, symbol) } while (symbol < 0x100);\r
+      }\r
+      else\r
+      {\r
+        unsigned matchByte = p->dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];\r
+        unsigned offs = 0x100;\r
+        symbol = 1;\r
+        do\r
+        {\r
+          unsigned bit;\r
+          CLzmaProb *probLit;\r
+          matchByte <<= 1;\r
+          bit = (matchByte & offs);\r
+          probLit = prob + offs + bit + symbol;\r
+          GET_BIT2(probLit, symbol, offs &= ~bit, offs &= bit)\r
+        }\r
+        while (symbol < 0x100);\r
+      }\r
+      dic[dicPos++] = (Byte)symbol;\r
+      processedPos++;\r
+\r
+      state = kLiteralNextStates[state];\r
+      /* if (state < 4) state = 0; else if (state < 10) state -= 3; else state -= 6; */\r
+      continue;\r
+    }\r
+    else\r
+    {\r
+      UPDATE_1(prob);\r
+      prob = probs + IsRep + state;\r
+      IF_BIT_0(prob)\r
+      {\r
+        UPDATE_0(prob);\r
+        state += kNumStates;\r
+        prob = probs + LenCoder;\r
+      }\r
+      else\r
+      {\r
+        UPDATE_1(prob);\r
+        if (checkDicSize == 0 && processedPos == 0)\r
+          return SZ_ERROR_DATA;\r
+        prob = probs + IsRepG0 + state;\r
+        IF_BIT_0(prob)\r
+        {\r
+          UPDATE_0(prob);\r
+          prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;\r
+          IF_BIT_0(prob)\r
+          {\r
+            UPDATE_0(prob);\r
+            dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];\r
+            dicPos++;\r
+            processedPos++;\r
+            state = state < kNumLitStates ? 9 : 11;\r
+            continue;\r
+          }\r
+          UPDATE_1(prob);\r
+        }\r
+        else\r
+        {\r
+          UInt32 distance;\r
+          UPDATE_1(prob);\r
+          prob = probs + IsRepG1 + state;\r
+          IF_BIT_0(prob)\r
+          {\r
+            UPDATE_0(prob);\r
+            distance = rep1;\r
+          }\r
+          else\r
+          {\r
+            UPDATE_1(prob);\r
+            prob = probs + IsRepG2 + state;\r
+            IF_BIT_0(prob)\r
+            {\r
+              UPDATE_0(prob);\r
+              distance = rep2;\r
+            }\r
+            else\r
+            {\r
+              UPDATE_1(prob);\r
+              distance = rep3;\r
+              rep3 = rep2;\r
+            }\r
+            rep2 = rep1;\r
+          }\r
+          rep1 = rep0;\r
+          rep0 = distance;\r
+        }\r
+        state = state < kNumLitStates ? 8 : 11;\r
+        prob = probs + RepLenCoder;\r
+      }\r
+      {\r
+        unsigned limit2, offset;\r
+        CLzmaProb *probLen = prob + LenChoice;\r
+        IF_BIT_0(probLen)\r
+        {\r
+          UPDATE_0(probLen);\r
+          probLen = prob + LenLow + (posState << kLenNumLowBits);\r
+          offset = 0;\r
+          limit2 = (1 << kLenNumLowBits);\r
+        }\r
+        else\r
+        {\r
+          UPDATE_1(probLen);\r
+          probLen = prob + LenChoice2;\r
+          IF_BIT_0(probLen)\r
+          {\r
+            UPDATE_0(probLen);\r
+            probLen = prob + LenMid + (posState << kLenNumMidBits);\r
+            offset = kLenNumLowSymbols;\r
+            limit2 = (1 << kLenNumMidBits);\r
+          }\r
+          else\r
+          {\r
+            UPDATE_1(probLen);\r
+            probLen = prob + LenHigh;\r
+            offset = kLenNumLowSymbols + kLenNumMidSymbols;\r
+            limit2 = (1 << kLenNumHighBits);\r
+          }\r
+        }\r
+        TREE_DECODE(probLen, limit2, len);\r
+        len += offset;\r
+      }\r
+\r
+      if (state >= kNumStates)\r
+      {\r
+        UInt32 distance;\r
+        prob = probs + PosSlot +\r
+            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << kNumPosSlotBits);\r
+        TREE_6_DECODE(prob, distance);\r
+        if (distance >= kStartPosModelIndex)\r
+        {\r
+          unsigned posSlot = (unsigned)distance;\r
+          int numDirectBits = (int)(((distance >> 1) - 1));\r
+          distance = (2 | (distance & 1));\r
+          if (posSlot < kEndPosModelIndex)\r
+          {\r
+            distance <<= numDirectBits;\r
+            prob = probs + SpecPos + distance - posSlot - 1;\r
+            {\r
+              UInt32 mask = 1;\r
+              unsigned i = 1;\r
+              do\r
+              {\r
+                GET_BIT2(prob + i, i, ; , distance |= mask);\r
+                mask <<= 1;\r
+              }\r
+              while (--numDirectBits != 0);\r
+            }\r
+          }\r
+          else\r
+          {\r
+            numDirectBits -= kNumAlignBits;\r
+            do\r
+            {\r
+              NORMALIZE\r
+              range >>= 1;\r
+              \r
+              {\r
+                UInt32 t;\r
+                code -= range;\r
+                t = (0 - ((UInt32)code >> 31)); /* (UInt32)((Int32)code >> 31) */\r
+                distance = (distance << 1) + (t + 1);\r
+                code += range & t;\r
+              }\r
+              /*\r
+              distance <<= 1;\r
+              if (code >= range)\r
+              {\r
+                code -= range;\r
+                distance |= 1;\r
+              }\r
+              */\r
+            }\r
+            while (--numDirectBits != 0);\r
+            prob = probs + Align;\r
+            distance <<= kNumAlignBits;\r
+            {\r
+              unsigned i = 1;\r
+              GET_BIT2(prob + i, i, ; , distance |= 1);\r
+              GET_BIT2(prob + i, i, ; , distance |= 2);\r
+              GET_BIT2(prob + i, i, ; , distance |= 4);\r
+              GET_BIT2(prob + i, i, ; , distance |= 8);\r
+            }\r
+            if (distance == (UInt32)0xFFFFFFFF)\r
+            {\r
+              len += kMatchSpecLenStart;\r
+              state -= kNumStates;\r
+              break;\r
+            }\r
+          }\r
+        }\r
+        rep3 = rep2;\r
+        rep2 = rep1;\r
+        rep1 = rep0;\r
+        rep0 = distance + 1;\r
+        if (checkDicSize == 0)\r
+        {\r
+          if (distance >= processedPos)\r
+            return SZ_ERROR_DATA;\r
+        }\r
+        else if (distance >= checkDicSize)\r
+          return SZ_ERROR_DATA;\r
+        state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3;\r
+        /* state = kLiteralNextStates[state]; */\r
+      }\r
+\r
+      len += kMatchMinLen;\r
+\r
+      if (limit == dicPos)\r
+        return SZ_ERROR_DATA;\r
+      {\r
+        SizeT rem = limit - dicPos;\r
+        unsigned curLen = ((rem < len) ? (unsigned)rem : len);\r
+        SizeT pos = (dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0);\r
+\r
+        processedPos += curLen;\r
+\r
+        len -= curLen;\r
+        if (pos + curLen <= dicBufSize)\r
+        {\r
+          Byte *dest = dic + dicPos;\r
+          ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos;\r
+          const Byte *lim = dest + curLen;\r
+          dicPos += curLen;\r
+          do\r
+            *(dest) = (Byte)*(dest + src);\r
+          while (++dest != lim);\r
+        }\r
+        else\r
+        {\r
+          do\r
+          {\r
+            dic[dicPos++] = dic[pos];\r
+            if (++pos == dicBufSize)\r
+              pos = 0;\r
+          }\r
+          while (--curLen != 0);\r
+        }\r
+      }\r
+    }\r
+  }\r
+  while (dicPos < limit && buf < bufLimit);\r
+  NORMALIZE;\r
+  p->buf = buf;\r
+  p->range = range;\r
+  p->code = code;\r
+  p->remainLen = len;\r
+  p->dicPos = dicPos;\r
+  p->processedPos = processedPos;\r
+  p->reps[0] = rep0;\r
+  p->reps[1] = rep1;\r
+  p->reps[2] = rep2;\r
+  p->reps[3] = rep3;\r
+  p->state = state;\r
+\r
+  return SZ_OK;\r
+}\r
+\r
+static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)\r
+{\r
+  if (p->remainLen != 0 && p->remainLen < kMatchSpecLenStart)\r
+  {\r
+    Byte *dic = p->dic;\r
+    SizeT dicPos = p->dicPos;\r
+    SizeT dicBufSize = p->dicBufSize;\r
+    unsigned len = p->remainLen;\r
+    UInt32 rep0 = p->reps[0];\r
+    if (limit - dicPos < len)\r
+      len = (unsigned)(limit - dicPos);\r
+\r
+    if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= len)\r
+      p->checkDicSize = p->prop.dicSize;\r
+\r
+    p->processedPos += len;\r
+    p->remainLen -= len;\r
+    while (len-- != 0)\r
+    {\r
+      dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];\r
+      dicPos++;\r
+    }\r
+    p->dicPos = dicPos;\r
+  }\r
+}\r
+\r
+static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit)\r
+{\r
+  do\r
+  {\r
+    SizeT limit2 = limit;\r
+    if (p->checkDicSize == 0)\r
+    {\r
+      UInt32 rem = p->prop.dicSize - p->processedPos;\r
+      if (limit - p->dicPos > rem)\r
+        limit2 = p->dicPos + rem;\r
+    }\r
+    RINOK(LzmaDec_DecodeReal(p, limit2, bufLimit));\r
+    if (p->processedPos >= p->prop.dicSize)\r
+      p->checkDicSize = p->prop.dicSize;\r
+    LzmaDec_WriteRem(p, limit);\r
+  }\r
+  while (p->dicPos < limit && p->buf < bufLimit && p->remainLen < kMatchSpecLenStart);\r
+\r
+  if (p->remainLen > kMatchSpecLenStart)\r
+  {\r
+    p->remainLen = kMatchSpecLenStart;\r
+  }\r
+  return 0;\r
+}\r
+\r
+typedef enum\r
+{\r
+  DUMMY_ERROR, /* unexpected end of input stream */\r
+  DUMMY_LIT,\r
+  DUMMY_MATCH,\r
+  DUMMY_REP\r
+} ELzmaDummy;\r
+\r
+static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inSize)\r
+{\r
+  UInt32 range = p->range;\r
+  UInt32 code = p->code;\r
+  const Byte *bufLimit = buf + inSize;\r
+  CLzmaProb *probs = p->probs;\r
+  unsigned state = p->state;\r
+  ELzmaDummy res;\r
+\r
+  {\r
+    CLzmaProb *prob;\r
+    UInt32 bound;\r
+    unsigned ttt;\r
+    unsigned posState = (p->processedPos) & ((1 << p->prop.pb) - 1);\r
+\r
+    prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;\r
+    IF_BIT_0_CHECK(prob)\r
+    {\r
+      UPDATE_0_CHECK\r
+\r
+      /* if (bufLimit - buf >= 7) return DUMMY_LIT; */\r
+\r
+      prob = probs + Literal;\r
+      if (p->checkDicSize != 0 || p->processedPos != 0)\r
+        prob += (LZMA_LIT_SIZE *\r
+          ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) +\r
+          (p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));\r
+\r
+      if (state < kNumLitStates)\r
+      {\r
+        unsigned symbol = 1;\r
+        do { GET_BIT_CHECK(prob + symbol, symbol) } while (symbol < 0x100);\r
+      }\r
+      else\r
+      {\r
+        unsigned matchByte = p->dic[p->dicPos - p->reps[0] +\r
+            ((p->dicPos < p->reps[0]) ? p->dicBufSize : 0)];\r
+        unsigned offs = 0x100;\r
+        unsigned symbol = 1;\r
+        do\r
+        {\r
+          unsigned bit;\r
+          CLzmaProb *probLit;\r
+          matchByte <<= 1;\r
+          bit = (matchByte & offs);\r
+          probLit = prob + offs + bit + symbol;\r
+          GET_BIT2_CHECK(probLit, symbol, offs &= ~bit, offs &= bit)\r
+        }\r
+        while (symbol < 0x100);\r
+      }\r
+      res = DUMMY_LIT;\r
+    }\r
+    else\r
+    {\r
+      unsigned len;\r
+      UPDATE_1_CHECK;\r
+\r
+      prob = probs + IsRep + state;\r
+      IF_BIT_0_CHECK(prob)\r
+      {\r
+        UPDATE_0_CHECK;\r
+        state = 0;\r
+        prob = probs + LenCoder;\r
+        res = DUMMY_MATCH;\r
+      }\r
+      else\r
+      {\r
+        UPDATE_1_CHECK;\r
+        res = DUMMY_REP;\r
+        prob = probs + IsRepG0 + state;\r
+        IF_BIT_0_CHECK(prob)\r
+        {\r
+          UPDATE_0_CHECK;\r
+          prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;\r
+          IF_BIT_0_CHECK(prob)\r
+          {\r
+            UPDATE_0_CHECK;\r
+            NORMALIZE_CHECK;\r
+            return DUMMY_REP;\r
+          }\r
+          else\r
+          {\r
+            UPDATE_1_CHECK;\r
+          }\r
+        }\r
+        else\r
+        {\r
+          UPDATE_1_CHECK;\r
+          prob = probs + IsRepG1 + state;\r
+          IF_BIT_0_CHECK(prob)\r
+          {\r
+            UPDATE_0_CHECK;\r
+          }\r
+          else\r
+          {\r
+            UPDATE_1_CHECK;\r
+            prob = probs + IsRepG2 + state;\r
+            IF_BIT_0_CHECK(prob)\r
+            {\r
+              UPDATE_0_CHECK;\r
+            }\r
+            else\r
+            {\r
+              UPDATE_1_CHECK;\r
+            }\r
+          }\r
+        }\r
+        state = kNumStates;\r
+        prob = probs + RepLenCoder;\r
+      }\r
+      {\r
+        unsigned limit, offset;\r
+        CLzmaProb *probLen = prob + LenChoice;\r
+        IF_BIT_0_CHECK(probLen)\r
+        {\r
+          UPDATE_0_CHECK;\r
+          probLen = prob + LenLow + (posState << kLenNumLowBits);\r
+          offset = 0;\r
+          limit = 1 << kLenNumLowBits;\r
+        }\r
+        else\r
+        {\r
+          UPDATE_1_CHECK;\r
+          probLen = prob + LenChoice2;\r
+          IF_BIT_0_CHECK(probLen)\r
+          {\r
+            UPDATE_0_CHECK;\r
+            probLen = prob + LenMid + (posState << kLenNumMidBits);\r
+            offset = kLenNumLowSymbols;\r
+            limit = 1 << kLenNumMidBits;\r
+          }\r
+          else\r
+          {\r
+            UPDATE_1_CHECK;\r
+            probLen = prob + LenHigh;\r
+            offset = kLenNumLowSymbols + kLenNumMidSymbols;\r
+            limit = 1 << kLenNumHighBits;\r
+          }\r
+        }\r
+        TREE_DECODE_CHECK(probLen, limit, len);\r
+        len += offset;\r
+      }\r
+\r
+      if (state < 4)\r
+      {\r
+        unsigned posSlot;\r
+        prob = probs + PosSlot +\r
+            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<\r
+            kNumPosSlotBits);\r
+        TREE_DECODE_CHECK(prob, 1 << kNumPosSlotBits, posSlot);\r
+        if (posSlot >= kStartPosModelIndex)\r
+        {\r
+          int numDirectBits = ((posSlot >> 1) - 1);\r
+\r
+          /* if (bufLimit - buf >= 8) return DUMMY_MATCH; */\r
+\r
+          if (posSlot < kEndPosModelIndex)\r
+          {\r
+            prob = probs + SpecPos + ((2 | (posSlot & 1)) << numDirectBits) - posSlot - 1;\r
+          }\r
+          else\r
+          {\r
+            numDirectBits -= kNumAlignBits;\r
+            do\r
+            {\r
+              NORMALIZE_CHECK\r
+              range >>= 1;\r
+              code -= range & (((code - range) >> 31) - 1);\r
+              /* if (code >= range) code -= range; */\r
+            }\r
+            while (--numDirectBits != 0);\r
+            prob = probs + Align;\r
+            numDirectBits = kNumAlignBits;\r
+          }\r
+          {\r
+            unsigned i = 1;\r
+            do\r
+            {\r
+              GET_BIT_CHECK(prob + i, i);\r
+            }\r
+            while (--numDirectBits != 0);\r
+          }\r
+        }\r
+      }\r
+    }\r
+  }\r
+  NORMALIZE_CHECK;\r
+  return res;\r
+}\r
+\r
+static void LzmaDec_InitRc(CLzmaDec *p, const Byte *data)\r
+{\r
+  p->code = ((UInt32)data[1] << 24) | ((UInt32)data[2] << 16) | ((UInt32)data[3] << 8) | ((UInt32)data[4]);\r
+  p->range = 0xFFFFFFFF;\r
+  p->needFlush = 0;\r
+}\r
+\r
+void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)\r
+{\r
+  p->needFlush = 1;\r
+  p->remainLen = 0;\r
+  p->tempBufSize = 0;\r
+\r
+  if (initDic)\r
+  {\r
+    p->processedPos = 0;\r
+    p->checkDicSize = 0;\r
+    p->needInitState = 1;\r
+  }\r
+  if (initState)\r
+    p->needInitState = 1;\r
+}\r
+\r
+void LzmaDec_Init(CLzmaDec *p)\r
+{\r
+  p->dicPos = 0;\r
+  LzmaDec_InitDicAndState(p, True, True);\r
+}\r
+\r
+static void LzmaDec_InitStateReal(CLzmaDec *p)\r
+{\r
+  UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (p->prop.lc + p->prop.lp));\r
+  UInt32 i;\r
+  CLzmaProb *probs = p->probs;\r
+  for (i = 0; i < numProbs; i++)\r
+    probs[i] = kBitModelTotal >> 1;\r
+  p->reps[0] = p->reps[1] = p->reps[2] = p->reps[3] = 1;\r
+  p->state = 0;\r
+  p->needInitState = 0;\r
+}\r
+\r
+SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen,\r
+    ELzmaFinishMode finishMode, ELzmaStatus *status)\r
+{\r
+  SizeT inSize = *srcLen;\r
+  (*srcLen) = 0;\r
+  LzmaDec_WriteRem(p, dicLimit);\r
+  \r
+  *status = LZMA_STATUS_NOT_SPECIFIED;\r
+\r
+  while (p->remainLen != kMatchSpecLenStart)\r
+  {\r
+      int checkEndMarkNow;\r
+\r
+      if (p->needFlush != 0)\r
+      {\r
+        for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--)\r
+          p->tempBuf[p->tempBufSize++] = *src++;\r
+        if (p->tempBufSize < RC_INIT_SIZE)\r
+        {\r
+          *status = LZMA_STATUS_NEEDS_MORE_INPUT;\r
+          return SZ_OK;\r
+        }\r
+        if (p->tempBuf[0] != 0)\r
+          return SZ_ERROR_DATA;\r
+\r
+        LzmaDec_InitRc(p, p->tempBuf);\r
+        p->tempBufSize = 0;\r
+      }\r
+\r
+      checkEndMarkNow = 0;\r
+      if (p->dicPos >= dicLimit)\r
+      {\r
+        if (p->remainLen == 0 && p->code == 0)\r
+        {\r
+          *status = LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK;\r
+          return SZ_OK;\r
+        }\r
+        if (finishMode == LZMA_FINISH_ANY)\r
+        {\r
+          *status = LZMA_STATUS_NOT_FINISHED;\r
+          return SZ_OK;\r
+        }\r
+        if (p->remainLen != 0)\r
+        {\r
+          *status = LZMA_STATUS_NOT_FINISHED;\r
+          return SZ_ERROR_DATA;\r
+        }\r
+        checkEndMarkNow = 1;\r
+      }\r
+\r
+      if (p->needInitState)\r
+        LzmaDec_InitStateReal(p);\r
+  \r
+      if (p->tempBufSize == 0)\r
+      {\r
+        SizeT processed;\r
+        const Byte *bufLimit;\r
+        if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)\r
+        {\r
+          int dummyRes = LzmaDec_TryDummy(p, src, inSize);\r
+          if (dummyRes == DUMMY_ERROR)\r
+          {\r
+            memcpy(p->tempBuf, src, inSize);\r
+            p->tempBufSize = (unsigned)inSize;\r
+            (*srcLen) += inSize;\r
+            *status = LZMA_STATUS_NEEDS_MORE_INPUT;\r
+            return SZ_OK;\r
+          }\r
+          if (checkEndMarkNow && dummyRes != DUMMY_MATCH)\r
+          {\r
+            *status = LZMA_STATUS_NOT_FINISHED;\r
+            return SZ_ERROR_DATA;\r
+          }\r
+          bufLimit = src;\r
+        }\r
+        else\r
+          bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX;\r
+        p->buf = src;\r
+        if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0)\r
+          return SZ_ERROR_DATA;\r
+        processed = (SizeT)(p->buf - src);\r
+        (*srcLen) += processed;\r
+        src += processed;\r
+        inSize -= processed;\r
+      }\r
+      else\r
+      {\r
+        unsigned rem = p->tempBufSize, lookAhead = 0;\r
+        while (rem < LZMA_REQUIRED_INPUT_MAX && lookAhead < inSize)\r
+          p->tempBuf[rem++] = src[lookAhead++];\r
+        p->tempBufSize = rem;\r
+        if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)\r
+        {\r
+          int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, rem);\r
+          if (dummyRes == DUMMY_ERROR)\r
+          {\r
+            (*srcLen) += lookAhead;\r
+            *status = LZMA_STATUS_NEEDS_MORE_INPUT;\r
+            return SZ_OK;\r
+          }\r
+          if (checkEndMarkNow && dummyRes != DUMMY_MATCH)\r
+          {\r
+            *status = LZMA_STATUS_NOT_FINISHED;\r
+            return SZ_ERROR_DATA;\r
+          }\r
+        }\r
+        p->buf = p->tempBuf;\r
+        if (LzmaDec_DecodeReal2(p, dicLimit, p->buf) != 0)\r
+          return SZ_ERROR_DATA;\r
+        lookAhead -= (rem - (unsigned)(p->buf - p->tempBuf));\r
+        (*srcLen) += lookAhead;\r
+        src += lookAhead;\r
+        inSize -= lookAhead;\r
+        p->tempBufSize = 0;\r
+      }\r
+  }\r
+  if (p->code == 0)\r
+    *status = LZMA_STATUS_FINISHED_WITH_MARK;\r
+  return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA;\r
+}\r
+\r
+SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)\r
+{\r
+  SizeT outSize = *destLen;\r
+  SizeT inSize = *srcLen;\r
+  *srcLen = *destLen = 0;\r
+  for (;;)\r
+  {\r
+    SizeT inSizeCur = inSize, outSizeCur, dicPos;\r
+    ELzmaFinishMode curFinishMode;\r
+    SRes res;\r
+    if (p->dicPos == p->dicBufSize)\r
+      p->dicPos = 0;\r
+    dicPos = p->dicPos;\r
+    if (outSize > p->dicBufSize - dicPos)\r
+    {\r
+      outSizeCur = p->dicBufSize;\r
+      curFinishMode = LZMA_FINISH_ANY;\r
+    }\r
+    else\r
+    {\r
+      outSizeCur = dicPos + outSize;\r
+      curFinishMode = finishMode;\r
+    }\r
+\r
+    res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status);\r
+    src += inSizeCur;\r
+    inSize -= inSizeCur;\r
+    *srcLen += inSizeCur;\r
+    outSizeCur = p->dicPos - dicPos;\r
+    memcpy(dest, p->dic + dicPos, outSizeCur);\r
+    dest += outSizeCur;\r
+    outSize -= outSizeCur;\r
+    *destLen += outSizeCur;\r
+    if (res != 0)\r
+      return res;\r
+    if (outSizeCur == 0 || outSize == 0)\r
+      return SZ_OK;\r
+  }\r
+}\r
+\r
+void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)\r
+{\r
+  alloc->Free(alloc, p->probs);\r
+  p->probs = 0;\r
+}\r
+\r
+static void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc)\r
+{\r
+  alloc->Free(alloc, p->dic);\r
+  p->dic = 0;\r
+}\r
+\r
+void LzmaDec_Free(CLzmaDec *p, ISzAlloc *alloc)\r
+{\r
+  LzmaDec_FreeProbs(p, alloc);\r
+  LzmaDec_FreeDict(p, alloc);\r
+}\r
+\r
+SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)\r
+{\r
+  UInt32 dicSize;\r
+  Byte d;\r
+  \r
+  if (size < LZMA_PROPS_SIZE)\r
+    return SZ_ERROR_UNSUPPORTED;\r
+  else\r
+    dicSize = data[1] | ((UInt32)data[2] << 8) | ((UInt32)data[3] << 16) | ((UInt32)data[4] << 24);\r
\r
+  if (dicSize < LZMA_DIC_MIN)\r
+    dicSize = LZMA_DIC_MIN;\r
+  p->dicSize = dicSize;\r
+\r
+  d = data[0];\r
+  if (d >= (9 * 5 * 5))\r
+    return SZ_ERROR_UNSUPPORTED;\r
+\r
+  p->lc = d % 9;\r
+  d /= 9;\r
+  p->pb = d / 5;\r
+  p->lp = d % 5;\r
+\r
+  return SZ_OK;\r
+}\r
+\r
+static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc)\r
+{\r
+  UInt32 numProbs = LzmaProps_GetNumProbs(propNew);\r
+  if (p->probs == 0 || numProbs != p->numProbs)\r
+  {\r
+    LzmaDec_FreeProbs(p, alloc);\r
+    p->probs = (CLzmaProb *)alloc->Alloc(alloc, numProbs * sizeof(CLzmaProb));\r
+    p->numProbs = numProbs;\r
+    if (p->probs == 0)\r
+      return SZ_ERROR_MEM;\r
+  }\r
+  return SZ_OK;\r
+}\r
+\r
+SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)\r
+{\r
+  CLzmaProps propNew;\r
+  RINOK(LzmaProps_Decode(&propNew, props, propsSize));\r
+  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));\r
+  p->prop = propNew;\r
+  return SZ_OK;\r
+}\r
+\r
+SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)\r
+{\r
+  CLzmaProps propNew;\r
+  SizeT dicBufSize;\r
+  RINOK(LzmaProps_Decode(&propNew, props, propsSize));\r
+  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));\r
+  dicBufSize = propNew.dicSize;\r
+  if (p->dic == 0 || dicBufSize != p->dicBufSize)\r
+  {\r
+    LzmaDec_FreeDict(p, alloc);\r
+    p->dic = (Byte *)alloc->Alloc(alloc, dicBufSize);\r
+    if (p->dic == 0)\r
+    {\r
+      LzmaDec_FreeProbs(p, alloc);\r
+      return SZ_ERROR_MEM;\r
+    }\r
+  }\r
+  p->dicBufSize = dicBufSize;\r
+  p->prop = propNew;\r
+  return SZ_OK;\r
+}\r
+\r
+SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\r
+    const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,\r
+    ELzmaStatus *status, ISzAlloc *alloc)\r
+{\r
+  CLzmaDec p;\r
+  SRes res;\r
+  SizeT inSize = *srcLen;\r
+  SizeT outSize = *destLen;\r
+  *srcLen = *destLen = 0;\r
+  if (inSize < RC_INIT_SIZE)\r
+    return SZ_ERROR_INPUT_EOF;\r
+\r
+  LzmaDec_Construct(&p);\r
+  res = LzmaDec_AllocateProbs(&p, propData, propSize, alloc);\r
+  if (res != 0)\r
+    return res;\r
+  p.dic = dest;\r
+  p.dicBufSize = outSize;\r
+\r
+  LzmaDec_Init(&p);\r
+  \r
+  *srcLen = inSize;\r
+  res = LzmaDec_DecodeToDic(&p, outSize, src, srcLen, finishMode, status);\r
+\r
+  if (res == SZ_OK && *status == LZMA_STATUS_NEEDS_MORE_INPUT)\r
+    res = SZ_ERROR_INPUT_EOF;\r
+\r
+  (*destLen) = p.dicPos;\r
+  LzmaDec_FreeProbs(&p, alloc);\r
+  return res;\r
+}\r
+\r
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzmaDec.h b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzmaDec.h
new file mode 100644 (file)
index 0000000..ad7d705
--- /dev/null
@@ -0,0 +1,223 @@
+/* LzmaDec.h -- LZMA Decoder\r
+2008-10-04 : Igor Pavlov : Public domain */\r
+\r
+#ifndef __LZMADEC_H\r
+#define __LZMADEC_H\r
+\r
+#include "Types.h"\r
+\r
+/* #define _LZMA_PROB32 */\r
+/* _LZMA_PROB32 can increase the speed on some CPUs,\r
+   but memory usage for CLzmaDec::probs will be doubled in that case */\r
+\r
+#ifdef _LZMA_PROB32\r
+#define CLzmaProb UInt32\r
+#else\r
+#define CLzmaProb UInt16\r
+#endif\r
+\r
+\r
+/* ---------- LZMA Properties ---------- */\r
+\r
+#define LZMA_PROPS_SIZE 5\r
+\r
+typedef struct _CLzmaProps\r
+{\r
+  unsigned lc, lp, pb;\r
+  UInt32 dicSize;\r
+} CLzmaProps;\r
+\r
+/* LzmaProps_Decode - decodes properties\r
+Returns:\r
+  SZ_OK\r
+  SZ_ERROR_UNSUPPORTED - Unsupported properties\r
+*/\r
+\r
+SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);\r
+\r
+\r
+/* ---------- LZMA Decoder state ---------- */\r
+\r
+/* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.\r
+   Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */\r
+\r
+#define LZMA_REQUIRED_INPUT_MAX 20\r
+\r
+typedef struct\r
+{\r
+  CLzmaProps prop;\r
+  CLzmaProb *probs;\r
+  Byte *dic;\r
+  const Byte *buf;\r
+  UInt32 range, code;\r
+  SizeT dicPos;\r
+  SizeT dicBufSize;\r
+  UInt32 processedPos;\r
+  UInt32 checkDicSize;\r
+  unsigned state;\r
+  UInt32 reps[4];\r
+  unsigned remainLen;\r
+  int needFlush;\r
+  int needInitState;\r
+  UInt32 numProbs;\r
+  unsigned tempBufSize;\r
+  Byte tempBuf[LZMA_REQUIRED_INPUT_MAX];\r
+} CLzmaDec;\r
+\r
+#define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }\r
+\r
+void LzmaDec_Init(CLzmaDec *p);\r
+\r
+/* There are two types of LZMA streams:\r
+     0) Stream with end mark. That end mark adds about 6 bytes to compressed size.\r
+     1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */\r
+\r
+typedef enum\r
+{\r
+  LZMA_FINISH_ANY,   /* finish at any point */\r
+  LZMA_FINISH_END    /* block must be finished at the end */\r
+} ELzmaFinishMode;\r
+\r
+/* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!\r
+\r
+   You must use LZMA_FINISH_END, when you know that current output buffer\r
+   covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.\r
+\r
+   If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,\r
+   and output value of destLen will be less than output buffer size limit.\r
+   You can check status result also.\r
+\r
+   You can use multiple checks to test data integrity after full decompression:\r
+     1) Check Result and "status" variable.\r
+     2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.\r
+     3) Check that output(srcLen) = compressedSize, if you know real compressedSize.\r
+        You must use correct finish mode in that case. */\r
+\r
+typedef enum\r
+{\r
+  LZMA_STATUS_NOT_SPECIFIED,               /* use main error code instead */\r
+  LZMA_STATUS_FINISHED_WITH_MARK,          /* stream was finished with end mark. */\r
+  LZMA_STATUS_NOT_FINISHED,                /* stream was not finished */\r
+  LZMA_STATUS_NEEDS_MORE_INPUT,            /* you must provide more input bytes */\r
+  LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK  /* there is probability that stream was finished without end mark */\r
+} ELzmaStatus;\r
+\r
+/* ELzmaStatus is used only as output value for function call */\r
+\r
+\r
+/* ---------- Interfaces ---------- */\r
+\r
+/* There are 3 levels of interfaces:\r
+     1) Dictionary Interface\r
+     2) Buffer Interface\r
+     3) One Call Interface\r
+   You can select any of these interfaces, but don't mix functions from different\r
+   groups for same object. */\r
+\r
+\r
+/* There are two variants to allocate state for Dictionary Interface:\r
+     1) LzmaDec_Allocate / LzmaDec_Free\r
+     2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs\r
+   You can use variant 2, if you set dictionary buffer manually.\r
+   For Buffer Interface you must always use variant 1.\r
+\r
+LzmaDec_Allocate* can return:\r
+  SZ_OK\r
+  SZ_ERROR_MEM         - Memory allocation error\r
+  SZ_ERROR_UNSUPPORTED - Unsupported properties\r
+*/\r
+   \r
+SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc);\r
+void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc);\r
+\r
+SRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc);\r
+void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc);\r
+\r
+/* ---------- Dictionary Interface ---------- */\r
+\r
+/* You can use it, if you want to eliminate the overhead for data copying from\r
+   dictionary to some other external buffer.\r
+   You must work with CLzmaDec variables directly in this interface.\r
+\r
+   STEPS:\r
+     LzmaDec_Constr()\r
+     LzmaDec_Allocate()\r
+     for (each new stream)\r
+     {\r
+       LzmaDec_Init()\r
+       while (it needs more decompression)\r
+       {\r
+         LzmaDec_DecodeToDic()\r
+         use data from CLzmaDec::dic and update CLzmaDec::dicPos\r
+       }\r
+     }\r
+     LzmaDec_Free()\r
+*/\r
+\r
+/* LzmaDec_DecodeToDic\r
+   \r
+   The decoding to internal dictionary buffer (CLzmaDec::dic).\r
+   You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!\r
+\r
+finishMode:\r
+  It has meaning only if the decoding reaches output limit (dicLimit).\r
+  LZMA_FINISH_ANY - Decode just dicLimit bytes.\r
+  LZMA_FINISH_END - Stream must be finished after dicLimit.\r
+\r
+Returns:\r
+  SZ_OK\r
+    status:\r
+      LZMA_STATUS_FINISHED_WITH_MARK\r
+      LZMA_STATUS_NOT_FINISHED\r
+      LZMA_STATUS_NEEDS_MORE_INPUT\r
+      LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK\r
+  SZ_ERROR_DATA - Data error\r
+*/\r
+\r
+SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,\r
+    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);\r
+\r
+\r
+/* ---------- Buffer Interface ---------- */\r
+\r
+/* It's zlib-like interface.\r
+   See LzmaDec_DecodeToDic description for information about STEPS and return results,\r
+   but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need\r
+   to work with CLzmaDec variables manually.\r
+\r
+finishMode:\r
+  It has meaning only if the decoding reaches output limit (*destLen).\r
+  LZMA_FINISH_ANY - Decode just destLen bytes.\r
+  LZMA_FINISH_END - Stream must be finished after (*destLen).\r
+*/\r
+\r
+SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,\r
+    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);\r
+\r
+\r
+/* ---------- One Call Interface ---------- */\r
+\r
+/* LzmaDecode\r
+\r
+finishMode:\r
+  It has meaning only if the decoding reaches output limit (*destLen).\r
+  LZMA_FINISH_ANY - Decode just destLen bytes.\r
+  LZMA_FINISH_END - Stream must be finished after (*destLen).\r
+\r
+Returns:\r
+  SZ_OK\r
+    status:\r
+      LZMA_STATUS_FINISHED_WITH_MARK\r
+      LZMA_STATUS_NOT_FINISHED\r
+      LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK\r
+  SZ_ERROR_DATA - Data error\r
+  SZ_ERROR_MEM  - Memory allocation error\r
+  SZ_ERROR_UNSUPPORTED - Unsupported properties\r
+  SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).\r
+*/\r
+\r
+SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\r
+    const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,\r
+    ELzmaStatus *status, ISzAlloc *alloc);\r
+\r
+#endif\r
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Types.h b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Types.h
new file mode 100644 (file)
index 0000000..27396e8
--- /dev/null
@@ -0,0 +1,231 @@
+/** @file\r
+  Types.h\r
+\r
+  Based on LZMA SDK 4.65:\r
+    Types.h -- Basic types\r
+    2008-11-23 : Igor Pavlov : Public domain\r
+\r
+  Copyright (c) 2009, Intel Corporation<BR>\r
+  All rights reserved. This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __7Z_TYPES_H\r
+#define __7Z_TYPES_H\r
+\r
+#ifdef EFIAPI\r
+\r
+#include "UefiLzma.h"\r
+\r
+#else\r
+\r
+#include <stddef.h>\r
+\r
+#ifdef _WIN32\r
+#include <windows.h>\r
+#endif\r
+\r
+#endif\r
+\r
+#define SZ_OK 0\r
+\r
+#define SZ_ERROR_DATA 1\r
+#define SZ_ERROR_MEM 2\r
+#define SZ_ERROR_CRC 3\r
+#define SZ_ERROR_UNSUPPORTED 4\r
+#define SZ_ERROR_PARAM 5\r
+#define SZ_ERROR_INPUT_EOF 6\r
+#define SZ_ERROR_OUTPUT_EOF 7\r
+#define SZ_ERROR_READ 8\r
+#define SZ_ERROR_WRITE 9\r
+#define SZ_ERROR_PROGRESS 10\r
+#define SZ_ERROR_FAIL 11\r
+#define SZ_ERROR_THREAD 12\r
+\r
+#define SZ_ERROR_ARCHIVE 16\r
+#define SZ_ERROR_NO_ARCHIVE 17\r
+\r
+typedef int SRes;\r
+\r
+#ifdef _WIN32\r
+typedef DWORD WRes;\r
+#else\r
+typedef int WRes;\r
+#endif\r
+\r
+#ifndef RINOK\r
+#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }\r
+#endif\r
+\r
+typedef unsigned char Byte;\r
+typedef short Int16;\r
+typedef unsigned short UInt16;\r
+\r
+#ifdef _LZMA_UINT32_IS_ULONG\r
+typedef long Int32;\r
+typedef unsigned long UInt32;\r
+#else\r
+typedef int Int32;\r
+typedef unsigned int UInt32;\r
+#endif\r
+\r
+#ifdef _SZ_NO_INT_64\r
+\r
+/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.\r
+   NOTES: Some code will work incorrectly in that case! */\r
+\r
+typedef long Int64;\r
+typedef unsigned long UInt64;\r
+\r
+#else\r
+\r
+#if defined(_MSC_VER) || defined(__BORLANDC__)\r
+typedef __int64 Int64;\r
+typedef unsigned __int64 UInt64;\r
+#else\r
+typedef long long int Int64;\r
+typedef unsigned long long int UInt64;\r
+#endif\r
+\r
+#endif\r
+\r
+#ifdef _LZMA_NO_SYSTEM_SIZE_T\r
+typedef UInt32 SizeT;\r
+#else\r
+typedef size_t SizeT;\r
+#endif\r
+\r
+typedef int Bool;\r
+#define True 1\r
+#define False 0\r
+\r
+\r
+#ifdef _MSC_VER\r
+\r
+#if _MSC_VER >= 1300\r
+#define MY_NO_INLINE __declspec(noinline)\r
+#else\r
+#define MY_NO_INLINE\r
+#endif\r
+\r
+#define MY_CDECL __cdecl\r
+#define MY_STD_CALL __stdcall\r
+#define MY_FAST_CALL MY_NO_INLINE __fastcall\r
+\r
+#else\r
+\r
+#define MY_CDECL\r
+#define MY_STD_CALL\r
+#define MY_FAST_CALL\r
+\r
+#endif\r
+\r
+\r
+/* The following interfaces use first parameter as pointer to structure */\r
+\r
+typedef struct\r
+{\r
+  SRes (*Read)(void *p, void *buf, size_t *size);\r
+    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.\r
+       (output(*size) < input(*size)) is allowed */\r
+} ISeqInStream;\r
+\r
+/* it can return SZ_ERROR_INPUT_EOF */\r
+SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);\r
+SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);\r
+SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);\r
+\r
+typedef struct\r
+{\r
+  size_t (*Write)(void *p, const void *buf, size_t size);\r
+    /* Returns: result - the number of actually written bytes.\r
+       (result < size) means error */\r
+} ISeqOutStream;\r
+\r
+typedef enum\r
+{\r
+  SZ_SEEK_SET = 0,\r
+  SZ_SEEK_CUR = 1,\r
+  SZ_SEEK_END = 2\r
+} ESzSeek;\r
+\r
+typedef struct\r
+{\r
+  SRes (*Read)(void *p, void *buf, size_t *size);  /* same as ISeqInStream::Read */\r
+  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);\r
+} ISeekInStream;\r
+\r
+typedef struct\r
+{\r
+  SRes (*Look)(void *p, void **buf, size_t *size);\r
+    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.\r
+       (output(*size) > input(*size)) is not allowed\r
+       (output(*size) < input(*size)) is allowed */\r
+  SRes (*Skip)(void *p, size_t offset);\r
+    /* offset must be <= output(*size) of Look */\r
+\r
+  SRes (*Read)(void *p, void *buf, size_t *size);\r
+    /* reads directly (without buffer). It's same as ISeqInStream::Read */\r
+  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);\r
+} ILookInStream;\r
+\r
+SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);\r
+SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);\r
+\r
+/* reads via ILookInStream::Read */\r
+SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);\r
+SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);\r
+\r
+#define LookToRead_BUF_SIZE (1 << 14)\r
+\r
+typedef struct\r
+{\r
+  ILookInStream s;\r
+  ISeekInStream *realStream;\r
+  size_t pos;\r
+  size_t size;\r
+  Byte buf[LookToRead_BUF_SIZE];\r
+} CLookToRead;\r
+\r
+void LookToRead_CreateVTable(CLookToRead *p, int lookahead);\r
+void LookToRead_Init(CLookToRead *p);\r
+\r
+typedef struct\r
+{\r
+  ISeqInStream s;\r
+  ILookInStream *realStream;\r
+} CSecToLook;\r
+\r
+void SecToLook_CreateVTable(CSecToLook *p);\r
+\r
+typedef struct\r
+{\r
+  ISeqInStream s;\r
+  ILookInStream *realStream;\r
+} CSecToRead;\r
+\r
+void SecToRead_CreateVTable(CSecToRead *p);\r
+\r
+typedef struct\r
+{\r
+  SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);\r
+    /* Returns: result. (result != SZ_OK) means break.\r
+       Value (UInt64)(Int64)-1 for size means unknown value. */\r
+} ICompressProgress;\r
+\r
+typedef struct\r
+{\r
+  void *(*Alloc)(void *p, size_t size);\r
+  void (*Free)(void *p, void *address); /* address can be 0 */\r
+} ISzAlloc;\r
+\r
+#define IAlloc_Alloc(p, size) (p)->Alloc((p), size)\r
+#define IAlloc_Free(p, a) (p)->Free((p), a)\r
+\r
+#endif\r
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/history.txt b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/history.txt
new file mode 100644 (file)
index 0000000..9bed5eb
--- /dev/null
@@ -0,0 +1,236 @@
+HISTORY of the LZMA SDK\r
+-----------------------\r
+\r
+4.65           2009-02-03\r
+-------------------------\r
+- Some minor fixes\r
+\r
+\r
+4.63           2008-12-31\r
+-------------------------\r
+- Some minor fixes\r
+\r
+\r
+4.61 beta      2008-11-23\r
+-------------------------\r
+- The bug in ANSI-C LZMA Decoder was fixed:\r
+    If encoded stream was corrupted, decoder could access memory \r
+    outside of allocated range.\r
+- Some changes in ANSI-C 7z Decoder interfaces.\r
+- LZMA SDK is placed in the public domain.\r
+\r
+\r
+4.60 beta      2008-08-19\r
+-------------------------\r
+- Some minor fixes.\r
+\r
+\r
+4.59 beta      2008-08-13\r
+-------------------------\r
+- The bug was fixed:\r
+    LZMA Encoder in fast compression mode could access memory outside of \r
+    allocated range in some rare cases.\r
+\r
+\r
+4.58 beta      2008-05-05\r
+-------------------------\r
+- ANSI-C LZMA Decoder was rewritten for speed optimizations.\r
+- ANSI-C LZMA Encoder was included to LZMA SDK.\r
+- C++ LZMA code now is just wrapper over ANSI-C code.\r
+\r
+\r
+4.57           2007-12-12\r
+-------------------------\r
+- Speed optimizations in Ã‘++ LZMA Decoder. \r
+- Small changes for more compatibility with some C/C++ compilers.\r
+\r
+\r
+4.49 beta      2007-07-05\r
+-------------------------\r
+- .7z ANSI-C Decoder:\r
+     - now it supports BCJ and BCJ2 filters\r
+     - now it supports files larger than 4 GB.\r
+     - now it supports "Last Write Time" field for files.\r
+- C++ code for .7z archives compressing/decompressing from 7-zip \r
+  was included to LZMA SDK.\r
+  \r
+\r
+4.43           2006-06-04\r
+-------------------------\r
+- Small changes for more compatibility with some C/C++ compilers.\r
+  \r
+\r
+4.42           2006-05-15\r
+-------------------------\r
+- Small changes in .h files in ANSI-C version.\r
+  \r
+\r
+4.39 beta      2006-04-14\r
+-------------------------\r
+- The bug in versions 4.33b:4.38b was fixed:\r
+  C++ version of LZMA encoder could not correctly compress \r
+  files larger than 2 GB with HC4 match finder (-mfhc4).\r
+  \r
+\r
+4.37 beta      2005-04-06\r
+-------------------------\r
+- Fixes in C++ code: code could no be compiled if _NO_EXCEPTIONS was defined. \r
+\r
+\r
+4.35 beta      2005-03-02\r
+-------------------------\r
+- The bug was fixed in C++ version of LZMA Decoder:\r
+    If encoded stream was corrupted, decoder could access memory \r
+    outside of allocated range.\r
+\r
+\r
+4.34 beta      2006-02-27\r
+-------------------------\r
+- Compressing speed and memory requirements for compressing were increased\r
+- LZMA now can use only these match finders: HC4, BT2, BT3, BT4\r
+\r
+\r
+4.32           2005-12-09\r
+-------------------------\r
+- Java version of LZMA SDK was included\r
+\r
+\r
+4.30           2005-11-20\r
+-------------------------\r
+- Compression ratio was improved in -a2 mode\r
+- Speed optimizations for compressing in -a2 mode\r
+- -fb switch now supports values up to 273\r
+- The bug in 7z_C (7zIn.c) was fixed:\r
+  It used Alloc/Free functions from different memory pools.\r
+  So if program used two memory pools, it worked incorrectly.\r
+- 7z_C: .7z format supporting was improved\r
+- LZMA# SDK (C#.NET version) was included\r
+\r
+\r
+4.27 (Updated) 2005-09-21\r
+-------------------------\r
+- Some GUIDs/interfaces in C++ were changed.\r
+ IStream.h:\r
+   ISequentialInStream::Read now works as old ReadPart\r
+   ISequentialOutStream::Write now works as old WritePart\r
+\r
+\r
+4.27           2005-08-07\r
+-------------------------\r
+- The bug in LzmaDecodeSize.c was fixed:\r
+   if _LZMA_IN_CB and _LZMA_OUT_READ were defined,\r
+   decompressing worked incorrectly.\r
+\r
+\r
+4.26           2005-08-05\r
+-------------------------\r
+- Fixes in 7z_C code and LzmaTest.c:\r
+  previous versions could work incorrectly,\r
+  if malloc(0) returns 0\r
+\r
+\r
+4.23           2005-06-29\r
+-------------------------\r
+- Small fixes in C++ code\r
+\r
+\r
+4.22           2005-06-10\r
+-------------------------\r
+- Small fixes\r
+\r
+\r
+4.21           2005-06-08\r
+-------------------------\r
+- Interfaces for ANSI-C LZMA Decoder (LzmaDecode.c) were changed\r
+- New additional version of ANSI-C LZMA Decoder with zlib-like interface:\r
+    - LzmaStateDecode.h\r
+    - LzmaStateDecode.c\r
+    - LzmaStateTest.c\r
+- ANSI-C LZMA Decoder now can decompress files larger than 4 GB\r
+\r
+\r
+4.17           2005-04-18\r
+-------------------------\r
+- New example for RAM->RAM compressing/decompressing: \r
+  LZMA + BCJ (filter for x86 code):\r
+    - LzmaRam.h\r
+    - LzmaRam.cpp\r
+    - LzmaRamDecode.h\r
+    - LzmaRamDecode.c\r
+    - -f86 switch for lzma.exe\r
+\r
+\r
+4.16           2005-03-29\r
+-------------------------\r
+- The bug was fixed in LzmaDecode.c (ANSI-C LZMA Decoder): \r
+   If _LZMA_OUT_READ was defined, and if encoded stream was corrupted,\r
+   decoder could access memory outside of allocated range.\r
+- Speed optimization of ANSI-C LZMA Decoder (now it's about 20% faster).\r
+  Old version of LZMA Decoder now is in file LzmaDecodeSize.c. \r
+  LzmaDecodeSize.c can provide slightly smaller code than LzmaDecode.c\r
+- Small speed optimization in LZMA C++ code\r
+- filter for SPARC's code was added\r
+- Simplified version of .7z ANSI-C Decoder was included\r
+\r
+\r
+4.06           2004-09-05\r
+-------------------------\r
+- The bug in v4.05 was fixed:\r
+    LZMA-Encoder didn't release output stream in some cases.\r
+\r
+\r
+4.05           2004-08-25\r
+-------------------------\r
+- Source code of filters for x86, IA-64, ARM, ARM-Thumb \r
+  and PowerPC code was included to SDK\r
+- Some internal minor changes\r
+\r
+\r
+4.04           2004-07-28\r
+-------------------------\r
+- More compatibility with some C++ compilers\r
+\r
+\r
+4.03           2004-06-18\r
+-------------------------\r
+- "Benchmark" command was added. It measures compressing \r
+  and decompressing speed and shows rating values. \r
+  Also it checks hardware errors.\r
+\r
+\r
+4.02           2004-06-10\r
+-------------------------\r
+- C++ LZMA Encoder/Decoder code now is more portable\r
+  and it can be compiled by GCC on Linux.\r
+\r
+\r
+4.01           2004-02-15\r
+-------------------------\r
+- Some detection of data corruption was enabled.\r
+    LzmaDecode.c / RangeDecoderReadByte\r
+    .....\r
+    {\r
+      rd->ExtraBytes = 1;\r
+      return 0xFF;\r
+    }\r
+\r
+\r
+4.00           2004-02-13\r
+-------------------------\r
+- Original version of LZMA SDK\r
+\r
+\r
+\r
+HISTORY of the LZMA\r
+-------------------\r
+  2001-2008:  Improvements to LZMA compressing/decompressing code, \r
+              keeping compatibility with original LZMA format\r
+  1996-2001:  Development of LZMA compression format\r
+\r
+  Some milestones:\r
+\r
+  2001-08-30: LZMA compression was added to 7-Zip\r
+  1999-01-02: First version of 7-Zip was released\r
+  \r
+\r
+End of document\r
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/lzma.txt b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/lzma.txt
new file mode 100644 (file)
index 0000000..d4f4af9
--- /dev/null
@@ -0,0 +1,594 @@
+LZMA SDK 4.65\r
+-------------\r
+\r
+LZMA SDK provides the documentation, samples, header files, libraries, \r
+and tools you need to develop applications that use LZMA compression.\r
+\r
+LZMA is default and general compression method of 7z format\r
+in 7-Zip compression program (www.7-zip.org). LZMA provides high \r
+compression ratio and very fast decompression.\r
+\r
+LZMA is an improved version of famous LZ77 compression algorithm. \r
+It was improved in way of maximum increasing of compression ratio,\r
+keeping high decompression speed and low memory requirements for \r
+decompressing.\r
+\r
+\r
+\r
+LICENSE\r
+-------\r
+\r
+LZMA SDK is written and placed in the public domain by Igor Pavlov.\r
+\r
+\r
+LZMA SDK Contents\r
+-----------------\r
+\r
+LZMA SDK includes:\r
+\r
+  - ANSI-C/C++/C#/Java source code for LZMA compressing and decompressing\r
+  - Compiled file->file LZMA compressing/decompressing program for Windows system\r
+\r
+\r
+UNIX/Linux version \r
+------------------\r
+To compile C++ version of file->file LZMA encoding, go to directory\r
+C++/7zip/Compress/LZMA_Alone \r
+and call make to recompile it:\r
+  make -f makefile.gcc clean all\r
+\r
+In some UNIX/Linux versions you must compile LZMA with static libraries.\r
+To compile with static libraries, you can use \r
+LIB = -lm -static\r
+\r
+\r
+Files\r
+---------------------\r
+lzma.txt     - LZMA SDK description (this file)\r
+7zFormat.txt - 7z Format description\r
+7zC.txt      - 7z ANSI-C Decoder description\r
+methods.txt  - Compression method IDs for .7z\r
+lzma.exe     - Compiled file->file LZMA encoder/decoder for Windows\r
+history.txt  - history of the LZMA SDK\r
+\r
+\r
+Source code structure\r
+---------------------\r
+\r
+C/  - C files\r
+        7zCrc*.*   - CRC code\r
+        Alloc.*    - Memory allocation functions\r
+        Bra*.*     - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code\r
+        LzFind.*   - Match finder for LZ (LZMA) encoders \r
+        LzFindMt.* - Match finder for LZ (LZMA) encoders for multithreading encoding\r
+        LzHash.h   - Additional file for LZ match finder\r
+        LzmaDec.*  - LZMA decoding\r
+        LzmaEnc.*  - LZMA encoding\r
+        LzmaLib.*  - LZMA Library for DLL calling\r
+        Types.h    - Basic types for another .c files\r
+       Threads.*  - The code for multithreading.\r
+\r
+    LzmaLib  - LZMA Library (.DLL for Windows)\r
+    \r
+    LzmaUtil - LZMA Utility (file->file LZMA encoder/decoder).\r
+\r
+    Archive - files related to archiving\r
+      7z     - 7z ANSI-C Decoder\r
+\r
+CPP/ -- CPP files\r
+\r
+  Common  - common files for C++ projects\r
+  Windows - common files for Windows related code\r
+\r
+  7zip    - files related to 7-Zip Project\r
+\r
+    Common   - common files for 7-Zip\r
+\r
+    Compress - files related to compression/decompression\r
+\r
+      Copy         - Copy coder\r
+      RangeCoder   - Range Coder (special code of compression/decompression)\r
+      LZMA         - LZMA compression/decompression on C++\r
+      LZMA_Alone   - file->file LZMA compression/decompression\r
+      Branch       - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code\r
+\r
+    Archive - files related to archiving\r
+\r
+      Common   - common files for archive handling\r
+      7z       - 7z C++ Encoder/Decoder\r
+\r
+    Bundles    - Modules that are bundles of other modules\r
+  \r
+      Alone7z           - 7zr.exe: Standalone version of 7z.exe that supports only 7z/LZMA/BCJ/BCJ2\r
+      Format7zR         - 7zr.dll: Reduced version of 7za.dll: extracting/compressing to 7z/LZMA/BCJ/BCJ2\r
+      Format7zExtractR  - 7zxr.dll: Reduced version of 7zxa.dll: extracting from 7z/LZMA/BCJ/BCJ2.\r
+\r
+    UI        - User Interface files\r
+         \r
+      Client7z - Test application for 7za.dll,  7zr.dll, 7zxr.dll\r
+      Common   - Common UI files\r
+      Console  - Code for console archiver\r
+\r
+\r
+\r
+CS/ - C# files\r
+  7zip\r
+    Common   - some common files for 7-Zip\r
+    Compress - files related to compression/decompression\r
+      LZ     - files related to LZ (Lempel-Ziv) compression algorithm\r
+      LZMA         - LZMA compression/decompression\r
+      LzmaAlone    - file->file LZMA compression/decompression\r
+      RangeCoder   - Range Coder (special code of compression/decompression)\r
+\r
+Java/  - Java files\r
+  SevenZip\r
+    Compression    - files related to compression/decompression\r
+      LZ           - files related to LZ (Lempel-Ziv) compression algorithm\r
+      LZMA         - LZMA compression/decompression\r
+      RangeCoder   - Range Coder (special code of compression/decompression)\r
+\r
+\r
+C/C++ source code of LZMA SDK is part of 7-Zip project.\r
+7-Zip source code can be downloaded from 7-Zip's SourceForge page:\r
+\r
+  http://sourceforge.net/projects/sevenzip/\r
+\r
+\r
+\r
+LZMA features\r
+-------------\r
+  - Variable dictionary size (up to 1 GB)\r
+  - Estimated compressing speed: about 2 MB/s on 2 GHz CPU\r
+  - Estimated decompressing speed: \r
+      - 20-30 MB/s on 2 GHz Core 2 or AMD Athlon 64\r
+      - 1-2 MB/s on 200 MHz ARM, MIPS, PowerPC or other simple RISC\r
+  - Small memory requirements for decompressing (16 KB + DictionarySize)\r
+  - Small code size for decompressing: 5-8 KB\r
+\r
+LZMA decoder uses only integer operations and can be \r
+implemented in any modern 32-bit CPU (or on 16-bit CPU with some conditions).\r
+\r
+Some critical operations that affect the speed of LZMA decompression:\r
+  1) 32*16 bit integer multiply\r
+  2) Misspredicted branches (penalty mostly depends from pipeline length)\r
+  3) 32-bit shift and arithmetic operations\r
+\r
+The speed of LZMA decompressing mostly depends from CPU speed.\r
+Memory speed has no big meaning. But if your CPU has small data cache, \r
+overall weight of memory speed will slightly increase.\r
+\r
+\r
+How To Use\r
+----------\r
+\r
+Using LZMA encoder/decoder executable\r
+--------------------------------------\r
+\r
+Usage:  LZMA <e|d> inputFile outputFile [<switches>...]\r
+\r
+  e: encode file\r
+\r
+  d: decode file\r
+\r
+  b: Benchmark. There are two tests: compressing and decompressing \r
+     with LZMA method. Benchmark shows rating in MIPS (million \r
+     instructions per second). Rating value is calculated from \r
+     measured speed and it is normalized with Intel's Core 2 results.\r
+     Also Benchmark checks possible hardware errors (RAM \r
+     errors in most cases). Benchmark uses these settings:\r
+     (-a1, -d21, -fb32, -mfbt4). You can change only -d parameter. \r
+     Also you can change the number of iterations. Example for 30 iterations:\r
+       LZMA b 30\r
+     Default number of iterations is 10.\r
+\r
+<Switches>\r
+  \r
+\r
+  -a{N}:  set compression mode 0 = fast, 1 = normal\r
+          default: 1 (normal)\r
+\r
+  d{N}:   Sets Dictionary size - [0, 30], default: 23 (8MB)\r
+          The maximum value for dictionary size is 1 GB = 2^30 bytes.\r
+          Dictionary size is calculated as DictionarySize = 2^N bytes. \r
+          For decompressing file compressed by LZMA method with dictionary \r
+          size D = 2^N you need about D bytes of memory (RAM).\r
+\r
+  -fb{N}: set number of fast bytes - [5, 273], default: 128\r
+          Usually big number gives a little bit better compression ratio \r
+          and slower compression process.\r
+\r
+  -lc{N}: set number of literal context bits - [0, 8], default: 3\r
+          Sometimes lc=4 gives gain for big files.\r
+\r
+  -lp{N}: set number of literal pos bits - [0, 4], default: 0\r
+          lp switch is intended for periodical data when period is \r
+          equal 2^N. For example, for 32-bit (4 bytes) \r
+          periodical data you can use lp=2. Often it's better to set lc0, \r
+          if you change lp switch.\r
+\r
+  -pb{N}: set number of pos bits - [0, 4], default: 2\r
+          pb switch is intended for periodical data \r
+          when period is equal 2^N.\r
+\r
+  -mf{MF_ID}: set Match Finder. Default: bt4. \r
+              Algorithms from hc* group doesn't provide good compression \r
+              ratio, but they often works pretty fast in combination with \r
+              fast mode (-a0).\r
+\r
+              Memory requirements depend from dictionary size \r
+              (parameter "d" in table below). \r
+\r
+               MF_ID     Memory                   Description\r
+\r
+                bt2    d *  9.5 + 4MB  Binary Tree with 2 bytes hashing.\r
+                bt3    d * 11.5 + 4MB  Binary Tree with 3 bytes hashing.\r
+                bt4    d * 11.5 + 4MB  Binary Tree with 4 bytes hashing.\r
+                hc4    d *  7.5 + 4MB  Hash Chain with 4 bytes hashing.\r
+\r
+  -eos:   write End Of Stream marker. By default LZMA doesn't write \r
+          eos marker, since LZMA decoder knows uncompressed size \r
+          stored in .lzma file header.\r
+\r
+  -si:    Read data from stdin (it will write End Of Stream marker).\r
+  -so:    Write data to stdout\r
+\r
+\r
+Examples:\r
+\r
+1) LZMA e file.bin file.lzma -d16 -lc0 \r
+\r
+compresses file.bin to file.lzma with 64 KB dictionary (2^16=64K)  \r
+and 0 literal context bits. -lc0 allows to reduce memory requirements \r
+for decompression.\r
+\r
+\r
+2) LZMA e file.bin file.lzma -lc0 -lp2\r
+\r
+compresses file.bin to file.lzma with settings suitable \r
+for 32-bit periodical data (for example, ARM or MIPS code).\r
+\r
+3) LZMA d file.lzma file.bin\r
+\r
+decompresses file.lzma to file.bin.\r
+\r
+\r
+Compression ratio hints\r
+-----------------------\r
+\r
+Recommendations\r
+---------------\r
+\r
+To increase the compression ratio for LZMA compressing it's desirable \r
+to have aligned data (if it's possible) and also it's desirable to locate\r
+data in such order, where code is grouped in one place and data is \r
+grouped in other place (it's better than such mixing: code, data, code,\r
+data, ...).\r
+\r
+\r
+Filters\r
+-------\r
+You can increase the compression ratio for some data types, using\r
+special filters before compressing. For example, it's possible to \r
+increase the compression ratio on 5-10% for code for those CPU ISAs: \r
+x86, IA-64, ARM, ARM-Thumb, PowerPC, SPARC.\r
+\r
+You can find C source code of such filters in C/Bra*.* files\r
+\r
+You can check the compression ratio gain of these filters with such \r
+7-Zip commands (example for ARM code):\r
+No filter:\r
+  7z a a1.7z a.bin -m0=lzma\r
+\r
+With filter for little-endian ARM code:\r
+  7z a a2.7z a.bin -m0=arm -m1=lzma        \r
+\r
+It works in such manner:\r
+Compressing    = Filter_encoding + LZMA_encoding\r
+Decompressing  = LZMA_decoding + Filter_decoding\r
+\r
+Compressing and decompressing speed of such filters is very high,\r
+so it will not increase decompressing time too much.\r
+Moreover, it reduces decompression time for LZMA_decoding, \r
+since compression ratio with filtering is higher.\r
+\r
+These filters convert CALL (calling procedure) instructions \r
+from relative offsets to absolute addresses, so such data becomes more \r
+compressible.\r
+\r
+For some ISAs (for example, for MIPS) it's impossible to get gain from such filter.\r
+\r
+\r
+LZMA compressed file format\r
+---------------------------\r
+Offset Size Description\r
+  0     1   Special LZMA properties (lc,lp, pb in encoded form)\r
+  1     4   Dictionary size (little endian)\r
+  5     8   Uncompressed size (little endian). -1 means unknown size\r
+ 13         Compressed data\r
+\r
+\r
+ANSI-C LZMA Decoder\r
+~~~~~~~~~~~~~~~~~~~\r
+\r
+Please note that interfaces for ANSI-C code were changed in LZMA SDK 4.58.\r
+If you want to use old interfaces you can download previous version of LZMA SDK\r
+from sourceforge.net site.\r
+\r
+To use ANSI-C LZMA Decoder you need the following files:\r
+1) LzmaDec.h + LzmaDec.c + Types.h\r
+LzmaUtil/LzmaUtil.c is example application that uses these files.\r
+\r
+\r
+Memory requirements for LZMA decoding\r
+-------------------------------------\r
+\r
+Stack usage of LZMA decoding function for local variables is not \r
+larger than 200-400 bytes.\r
+\r
+LZMA Decoder uses dictionary buffer and internal state structure.\r
+Internal state structure consumes\r
+  state_size = (4 + (1.5 << (lc + lp))) KB\r
+by default (lc=3, lp=0), state_size = 16 KB.\r
+\r
+\r
+How To decompress data\r
+----------------------\r
+\r
+LZMA Decoder (ANSI-C version) now supports 2 interfaces:\r
+1) Single-call Decompressing\r
+2) Multi-call State Decompressing (zlib-like interface)\r
+\r
+You must use external allocator:\r
+Example:\r
+void *SzAlloc(void *p, size_t size) { p = p; return malloc(size); }\r
+void SzFree(void *p, void *address) { p = p; free(address); }\r
+ISzAlloc alloc = { SzAlloc, SzFree };\r
+\r
+You can use p = p; operator to disable compiler warnings.\r
+\r
+\r
+Single-call Decompressing\r
+-------------------------\r
+When to use: RAM->RAM decompressing\r
+Compile files: LzmaDec.h + LzmaDec.c + Types.h\r
+Compile defines: no defines\r
+Memory Requirements:\r
+  - Input buffer: compressed size\r
+  - Output buffer: uncompressed size\r
+  - LZMA Internal Structures: state_size (16 KB for default settings) \r
+\r
+Interface:\r
+  int LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\r
+      const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode, \r
+      ELzmaStatus *status, ISzAlloc *alloc);\r
+  In: \r
+    dest     - output data\r
+    destLen  - output data size\r
+    src      - input data\r
+    srcLen   - input data size\r
+    propData - LZMA properties  (5 bytes)\r
+    propSize - size of propData buffer (5 bytes)\r
+    finishMode - It has meaning only if the decoding reaches output limit (*destLen).\r
+        LZMA_FINISH_ANY - Decode just destLen bytes.\r
+        LZMA_FINISH_END - Stream must be finished after (*destLen).\r
+                           You can use LZMA_FINISH_END, when you know that \r
+                           current output buffer covers last bytes of stream. \r
+    alloc    - Memory allocator.\r
+\r
+  Out: \r
+    destLen  - processed output size \r
+    srcLen   - processed input size \r
+\r
+  Output:\r
+    SZ_OK\r
+      status:\r
+        LZMA_STATUS_FINISHED_WITH_MARK\r
+        LZMA_STATUS_NOT_FINISHED \r
+        LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK\r
+    SZ_ERROR_DATA - Data error\r
+    SZ_ERROR_MEM  - Memory allocation error\r
+    SZ_ERROR_UNSUPPORTED - Unsupported properties\r
+    SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).\r
+\r
+  If LZMA decoder sees end_marker before reaching output limit, it returns OK result,\r
+  and output value of destLen will be less than output buffer size limit.\r
+\r
+  You can use multiple checks to test data integrity after full decompression:\r
+    1) Check Result and "status" variable.\r
+    2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.\r
+    3) Check that output(srcLen) = compressedSize, if you know real compressedSize. \r
+       You must use correct finish mode in that case. */ \r
+\r
+\r
+Multi-call State Decompressing (zlib-like interface)\r
+----------------------------------------------------\r
+\r
+When to use: file->file decompressing \r
+Compile files: LzmaDec.h + LzmaDec.c + Types.h\r
+\r
+Memory Requirements:\r
+ - Buffer for input stream: any size (for example, 16 KB)\r
+ - Buffer for output stream: any size (for example, 16 KB)\r
+ - LZMA Internal Structures: state_size (16 KB for default settings) \r
+ - LZMA dictionary (dictionary size is encoded in LZMA properties header)\r
+\r
+1) read LZMA properties (5 bytes) and uncompressed size (8 bytes, little-endian) to header:\r
+   unsigned char header[LZMA_PROPS_SIZE + 8];\r
+   ReadFile(inFile, header, sizeof(header)\r
+\r
+2) Allocate CLzmaDec structures (state + dictionary) using LZMA properties\r
+\r
+  CLzmaDec state;\r
+  LzmaDec_Constr(&state);\r
+  res = LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc);\r
+  if (res != SZ_OK)\r
+    return res;\r
+\r
+3) Init LzmaDec structure before any new LZMA stream. And call LzmaDec_DecodeToBuf in loop\r
+\r
+  LzmaDec_Init(&state);\r
+  for (;;)\r
+  {\r
+    ... \r
+    int res = LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, \r
+       const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode);\r
+    ...\r
+  }\r
+\r
+\r
+4) Free all allocated structures\r
+  LzmaDec_Free(&state, &g_Alloc);\r
+\r
+For full code example, look at C/LzmaUtil/LzmaUtil.c code.\r
+\r
+\r
+How To compress data\r
+--------------------\r
+\r
+Compile files: LzmaEnc.h + LzmaEnc.c + Types.h +\r
+LzFind.c + LzFind.h + LzFindMt.c + LzFindMt.h + LzHash.h\r
+\r
+Memory Requirements:\r
+  - (dictSize * 11.5 + 6 MB) + state_size\r
+\r
+Lzma Encoder can use two memory allocators:\r
+1) alloc - for small arrays.\r
+2) allocBig - for big arrays.\r
+\r
+For example, you can use Large RAM Pages (2 MB) in allocBig allocator for \r
+better compression speed. Note that Windows has bad implementation for \r
+Large RAM Pages. \r
+It's OK to use same allocator for alloc and allocBig.\r
+\r
+\r
+Single-call Compression with callbacks\r
+--------------------------------------\r
+\r
+Check C/LzmaUtil/LzmaUtil.c as example, \r
+\r
+When to use: file->file decompressing \r
+\r
+1) you must implement callback structures for interfaces:\r
+ISeqInStream\r
+ISeqOutStream\r
+ICompressProgress\r
+ISzAlloc\r
+\r
+static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\r
+static void SzFree(void *p, void *address) {  p = p; MyFree(address); }\r
+static ISzAlloc g_Alloc = { SzAlloc, SzFree };\r
+\r
+  CFileSeqInStream inStream;\r
+  CFileSeqOutStream outStream;\r
+\r
+  inStream.funcTable.Read = MyRead;\r
+  inStream.file = inFile;\r
+  outStream.funcTable.Write = MyWrite;\r
+  outStream.file = outFile;\r
+\r
+\r
+2) Create CLzmaEncHandle object;\r
+\r
+  CLzmaEncHandle enc;\r
+\r
+  enc = LzmaEnc_Create(&g_Alloc);\r
+  if (enc == 0)\r
+    return SZ_ERROR_MEM;\r
+\r
+\r
+3) initialize CLzmaEncProps properties;\r
+\r
+  LzmaEncProps_Init(&props);\r
+\r
+  Then you can change some properties in that structure.\r
+\r
+4) Send LZMA properties to LZMA Encoder\r
+\r
+  res = LzmaEnc_SetProps(enc, &props);\r
+\r
+5) Write encoded properties to header\r
+\r
+    Byte header[LZMA_PROPS_SIZE + 8];\r
+    size_t headerSize = LZMA_PROPS_SIZE;\r
+    UInt64 fileSize;\r
+    int i;\r
+\r
+    res = LzmaEnc_WriteProperties(enc, header, &headerSize);\r
+    fileSize = MyGetFileLength(inFile);\r
+    for (i = 0; i < 8; i++)\r
+      header[headerSize++] = (Byte)(fileSize >> (8 * i));\r
+    MyWriteFileAndCheck(outFile, header, headerSize)\r
+\r
+6) Call encoding function:\r
+      res = LzmaEnc_Encode(enc, &outStream.funcTable, &inStream.funcTable, \r
+        NULL, &g_Alloc, &g_Alloc);\r
+\r
+7) Destroy LZMA Encoder Object\r
+  LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc);\r
+\r
+\r
+If callback function return some error code, LzmaEnc_Encode also returns that code.\r
+\r
+\r
+Single-call RAM->RAM Compression\r
+--------------------------------\r
+\r
+Single-call RAM->RAM Compression is similar to Compression with callbacks,\r
+but you provide pointers to buffers instead of pointers to stream callbacks:\r
+\r
+HRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r
+    CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark, \r
+    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\r
+\r
+Return code:\r
+  SZ_OK               - OK\r
+  SZ_ERROR_MEM        - Memory allocation error \r
+  SZ_ERROR_PARAM      - Incorrect paramater\r
+  SZ_ERROR_OUTPUT_EOF - output buffer overflow\r
+  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)\r
+\r
+\r
+\r
+LZMA Defines\r
+------------\r
+\r
+_LZMA_SIZE_OPT - Enable some optimizations in LZMA Decoder to get smaller executable code.\r
+\r
+_LZMA_PROB32   - It can increase the speed on some 32-bit CPUs, but memory usage for \r
+                 some structures will be doubled in that case.\r
+\r
+_LZMA_UINT32_IS_ULONG  - Define it if int is 16-bit on your compiler and long is 32-bit.\r
+\r
+_LZMA_NO_SYSTEM_SIZE_T  - Define it if you don't want to use size_t type.\r
+\r
+\r
+C++ LZMA Encoder/Decoder \r
+~~~~~~~~~~~~~~~~~~~~~~~~\r
+C++ LZMA code use COM-like interfaces. So if you want to use it, \r
+you can study basics of COM/OLE.\r
+C++ LZMA code is just wrapper over ANSI-C code.\r
+\r
+\r
+C++ Notes\r
+~~~~~~~~~~~~~~~~~~~~~~~~\r
+If you use some C++ code folders in 7-Zip (for example, C++ code for .7z handling),\r
+you must check that you correctly work with "new" operator.\r
+7-Zip can be compiled with MSVC 6.0 that doesn't throw "exception" from "new" operator.\r
+So 7-Zip uses "CPP\Common\NewHandler.cpp" that redefines "new" operator:\r
+operator new(size_t size)\r
+{\r
+  void *p = ::malloc(size);\r
+  if (p == 0)\r
+    throw CNewException();\r
+  return p;\r
+}\r
+If you use MSCV that throws exception for "new" operator, you can compile without \r
+"NewHandler.cpp". So standard exception will be used. Actually some code of \r
+7-Zip catches any exception in internal code and converts it to HRESULT code.\r
+So you don't need to catch CNewException, if you call COM interfaces of 7-Zip.\r
+\r
+---\r
+\r
+http://www.7-zip.org\r
+http://www.7-zip.org/sdk.html\r
+http://www.7-zip.org/support.html\r
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/UefiLzma.h b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/UefiLzma.h
new file mode 100644 (file)
index 0000000..f6db7f1
--- /dev/null
@@ -0,0 +1,41 @@
+/** @file\r
+  LZMA UEFI Library header file\r
+\r
+  Allows LZMA code to build under UEFI (edk2) build environment\r
+\r
+  Copyright (c) 2009, Intel Corporation<BR>\r
+  All rights reserved. This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __UEFILZMA_H__\r
+#define __UEFILZMA_H__\r
+\r
+#include <Uefi.h>\r
+#include <Library/BaseMemoryLib.h>\r
+\r
+#ifdef _WIN32\r
+#undef _WIN32\r
+#endif\r
+\r
+#if !defined(_WIN64) || defined(__GNUC__)\r
+typedef unsigned int size_t;\r
+#endif\r
+\r
+#ifdef _WIN64\r
+#undef _WIN64\r
+#endif\r
+\r
+typedef int ptrdiff_t;\r
+\r
+#define memcpy CopyMem\r
+#define memmove CopyMem\r
+\r
+#endif // __UEFILZMA_H__\r
+\r