]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add LzmaArchCustomDecompressLib library instance, which supports for X86 (IA32/X64...
authorlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 19 Mar 2012 07:13:29 +0000 (07:13 +0000)
committerlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 19 Mar 2012 07:13:29 +0000 (07:13 +0000)
Signed-off-by: lgao4
Reviewed-by: jljusten
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13111 6f19259b-4bc3-4df7-8a09-765794883524

IntelFrameworkModulePkg/Include/Guid/LzmaDecompress.h
IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec
IntelFrameworkModulePkg/IntelFrameworkModulePkg.dsc
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/F86GuidedSectionExtraction.c [new file with mode: 0644]
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaArchCustomDecompressLib.inf [new file with mode: 0644]
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Bra.h [new file with mode: 0644]
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Bra86.c [new file with mode: 0644]

index 6d5af933978ea6310d60e3c492594caee721873a..18a6552f9c9184a2a97c2fea44d30c5571130ebe 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Lzma Custom decompress algorithm Guid definition.\r
 \r
-Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials are licensed and made available under \r
 the terms and conditions of the BSD License that accompanies this distribution.  \r
 The full text of the license may be found at\r
@@ -22,6 +22,14 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #define LZMA_CUSTOM_DECOMPRESS_GUID  \\r
   { 0xEE4E5898, 0x3914, 0x4259, { 0x9D, 0x6E, 0xDC, 0x7B, 0xD7, 0x94, 0x03, 0xCF } }\r
 \r
+///\r
+/// The Global ID used to identify a section of an FFS file of type \r
+/// EFI_SECTION_GUID_DEFINED, whose contents have been compressed using LZMA with X86 code Converter.\r
+///\r
+#define LZMAF86_CUSTOM_DECOMPRESS_GUID  \\r
+  { 0xD42AE6BD, 0x1352, 0x4bfb, { 0x90, 0x9A, 0xCA, 0x72, 0xA6, 0xEA, 0xE8, 0x89 } }\r
+\r
 extern GUID gLzmaCustomDecompressGuid;\r
+extern GUID gLzmaF86CustomDecompressGuid;\r
 \r
 #endif\r
index 0c46885287b50a8c685ed914ef2a7489e4745ac9..cb398779371d9dc22a07b5d23faff217825a9456 100644 (file)
@@ -2,7 +2,7 @@
 # Intel Framework Module Package contains the definitions and module implementation\r
 # which follows Intel EFI Framework Specification.\r
 #\r
-# Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>\r
 #\r
 # This program and the accompanying materials\r
 # are licensed and made available under the terms and conditions of the BSD License\r
@@ -46,6 +46,7 @@
   ## GUID indicates the LZMA custom compress/decompress algorithm.\r
   #  Include/Guid/LzmaDecompress.h\r
   gLzmaCustomDecompressGuid      = { 0xEE4E5898, 0x3914, 0x4259, { 0x9D, 0x6E, 0xDC, 0x7B, 0xD7, 0x94, 0x03, 0xCF }}\r
+  gLzmaF86CustomDecompressGuid     = { 0xD42AE6BD, 0x1352, 0x4bfb, { 0x90, 0x9A, 0xCA, 0x72, 0xA6, 0xEA, 0xE8, 0x89 }}\r
 \r
   ## Include/Guid/AcpiVariable.h\r
   gEfiAcpiVariableCompatiblityGuid   = { 0xc020489e, 0x6db2, 0x4ef2, { 0x9a, 0xa5, 0xca, 0x6,  0xfc, 0x11, 0xd3, 0x6a }}\r
index 70a8a39ef528d1424fad26288d1413ea2706879d..b00406715576cbfec8fef8a63acc63036020d840 100644 (file)
@@ -3,7 +3,7 @@
 #\r
 # This file is used to build all modules in IntelFrameworkModulePkg.\r
 #\r
-#Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>\r
+#Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>\r
 #This program and the accompanying materials are licensed and made available under \r
 #the terms and conditions of the BSD License that accompanies this distribution.  \r
 #The full text of the license may be found at\r
 \r
 [Components.IA32,Components.X64]\r
   IntelFrameworkModulePkg/Universal/Acpi/AcpiS3SaveDxe/AcpiS3SaveDxe.inf\r
+  IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaArchCustomDecompressLib.inf\r
 \r
 [Components.IA32,Components.X64,Components.IPF]\r
   IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBiosDxe.inf\r
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/F86GuidedSectionExtraction.c b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/F86GuidedSectionExtraction.c
new file mode 100644 (file)
index 0000000..4f870a1
--- /dev/null
@@ -0,0 +1,218 @@
+/** @file\r
+  LZMA Decompress GUIDed Section Extraction Library, which produces LZMA custom \r
+  decompression algorithm with the converter for the different arch code.\r
+  It wraps Lzma decompress interfaces to GUIDed Section Extraction interfaces\r
+  and registers them into GUIDed handler table.\r
+\r
+  Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>\r
+  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 "LzmaDecompressLibInternal.h"\r
+#include "Sdk/C/Bra.h"\r
+\r
+/**\r
+  Examines a GUIDed section and returns the size of the decoded buffer and the\r
+  size of an scratch buffer required to actually decode the data in a GUIDed section.\r
+\r
+  Examines a GUIDed section specified by InputSection.  \r
+  If GUID for InputSection does not match the GUID that this handler supports,\r
+  then RETURN_UNSUPPORTED is returned.  \r
+  If the required information can not be retrieved from InputSection,\r
+  then RETURN_INVALID_PARAMETER is returned.\r
+  If the GUID of InputSection does match the GUID that this handler supports,\r
+  then the size required to hold the decoded buffer is returned in OututBufferSize,\r
+  the size of an optional scratch buffer is returned in ScratchSize, and the Attributes field\r
+  from EFI_GUID_DEFINED_SECTION header of InputSection is returned in SectionAttribute.\r
+  \r
+  If InputSection is NULL, then ASSERT().\r
+  If OutputBufferSize is NULL, then ASSERT().\r
+  If ScratchBufferSize is NULL, then ASSERT().\r
+  If SectionAttribute is NULL, then ASSERT().\r
+\r
+\r
+  @param[in]  InputSection       A pointer to a GUIDed section of an FFS formatted file.\r
+  @param[out] OutputBufferSize   A pointer to the size, in bytes, of an output buffer required\r
+                                 if the buffer specified by InputSection were decoded.\r
+  @param[out] ScratchBufferSize  A pointer to the size, in bytes, required as scratch space\r
+                                 if the buffer specified by InputSection were decoded.\r
+  @param[out] SectionAttribute   A pointer to the attributes of the GUIDed section. See the Attributes\r
+                                 field of EFI_GUID_DEFINED_SECTION in the PI Specification.\r
+\r
+  @retval  RETURN_SUCCESS            The information about InputSection was returned.\r
+  @retval  RETURN_UNSUPPORTED        The section specified by InputSection does not match the GUID this handler supports.\r
+  @retval  RETURN_INVALID_PARAMETER  The information can not be retrieved from the section specified by InputSection.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+LzmaArchGuidedSectionGetInfo (\r
+  IN  CONST VOID  *InputSection,\r
+  OUT UINT32      *OutputBufferSize,\r
+  OUT UINT32      *ScratchBufferSize,\r
+  OUT UINT16      *SectionAttribute\r
+  )\r
+{\r
+  ASSERT (InputSection != NULL);\r
+  ASSERT (OutputBufferSize != NULL);\r
+  ASSERT (ScratchBufferSize != NULL);\r
+  ASSERT (SectionAttribute != NULL);\r
+\r
+  if (IS_SECTION2 (InputSection)) {\r
+    if (!CompareGuid (\r
+        &gLzmaF86CustomDecompressGuid,\r
+        &(((EFI_GUID_DEFINED_SECTION2 *) InputSection)->SectionDefinitionGuid))) {\r
+      return RETURN_INVALID_PARAMETER;\r
+    }\r
+\r
+    *SectionAttribute = ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->Attributes;\r
+\r
+    return LzmaUefiDecompressGetInfo (\r
+             (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,\r
+             SECTION2_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,\r
+             OutputBufferSize,\r
+             ScratchBufferSize\r
+             );\r
+  } else {\r
+    if (!CompareGuid (\r
+        &gLzmaF86CustomDecompressGuid,\r
+        &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
+      return RETURN_INVALID_PARAMETER;\r
+    }\r
+\r
+    *SectionAttribute = ((EFI_GUID_DEFINED_SECTION *) InputSection)->Attributes;\r
+\r
+    return LzmaUefiDecompressGetInfo (\r
+             (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
+             SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
+             OutputBufferSize,\r
+             ScratchBufferSize\r
+             );\r
+  }\r
+}\r
+\r
+/**\r
+  Decompress a LZAM compressed GUIDed section into a caller allocated output buffer.\r
+  \r
+  Decodes the GUIDed section specified by InputSection.  \r
+  If GUID for InputSection does not match the GUID that this handler supports, then RETURN_UNSUPPORTED is returned.  \r
+  If the data in InputSection can not be decoded, then RETURN_INVALID_PARAMETER is returned.\r
+  If the GUID of InputSection does match the GUID that this handler supports, then InputSection\r
+  is decoded into the buffer specified by OutputBuffer and the authentication status of this\r
+  decode operation is returned in AuthenticationStatus.  If the decoded buffer is identical to the\r
+  data in InputSection, then OutputBuffer is set to point at the data in InputSection.  Otherwise,\r
+  the decoded data will be placed in caller allocated buffer specified by OutputBuffer.\r
+  \r
+  If InputSection is NULL, then ASSERT().\r
+  If OutputBuffer is NULL, then ASSERT().\r
+  If ScratchBuffer is NULL and this decode operation requires a scratch buffer, then ASSERT().\r
+  If AuthenticationStatus is NULL, then ASSERT().\r
+\r
+\r
+  @param[in]  InputSection  A pointer to a GUIDed section of an FFS formatted file.\r
+  @param[out] OutputBuffer  A pointer to a buffer that contains the result of a decode operation. \r
+  @param[out] ScratchBuffer A caller allocated buffer that may be required by this function\r
+                            as a scratch buffer to perform the decode operation. \r
+  @param[out] AuthenticationStatus \r
+                            A pointer to the authentication status of the decoded output buffer.\r
+                            See the definition of authentication status in the EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI\r
+                            section of the PI Specification. EFI_AUTH_STATUS_PLATFORM_OVERRIDE must\r
+                            never be set by this handler.\r
+\r
+  @retval  RETURN_SUCCESS            The buffer specified by InputSection was decoded.\r
+  @retval  RETURN_UNSUPPORTED        The section specified by InputSection does not match the GUID this handler supports.\r
+  @retval  RETURN_INVALID_PARAMETER  The section specified by InputSection can not be decoded.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+LzmaArchGuidedSectionExtraction (\r
+  IN CONST  VOID    *InputSection,\r
+  OUT       VOID    **OutputBuffer,\r
+  OUT       VOID    *ScratchBuffer,        OPTIONAL\r
+  OUT       UINT32  *AuthenticationStatus\r
+  )\r
+{\r
+  EFI_GUID          *InputGuid;\r
+  VOID              *Source;\r
+  UINTN             SourceSize;\r
+  EFI_STATUS        Status;\r
+  UINT32            X86State;\r
+  UINT32            OutputBufferSize;\r
+  UINT32            ScratchBufferSize;\r
+  \r
+  ASSERT (OutputBuffer != NULL);\r
+  ASSERT (InputSection != NULL);\r
+\r
+  if (IS_SECTION2 (InputSection)) {\r
+    InputGuid  = &(((EFI_GUID_DEFINED_SECTION2 *) InputSection)->SectionDefinitionGuid);\r
+    Source     = (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset;\r
+    SourceSize = SECTION2_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset;\r
+  } else {\r
+    InputGuid  = &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid);\r
+    Source     = (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset;\r
+    SourceSize = SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset;\r
+  }\r
+\r
+  if (!CompareGuid (&gLzmaF86CustomDecompressGuid, InputGuid)) {\r
+    return RETURN_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Authentication is set to Zero, which may be ignored.\r
+  //\r
+  *AuthenticationStatus = 0;\r
+\r
+  Status = LzmaUefiDecompress (\r
+           Source,\r
+           SourceSize,\r
+           *OutputBuffer,\r
+           ScratchBuffer\r
+           );\r
+\r
+  //\r
+  // After decompress, the data need to be converted to the raw data. \r
+  //\r
+  if (!EFI_ERROR (Status)) {\r
+    Status = LzmaUefiDecompressGetInfo (\r
+             Source,\r
+             SourceSize,\r
+             &OutputBufferSize,\r
+             &ScratchBufferSize\r
+             );\r
+    \r
+    if (!EFI_ERROR (Status)) {\r
+      x86_Convert_Init(X86State);\r
+      x86_Convert(*OutputBuffer, OutputBufferSize, 0, &X86State, 0);\r
+    }\r
+  }\r
+  \r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Register LzmaArchDecompress and LzmaArchDecompressGetInfo handlers with LzmaF86CustomDecompressGuid.\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
+LzmaArchDecompressLibConstructor (\r
+  )\r
+{\r
+  return ExtractGuidedSectionRegisterHandlers (\r
+          &gLzmaF86CustomDecompressGuid,\r
+          LzmaArchGuidedSectionGetInfo,\r
+          LzmaArchGuidedSectionExtraction\r
+          );\r
+}\r
+\r
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaArchCustomDecompressLib.inf b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaArchCustomDecompressLib.inf
new file mode 100644 (file)
index 0000000..9dda211
--- /dev/null
@@ -0,0 +1,66 @@
+## @file\r
+#  LzmaArchCustomDecompressLib produces LZMA custom decompression algorithm \r
+#  with the converter for the different arch code.\r
+#\r
+#  It is based on the LZMA SDK 4.65.\r
+#  LZMA SDK 4.65 was placed in the public domain on 2009-02-03.  \r
+#  It was released on the http://www.7-zip.org/sdk.html website.\r
+#\r
+#  Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>\r
+#\r
+#  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                      = LzmaArchDecompressLib\r
+  FILE_GUID                      = A853C1D2-E003-4cc4-9DD1-8824AD79FE48\r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = NULL\r
+  CONSTRUCTOR                    = LzmaArchDecompressLibConstructor\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64\r
+#\r
+\r
+[Sources]\r
+  LzmaDecompress.c\r
+  Sdk/C/Bra.h\r
+  Sdk/C/LzFind.c\r
+  Sdk/C/LzmaDec.c\r
+  Sdk/C/7zVersion.h\r
+  Sdk/C/CpuArch.h\r
+  Sdk/C/LzFind.h\r
+  Sdk/C/LzHash.h\r
+  Sdk/C/LzmaDec.h\r
+  Sdk/C/Types.h  \r
+  UefiLzma.h\r
+  LzmaDecompressLibInternal.h\r
+\r
+[Sources.Ia32, Sources.X64]\r
+  Sdk/C/Bra86.c\r
+  F86GuidedSectionExtraction.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec\r
+\r
+[Guids.Ia32, Guids.X64]\r
+  gLzmaF86CustomDecompressGuid ## PRODUCED  ## GUID specifies LZMA custom decompress algorithm with converter for x86 code.\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  DebugLib\r
+  BaseMemoryLib\r
+  ExtractGuidedSectionLib\r
+\r
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Bra.h b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Bra.h
new file mode 100644 (file)
index 0000000..b9018eb
--- /dev/null
@@ -0,0 +1,60 @@
+/* Bra.h -- Branch converters for executables\r
+2008-10-04 : Igor Pavlov : Public domain */\r
+\r
+#ifndef __BRA_H\r
+#define __BRA_H\r
+\r
+#include "Types.h"\r
+\r
+/*\r
+These functions convert relative addresses to absolute addresses\r
+in CALL instructions to increase the compression ratio.\r
+  \r
+  In:\r
+    data     - data buffer\r
+    size     - size of data\r
+    ip       - current virtual Instruction Pinter (IP) value\r
+    state    - state variable for x86 converter\r
+    encoding - 0 (for decoding), 1 (for encoding)\r
+  \r
+  Out:\r
+    state    - state variable for x86 converter\r
+\r
+  Returns:\r
+    The number of processed bytes. If you call these functions with multiple calls,\r
+    you must start next call with first byte after block of processed bytes.\r
+  \r
+  Type   Endian  Alignment  LookAhead\r
+  \r
+  x86    little      1          4\r
+  ARMT   little      2          2\r
+  ARM    little      4          0\r
+  PPC     big        4          0\r
+  SPARC   big        4          0\r
+  IA64   little     16          0\r
+\r
+  size must be >= Alignment + LookAhead, if it's not last block.\r
+  If (size < Alignment + LookAhead), converter returns 0.\r
+\r
+  Example:\r
+\r
+    UInt32 ip = 0;\r
+    for ()\r
+    {\r
+      ; size must be >= Alignment + LookAhead, if it's not last block\r
+      SizeT processed = Convert(data, size, ip, 1);\r
+      data += processed;\r
+      size -= processed;\r
+      ip += processed;\r
+    }\r
+*/\r
+\r
+#define x86_Convert_Init(state) { state = 0; }\r
+SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding);\r
+SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r
+SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r
+SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r
+SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r
+SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r
+\r
+#endif\r
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Bra86.c b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Bra86.c
new file mode 100644 (file)
index 0000000..93566cb
--- /dev/null
@@ -0,0 +1,85 @@
+/* Bra86.c -- Converter for x86 code (BCJ)\r
+2008-10-04 : Igor Pavlov : Public domain */\r
+\r
+#include "Bra.h"\r
+\r
+#define Test86MSByte(b) ((b) == 0 || (b) == 0xFF)\r
+\r
+const Byte kMaskToAllowedStatus[8] = {1, 1, 1, 0, 1, 0, 0, 0};\r
+const Byte kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3};\r
+\r
+SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding)\r
+{\r
+  SizeT bufferPos = 0, prevPosT;\r
+  UInt32 prevMask = *state & 0x7;\r
+  if (size < 5)\r
+    return 0;\r
+  ip += 5;\r
+  prevPosT = (SizeT)0 - 1;\r
+\r
+  for (;;)\r
+  {\r
+    Byte *p = data + bufferPos;\r
+    Byte *limit = data + size - 4;\r
+    for (; p < limit; p++)\r
+      if ((*p & 0xFE) == 0xE8)\r
+        break;\r
+    bufferPos = (SizeT)(p - data);\r
+    if (p >= limit)\r
+      break;\r
+    prevPosT = bufferPos - prevPosT;\r
+    if (prevPosT > 3)\r
+      prevMask = 0;\r
+    else\r
+    {\r
+      prevMask = (prevMask << ((int)prevPosT - 1)) & 0x7;\r
+      if (prevMask != 0)\r
+      {\r
+        Byte b = p[4 - kMaskToBitNumber[prevMask]];\r
+        if (!kMaskToAllowedStatus[prevMask] || Test86MSByte(b))\r
+        {\r
+          prevPosT = bufferPos;\r
+          prevMask = ((prevMask << 1) & 0x7) | 1;\r
+          bufferPos++;\r
+          continue;\r
+        }\r
+      }\r
+    }\r
+    prevPosT = bufferPos;\r
+\r
+    if (Test86MSByte(p[4]))\r
+    {\r
+      UInt32 src = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]);\r
+      UInt32 dest;\r
+      for (;;)\r
+      {\r
+        Byte b;\r
+        int index;\r
+        if (encoding)\r
+          dest = (ip + (UInt32)bufferPos) + src;\r
+        else\r
+          dest = src - (ip + (UInt32)bufferPos);\r
+        if (prevMask == 0)\r
+          break;\r
+        index = kMaskToBitNumber[prevMask] * 8;\r
+        b = (Byte)(dest >> (24 - index));\r
+        if (!Test86MSByte(b))\r
+          break;\r
+        src = dest ^ ((1 << (32 - index)) - 1);\r
+      }\r
+      p[4] = (Byte)(~(((dest >> 24) & 1) - 1));\r
+      p[3] = (Byte)(dest >> 16);\r
+      p[2] = (Byte)(dest >> 8);\r
+      p[1] = (Byte)dest;\r
+      bufferPos += 5;\r
+    }\r
+    else\r
+    {\r
+      prevMask = ((prevMask << 1) & 0x7) | 1;\r
+      bufferPos++;\r
+    }\r
+  }\r
+  prevPosT = bufferPos - prevPosT;\r
+  *state = ((prevPosT > 3) ? 0 : ((prevMask << ((int)prevPosT - 1)) & 0x7));\r
+  return bufferPos;\r
+}\r