// Decompress the stream\r
//\r
if (CompressionHeader->CompressionType == EFI_STANDARD_COMPRESSION) {\r
- Status = CoreLocateProtocol (&gEfiTianoDecompressProtocolGuid, NULL, (VOID **)&Decompress);\r
+ Status = CoreLocateProtocol (&gEfiDecompressProtocolGuid, NULL, (VOID **)&Decompress);\r
} else {\r
Status = CoreLocateProtocol (&gEfiCustomizedDecompressProtocolGuid, NULL, (VOID **)&Decompress);\r
}\r
EFI_COMPRESSION_SECTION *CompressionSection;\r
UINT32 FvAlignment;\r
\r
+ //\r
+ // Initialize local variables.\r
+ //\r
+ DecompressLibrary = NULL;\r
+ DstBuffer = NULL;\r
+ DstBufferSize = 0;\r
+\r
Status = PeiServicesFfsFindSectionData (\r
EFI_SECTION_COMPRESSION,\r
FfsFileHeader,\r
\r
switch (CompressionSection->CompressionType) {\r
case EFI_STANDARD_COMPRESSION:\r
+ //\r
+ // Load EFI standard compression.\r
+ //\r
if (FeaturePcdGet (PcdDxeIplSupportTianoDecompress)) {\r
- DecompressLibrary = &gTianoDecompress;\r
+ DecompressLibrary = &gEfiDecompress;\r
} else {\r
ASSERT (FALSE);\r
return EFI_NOT_FOUND;\r
\r
case EFI_CUSTOMIZED_COMPRESSION:\r
//\r
- // Load user customized compression protocol.\r
+ // Load user customized compression.\r
//\r
if (FeaturePcdGet (PcdDxeIplSupportCustomDecompress)) {\r
DecompressLibrary = &gCustomDecompress;\r
break;\r
\r
case EFI_NOT_COMPRESSED:\r
+ //\r
+ // Allocate destination buffer\r
+ //\r
+ DstBufferSize = CompressionSection->UncompressedLength;\r
+ DstBuffer = AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize));\r
+ if (DstBuffer == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+ //\r
+ // stream is not actually compressed, just encapsulated. So just copy it.\r
+ //\r
+ CopyMem (DstBuffer, CompressionSection + 1, DstBufferSize);\r
+ break;\r
+\r
default:\r
//\r
- // Need to support not compressed file\r
+ // Don't support other unknown compression type.\r
//\r
ASSERT_EFI_ERROR (Status);\r
return EFI_NOT_FOUND;\r
}\r
-\r
- Status = DecompressLibrary->GetInfo (\r
- (UINT8 *) ((EFI_COMPRESSION_SECTION *) Section + 1),\r
- (UINT32) SectionLength - sizeof (EFI_COMPRESSION_SECTION),\r
- &DstBufferSize,\r
- &ScratchBufferSize\r
- );\r
- if (EFI_ERROR (Status)) {\r
+ \r
+ if (CompressionSection->CompressionType != EFI_NOT_COMPRESSED) {\r
//\r
- // GetInfo failed\r
+ // For compressed data, decompress them to dstbuffer.\r
//\r
- return EFI_NOT_FOUND;\r
- }\r
-\r
- //\r
- // Allocate scratch buffer\r
- //\r
- ScratchBuffer = AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize));\r
- if (ScratchBuffer == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
-\r
- //\r
- // Allocate destination buffer\r
- //\r
- DstBuffer = AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize));\r
- if (DstBuffer == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
+ Status = DecompressLibrary->GetInfo (\r
+ (UINT8 *) ((EFI_COMPRESSION_SECTION *) Section + 1),\r
+ (UINT32) SectionLength - sizeof (EFI_COMPRESSION_SECTION),\r
+ &DstBufferSize,\r
+ &ScratchBufferSize\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ //\r
+ // GetInfo failed\r
+ //\r
+ return EFI_NOT_FOUND;\r
+ }\r
+ \r
+ //\r
+ // Allocate scratch buffer\r
+ //\r
+ ScratchBuffer = AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize));\r
+ if (ScratchBuffer == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+ \r
+ //\r
+ // Allocate destination buffer\r
+ //\r
+ DstBuffer = AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize));\r
+ if (DstBuffer == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+ \r
+ //\r
+ // Call decompress function\r
+ //\r
+ Status = DecompressLibrary->Decompress (\r
+ (CHAR8 *) ((EFI_COMPRESSION_SECTION *) Section + 1),\r
+ DstBuffer,\r
+ ScratchBuffer\r
+ );\r
}\r
-\r
- //\r
- // Call decompress function\r
- //\r
- Status = DecompressLibrary->Decompress (\r
- (CHAR8 *) ((EFI_COMPRESSION_SECTION *) Section + 1),\r
- DstBuffer,\r
- ScratchBuffer\r
- );\r
-\r
+ \r
CmpSection = (EFI_COMMON_SECTION_HEADER *) DstBuffer;\r
if (CmpSection->Type == EFI_SECTION_FIRMWARE_VOLUME_IMAGE) {\r
// \r
} else {\r
return EFI_NOT_FOUND;\r
}\r
-\r
}\r
}\r
//\r
<IncludeHeader>Include/Library/EdkPeCoffLoaderLib.h</IncludeHeader>\r
<HelpText/>\r
</LibraryClass>\r
- <LibraryClass Name="EdkPeCoffLoaderX64Lib">\r
- <IncludeHeader>Include/Library/EdkPeCoffLoaderX64Lib.h</IncludeHeader>\r
- <HelpText/>\r
- </LibraryClass>\r
<LibraryClass Name="EdkScsiLib">\r
<IncludeHeader>Include/Library/EdkScsiLib.h</IncludeHeader>\r
<HelpText/>\r
<IncludeHeader>Include/Library/EdkPeCoffLoaderLib.h</IncludeHeader>\r
<HelpText/>\r
</IndustryStdHeader>\r
- <IndustryStdHeader Name="EdkPeCoffLoaderX64Lib">\r
- <IncludeHeader>Include/Library/EdkPeCoffLoaderX64Lib.h</IncludeHeader>\r
- <HelpText/>\r
- </IndustryStdHeader>\r
<IndustryStdHeader Name="EdkScsiLib">\r
<IncludeHeader>Include/Library/EdkScsiLib.h</IncludeHeader>\r
<HelpText/>\r
<Filename>Library/EdkIfrSupportLib/EdkIfrSupportLib.msa</Filename>\r
<Filename>Library/EdkNullCustomizedDecompressLib/EdkNullCustomizedDecompressLib.msa</Filename>\r
<Filename>Library/EdkPeCoffLoaderLib/EdkPeCoffLoaderLib.msa</Filename>\r
- <Filename>Library/EdkPeCoffLoaderX64Lib/EdkPeCoffLoaderX64Lib.msa</Filename>\r
<Filename>Library/PeiPerformanceLib/PeiPerformanceLib.msa</Filename>\r
<Filename>Library/EdkScsiLib/EdkScsiLib.msa</Filename>\r
<Filename>Library/EdkUefiDebugLibConOut/EdkUefiDebugLibConOut.msa</Filename>\r
+++ /dev/null
-/*++\r
-\r
-Copyright (c) 2006, 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
- EdkPeCoffLoaderX64Lib.h\r
-\r
-Abstract:\r
- Wrap the Base PE/COFF loader with the PE COFF Protocol\r
-\r
- \r
-\r
---*/\r
-\r
-#ifndef __EDK_PE_COFF_LOADER_X64_LIB__\r
-#define __EDK_PE_COFF_LOADER_X64_LIB__\r
-\r
-EFI_PEI_PE_COFF_LOADER_PROTOCOL *\r
-EFIAPI\r
-GetPeCoffLoaderX64Protocol (\r
- VOID\r
- );\r
-\r
-#endif\r
-\r
--- /dev/null
+/*++\r
+\r
+Copyright (c) 2004, 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
+ Decompress.c\r
+\r
+Abstract:\r
+\r
+ Decompressor. Algorithm Ported from OPSD code (Decomp.asm) \r
+ for Efi and Tiano compress algorithm.\r
+ \r
+--*/\r
+\r
+#include "Decompress.h"\r
+\r
+//\r
+// Decompression algorithm begins here\r
+//\r
+#define BITBUFSIZ 32\r
+#define MAXMATCH 256\r
+#define THRESHOLD 3\r
+#define CODE_BIT 16\r
+#define BAD_TABLE - 1\r
+\r
+//\r
+// C: Char&Len Set; P: Position Set; T: exTra Set\r
+//\r
+#define NC (0xff + MAXMATCH + 2 - THRESHOLD)\r
+#define CBIT 9\r
+#define EFIPBIT 4\r
+#define MAXPBIT 5\r
+#define TBIT 5\r
+#define MAXNP ((1U << MAXPBIT) - 1)\r
+#define NT (CODE_BIT + 3)\r
+#if NT > MAXNP\r
+#define NPT NT\r
+#else\r
+#define NPT MAXNP\r
+#endif\r
+\r
+typedef struct {\r
+ UINT8 *mSrcBase; // Starting address of compressed data\r
+ UINT8 *mDstBase; // Starting address of decompressed data\r
+ UINT32 mOutBuf;\r
+ UINT32 mInBuf;\r
+\r
+ UINT16 mBitCount;\r
+ UINT32 mBitBuf;\r
+ UINT32 mSubBitBuf;\r
+ UINT16 mBlockSize;\r
+ UINT32 mCompSize;\r
+ UINT32 mOrigSize;\r
+\r
+ UINT16 mBadTableFlag;\r
+\r
+ UINT16 mLeft[2 * NC - 1];\r
+ UINT16 mRight[2 * NC - 1];\r
+ UINT8 mCLen[NC];\r
+ UINT8 mPTLen[NPT];\r
+ UINT16 mCTable[4096];\r
+ UINT16 mPTTable[256];\r
+} SCRATCH_DATA;\r
+\r
+STATIC UINT16 mPbit = EFIPBIT;\r
+ \r
+STATIC\r
+VOID\r
+FillBuf (\r
+ IN SCRATCH_DATA *Sd,\r
+ IN UINT16 NumOfBits\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Shift mBitBuf NumOfBits left. Read in NumOfBits of bits from source.\r
+\r
+Arguments:\r
+\r
+ Sd - The global scratch data\r
+ NumOfBit - The number of bits to shift and read.\r
+\r
+Returns: (VOID)\r
+\r
+--*/\r
+{\r
+ Sd->mBitBuf = (UINT32) (Sd->mBitBuf << NumOfBits);\r
+\r
+ while (NumOfBits > Sd->mBitCount) {\r
+\r
+ Sd->mBitBuf |= (UINT32) (Sd->mSubBitBuf << (NumOfBits = (UINT16) (NumOfBits - Sd->mBitCount)));\r
+\r
+ if (Sd->mCompSize > 0) {\r
+ //\r
+ // Get 1 byte into SubBitBuf\r
+ //\r
+ Sd->mCompSize--;\r
+ Sd->mSubBitBuf = 0;\r
+ Sd->mSubBitBuf = Sd->mSrcBase[Sd->mInBuf++];\r
+ Sd->mBitCount = 8;\r
+\r
+ } else {\r
+ //\r
+ // No more bits from the source, just pad zero bit.\r
+ //\r
+ Sd->mSubBitBuf = 0;\r
+ Sd->mBitCount = 8;\r
+\r
+ }\r
+ }\r
+\r
+ Sd->mBitCount = (UINT16) (Sd->mBitCount - NumOfBits);\r
+ Sd->mBitBuf |= Sd->mSubBitBuf >> Sd->mBitCount;\r
+}\r
+\r
+STATIC\r
+UINT32\r
+GetBits (\r
+ IN SCRATCH_DATA *Sd,\r
+ IN UINT16 NumOfBits\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Get NumOfBits of bits out from mBitBuf. Fill mBitBuf with subsequent \r
+ NumOfBits of bits from source. Returns NumOfBits of bits that are \r
+ popped out.\r
+\r
+Arguments:\r
+\r
+ Sd - The global scratch data.\r
+ NumOfBits - The number of bits to pop and read.\r
+\r
+Returns:\r
+\r
+ The bits that are popped out.\r
+\r
+--*/\r
+{\r
+ UINT32 OutBits;\r
+\r
+ OutBits = (UINT32) (Sd->mBitBuf >> (BITBUFSIZ - NumOfBits));\r
+\r
+ FillBuf (Sd, NumOfBits);\r
+\r
+ return OutBits;\r
+}\r
+\r
+STATIC\r
+UINT16\r
+MakeTable (\r
+ IN SCRATCH_DATA *Sd,\r
+ IN UINT16 NumOfChar,\r
+ IN UINT8 *BitLen,\r
+ IN UINT16 TableBits,\r
+ OUT UINT16 *Table\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Creates Huffman Code mapping table according to code length array.\r
+\r
+Arguments:\r
+\r
+ Sd - The global scratch data\r
+ NumOfChar - Number of symbols in the symbol set\r
+ BitLen - Code length array\r
+ TableBits - The width of the mapping table\r
+ Table - The table\r
+ \r
+Returns:\r
+ \r
+ 0 - OK.\r
+ BAD_TABLE - The table is corrupted.\r
+\r
+--*/\r
+{\r
+ UINT16 Count[17];\r
+ UINT16 Weight[17];\r
+ UINT16 Start[18];\r
+ UINT16 *Pointer;\r
+ UINT16 Index3;\r
+ UINT16 Index;\r
+ UINT16 Len;\r
+ UINT16 Char;\r
+ UINT16 JuBits;\r
+ UINT16 Avail;\r
+ UINT16 NextCode;\r
+ UINT16 Mask;\r
+\r
+ for (Index = 1; Index <= 16; Index++) {\r
+ Count[Index] = 0;\r
+ }\r
+\r
+ for (Index = 0; Index < NumOfChar; Index++) {\r
+ Count[BitLen[Index]]++;\r
+ }\r
+\r
+ Start[1] = 0;\r
+\r
+ for (Index = 1; Index <= 16; Index++) {\r
+ Start[Index + 1] = (UINT16) (Start[Index] + (Count[Index] << (16 - Index)));\r
+ }\r
+\r
+ if (Start[17] != 0) {\r
+ /*(1U << 16)*/\r
+ return (UINT16) BAD_TABLE;\r
+ }\r
+\r
+ JuBits = (UINT16) (16 - TableBits);\r
+\r
+ for (Index = 1; Index <= TableBits; Index++) {\r
+ Start[Index] >>= JuBits;\r
+ Weight[Index] = (UINT16) (1U << (TableBits - Index));\r
+ }\r
+\r
+ while (Index <= 16) {\r
+ Weight[Index++] = (UINT16) (1U << (16 - Index));\r
+ }\r
+\r
+ Index = (UINT16) (Start[TableBits + 1] >> JuBits);\r
+\r
+ if (Index != 0) {\r
+ Index3 = (UINT16) (1U << TableBits);\r
+ while (Index != Index3) {\r
+ Table[Index++] = 0;\r
+ }\r
+ }\r
+\r
+ Avail = NumOfChar;\r
+ Mask = (UINT16) (1U << (15 - TableBits));\r
+\r
+ for (Char = 0; Char < NumOfChar; Char++) {\r
+\r
+ Len = BitLen[Char];\r
+ if (Len == 0) {\r
+ continue;\r
+ }\r
+\r
+ NextCode = (UINT16) (Start[Len] + Weight[Len]);\r
+\r
+ if (Len <= TableBits) {\r
+\r
+ for (Index = Start[Len]; Index < NextCode; Index++) {\r
+ Table[Index] = Char;\r
+ }\r
+\r
+ } else {\r
+\r
+ Index3 = Start[Len];\r
+ Pointer = &Table[Index3 >> JuBits];\r
+ Index = (UINT16) (Len - TableBits);\r
+\r
+ while (Index != 0) {\r
+ if (*Pointer == 0) {\r
+ Sd->mRight[Avail] = Sd->mLeft[Avail] = 0;\r
+ *Pointer = Avail++;\r
+ }\r
+\r
+ if (Index3 & Mask) {\r
+ Pointer = &Sd->mRight[*Pointer];\r
+ } else {\r
+ Pointer = &Sd->mLeft[*Pointer];\r
+ }\r
+\r
+ Index3 <<= 1;\r
+ Index--;\r
+ }\r
+\r
+ *Pointer = Char;\r
+\r
+ }\r
+\r
+ Start[Len] = NextCode;\r
+ }\r
+ //\r
+ // Succeeds\r
+ //\r
+ return 0;\r
+}\r
+\r
+STATIC\r
+UINT32\r
+DecodeP (\r
+ IN SCRATCH_DATA *Sd\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Decodes a position value.\r
+\r
+Arguments:\r
+\r
+ Sd - the global scratch data\r
+\r
+Returns:\r
+\r
+ The position value decoded.\r
+\r
+--*/\r
+{\r
+ UINT16 Val;\r
+ UINT32 Mask;\r
+ UINT32 Pos;\r
+\r
+ Val = Sd->mPTTable[Sd->mBitBuf >> (BITBUFSIZ - 8)];\r
+\r
+ if (Val >= MAXNP) {\r
+ Mask = 1U << (BITBUFSIZ - 1 - 8);\r
+\r
+ do {\r
+\r
+ if (Sd->mBitBuf & Mask) {\r
+ Val = Sd->mRight[Val];\r
+ } else {\r
+ Val = Sd->mLeft[Val];\r
+ }\r
+\r
+ Mask >>= 1;\r
+ } while (Val >= MAXNP);\r
+ }\r
+ //\r
+ // Advance what we have read\r
+ //\r
+ FillBuf (Sd, Sd->mPTLen[Val]);\r
+\r
+ Pos = Val;\r
+ if (Val > 1) {\r
+ Pos = (UINT32) ((1U << (Val - 1)) + GetBits (Sd, (UINT16) (Val - 1)));\r
+ }\r
+\r
+ return Pos;\r
+}\r
+\r
+STATIC\r
+UINT16\r
+ReadPTLen (\r
+ IN SCRATCH_DATA *Sd,\r
+ IN UINT16 nn,\r
+ IN UINT16 nbit,\r
+ IN UINT16 Special\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Reads code lengths for the Extra Set or the Position Set\r
+\r
+Arguments:\r
+\r
+ Sd - The global scratch data\r
+ nn - Number of symbols\r
+ nbit - Number of bits needed to represent nn\r
+ Special - The special symbol that needs to be taken care of \r
+\r
+Returns:\r
+\r
+ 0 - OK.\r
+ BAD_TABLE - Table is corrupted.\r
+\r
+--*/\r
+{\r
+ UINT16 Number;\r
+ UINT16 CharC;\r
+ UINT16 Index;\r
+ UINT32 Mask;\r
+\r
+ Number = (UINT16) GetBits (Sd, nbit);\r
+\r
+ if (Number == 0) {\r
+ CharC = (UINT16) GetBits (Sd, nbit);\r
+\r
+ for (Index = 0; Index < 256; Index++) {\r
+ Sd->mPTTable[Index] = CharC;\r
+ }\r
+\r
+ for (Index = 0; Index < nn; Index++) {\r
+ Sd->mPTLen[Index] = 0;\r
+ }\r
+\r
+ return 0;\r
+ }\r
+\r
+ Index = 0;\r
+\r
+ while (Index < Number) {\r
+\r
+ CharC = (UINT16) (Sd->mBitBuf >> (BITBUFSIZ - 3));\r
+\r
+ if (CharC == 7) {\r
+ Mask = 1U << (BITBUFSIZ - 1 - 3);\r
+ while (Mask & Sd->mBitBuf) {\r
+ Mask >>= 1;\r
+ CharC += 1;\r
+ }\r
+ }\r
+\r
+ FillBuf (Sd, (UINT16) ((CharC < 7) ? 3 : CharC - 3));\r
+\r
+ Sd->mPTLen[Index++] = (UINT8) CharC;\r
+\r
+ if (Index == Special) {\r
+ CharC = (UINT16) GetBits (Sd, 2);\r
+ CharC--;\r
+ while ((INT16) (CharC) >= 0) {\r
+ Sd->mPTLen[Index++] = 0;\r
+ CharC--;\r
+ }\r
+ }\r
+ }\r
+\r
+ while (Index < nn) {\r
+ Sd->mPTLen[Index++] = 0;\r
+ }\r
+\r
+ return MakeTable (Sd, nn, Sd->mPTLen, 8, Sd->mPTTable);\r
+}\r
+\r
+STATIC\r
+VOID\r
+ReadCLen (\r
+ SCRATCH_DATA *Sd\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Reads code lengths for Char&Len Set.\r
+\r
+Arguments:\r
+\r
+ Sd - the global scratch data\r
+\r
+Returns: (VOID)\r
+\r
+--*/\r
+{\r
+ UINT16 Number;\r
+ UINT16 CharC;\r
+ UINT16 Index;\r
+ UINT32 Mask;\r
+\r
+ Number = (UINT16) GetBits (Sd, CBIT);\r
+\r
+ if (Number == 0) {\r
+ CharC = (UINT16) GetBits (Sd, CBIT);\r
+\r
+ for (Index = 0; Index < NC; Index++) {\r
+ Sd->mCLen[Index] = 0;\r
+ }\r
+\r
+ for (Index = 0; Index < 4096; Index++) {\r
+ Sd->mCTable[Index] = CharC;\r
+ }\r
+\r
+ return ;\r
+ }\r
+\r
+ Index = 0;\r
+ while (Index < Number) {\r
+\r
+ CharC = Sd->mPTTable[Sd->mBitBuf >> (BITBUFSIZ - 8)];\r
+ if (CharC >= NT) {\r
+ Mask = 1U << (BITBUFSIZ - 1 - 8);\r
+\r
+ do {\r
+\r
+ if (Mask & Sd->mBitBuf) {\r
+ CharC = Sd->mRight[CharC];\r
+ } else {\r
+ CharC = Sd->mLeft[CharC];\r
+ }\r
+\r
+ Mask >>= 1;\r
+\r
+ } while (CharC >= NT);\r
+ }\r
+ //\r
+ // Advance what we have read\r
+ //\r
+ FillBuf (Sd, Sd->mPTLen[CharC]);\r
+\r
+ if (CharC <= 2) {\r
+\r
+ if (CharC == 0) {\r
+ CharC = 1;\r
+ } else if (CharC == 1) {\r
+ CharC = (UINT16) (GetBits (Sd, 4) + 3);\r
+ } else if (CharC == 2) {\r
+ CharC = (UINT16) (GetBits (Sd, CBIT) + 20);\r
+ }\r
+\r
+ CharC--;\r
+ while ((INT16) (CharC) >= 0) {\r
+ Sd->mCLen[Index++] = 0;\r
+ CharC--;\r
+ }\r
+\r
+ } else {\r
+\r
+ Sd->mCLen[Index++] = (UINT8) (CharC - 2);\r
+\r
+ }\r
+ }\r
+\r
+ while (Index < NC) {\r
+ Sd->mCLen[Index++] = 0;\r
+ }\r
+\r
+ MakeTable (Sd, NC, Sd->mCLen, 12, Sd->mCTable);\r
+\r
+ return ;\r
+}\r
+\r
+STATIC\r
+UINT16\r
+DecodeC (\r
+ SCRATCH_DATA *Sd\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Decode a character/length value.\r
+\r
+Arguments:\r
+\r
+ Sd - The global scratch data.\r
+\r
+Returns:\r
+\r
+ The value decoded.\r
+\r
+--*/\r
+{\r
+ UINT16 Index2;\r
+ UINT32 Mask;\r
+\r
+ if (Sd->mBlockSize == 0) {\r
+ //\r
+ // Starting a new block\r
+ //\r
+ Sd->mBlockSize = (UINT16) GetBits (Sd, 16);\r
+ Sd->mBadTableFlag = ReadPTLen (Sd, NT, TBIT, 3);\r
+ if (Sd->mBadTableFlag != 0) {\r
+ return 0;\r
+ }\r
+\r
+ ReadCLen (Sd);\r
+\r
+ Sd->mBadTableFlag = ReadPTLen (Sd, MAXNP, mPbit, (UINT16) (-1));\r
+ if (Sd->mBadTableFlag != 0) {\r
+ return 0;\r
+ }\r
+ }\r
+\r
+ Sd->mBlockSize--;\r
+ Index2 = Sd->mCTable[Sd->mBitBuf >> (BITBUFSIZ - 12)];\r
+\r
+ if (Index2 >= NC) {\r
+ Mask = 1U << (BITBUFSIZ - 1 - 12);\r
+\r
+ do {\r
+ if (Sd->mBitBuf & Mask) {\r
+ Index2 = Sd->mRight[Index2];\r
+ } else {\r
+ Index2 = Sd->mLeft[Index2];\r
+ }\r
+\r
+ Mask >>= 1;\r
+ } while (Index2 >= NC);\r
+ }\r
+ //\r
+ // Advance what we have read\r
+ //\r
+ FillBuf (Sd, Sd->mCLen[Index2]);\r
+\r
+ return Index2;\r
+}\r
+\r
+STATIC\r
+VOID\r
+Decode (\r
+ SCRATCH_DATA *Sd\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Decode the source data and put the resulting data into the destination buffer.\r
+\r
+Arguments:\r
+\r
+ Sd - The global scratch data\r
+\r
+Returns: (VOID)\r
+\r
+ --*/\r
+{\r
+ UINT16 BytesRemain;\r
+ UINT32 DataIdx;\r
+ UINT16 CharC;\r
+\r
+ BytesRemain = (UINT16) (-1);\r
+\r
+ DataIdx = 0;\r
+\r
+ for (;;) {\r
+ CharC = DecodeC (Sd);\r
+ if (Sd->mBadTableFlag != 0) {\r
+ return ;\r
+ }\r
+\r
+ if (CharC < 256) {\r
+ //\r
+ // Process an Original character\r
+ //\r
+ Sd->mDstBase[Sd->mOutBuf++] = (UINT8) CharC;\r
+ if (Sd->mOutBuf >= Sd->mOrigSize) {\r
+ return ;\r
+ }\r
+\r
+ } else {\r
+ //\r
+ // Process a Pointer\r
+ //\r
+ CharC = (UINT16) (CharC - (UINT8_MAX + 1 - THRESHOLD));\r
+\r
+ BytesRemain = CharC;\r
+\r
+ DataIdx = Sd->mOutBuf - DecodeP (Sd) - 1;\r
+\r
+ BytesRemain--;\r
+ while ((INT16) (BytesRemain) >= 0) {\r
+ Sd->mDstBase[Sd->mOutBuf++] = Sd->mDstBase[DataIdx++];\r
+ if (Sd->mOutBuf >= Sd->mOrigSize) {\r
+ return ;\r
+ }\r
+\r
+ BytesRemain--;\r
+ }\r
+ }\r
+ }\r
+\r
+ return ;\r
+}\r
+\r
+EFI_STATUS\r
+GetInfo (\r
+ IN VOID *Source,\r
+ IN UINT32 SrcSize,\r
+ OUT UINT32 *DstSize,\r
+ OUT UINT32 *ScratchSize\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ The implementation of EFI_DECOMPRESS_PROTOCOL.GetInfo().\r
+\r
+Arguments:\r
+\r
+ Source - The source buffer containing the compressed data.\r
+ SrcSize - The size of source buffer\r
+ DstSize - The size of destination buffer.\r
+ ScratchSize - The size of scratch buffer.\r
+\r
+Returns:\r
+\r
+ EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved.\r
+ EFI_INVALID_PARAMETER - The source data is corrupted\r
+\r
+--*/\r
+{\r
+ UINT8 *Src;\r
+\r
+ *ScratchSize = sizeof (SCRATCH_DATA);\r
+\r
+ Src = Source;\r
+ if (SrcSize < 8) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ *DstSize = Src[4] + (Src[5] << 8) + (Src[6] << 16) + (Src[7] << 24);\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+Decompress (\r
+ IN VOID *Source,\r
+ IN UINT32 SrcSize,\r
+ IN OUT VOID *Destination,\r
+ IN UINT32 DstSize,\r
+ IN OUT VOID *Scratch,\r
+ IN UINT32 ScratchSize\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ The implementation Efi and Tiano Decompress().\r
+\r
+Arguments:\r
+\r
+ Source - The source buffer containing the compressed data.\r
+ SrcSize - The size of source buffer\r
+ Destination - The destination buffer to store the decompressed data\r
+ DstSize - The size of destination buffer.\r
+ Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.\r
+ ScratchSize - The size of scratch buffer.\r
+\r
+Returns:\r
+\r
+ EFI_SUCCESS - Decompression is successfull\r
+ EFI_INVALID_PARAMETER - The source data is corrupted\r
+\r
+--*/\r
+{\r
+ UINT32 Index;\r
+ UINT32 CompSize;\r
+ UINT32 OrigSize;\r
+ EFI_STATUS Status;\r
+ SCRATCH_DATA *Sd;\r
+ UINT8 *Src;\r
+ UINT8 *Dst;\r
+\r
+ Status = EFI_SUCCESS;\r
+ Src = Source;\r
+ Dst = Destination;\r
+\r
+ if (ScratchSize < sizeof (SCRATCH_DATA)) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ Sd = (SCRATCH_DATA *) Scratch;\r
+\r
+ if (SrcSize < 8) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ CompSize = Src[0] + (Src[1] << 8) + (Src[2] << 16) + (Src[3] << 24);\r
+ OrigSize = Src[4] + (Src[5] << 8) + (Src[6] << 16) + (Src[7] << 24);\r
+\r
+ if (SrcSize < CompSize + 8) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ if (DstSize != OrigSize) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ Src = Src + 8;\r
+\r
+ for (Index = 0; Index < sizeof (SCRATCH_DATA); Index++) {\r
+ ((UINT8 *) Sd)[Index] = 0;\r
+ }\r
+\r
+ Sd->mSrcBase = Src;\r
+ Sd->mDstBase = Dst;\r
+ Sd->mCompSize = CompSize;\r
+ Sd->mOrigSize = OrigSize;\r
+\r
+ //\r
+ // Fill the first BITBUFSIZ bits\r
+ //\r
+ FillBuf (Sd, BITBUFSIZ);\r
+\r
+ //\r
+ // Decompress it\r
+ //\r
+ Decode (Sd);\r
+\r
+ if (Sd->mBadTableFlag != 0) {\r
+ //\r
+ // Something wrong with the source\r
+ //\r
+ Status = EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EfiGetInfo (\r
+ IN VOID *Source,\r
+ IN UINT32 SrcSize,\r
+ OUT UINT32 *DstSize,\r
+ OUT UINT32 *ScratchSize\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ The implementation Efi Decompress GetInfo().\r
+\r
+Arguments:\r
+\r
+ Source - The source buffer containing the compressed data.\r
+ SrcSize - The size of source buffer\r
+ DstSize - The size of destination buffer.\r
+ ScratchSize - The size of scratch buffer.\r
+\r
+Returns:\r
+\r
+ EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved.\r
+ EFI_INVALID_PARAMETER - The source data is corrupted\r
+\r
+--*/\r
+{\r
+ return GetInfo (Source, SrcSize, DstSize, ScratchSize);\r
+}\r
+\r
+EFI_STATUS\r
+TianoGetInfo (\r
+ IN VOID *Source,\r
+ IN UINT32 SrcSize,\r
+ OUT UINT32 *DstSize,\r
+ OUT UINT32 *ScratchSize\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ The implementation Tiano Decompress GetInfo().\r
+\r
+Arguments:\r
+\r
+ Source - The source buffer containing the compressed data.\r
+ SrcSize - The size of source buffer\r
+ DstSize - The size of destination buffer.\r
+ ScratchSize - The size of scratch buffer.\r
+\r
+Returns:\r
+\r
+ EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved.\r
+ EFI_INVALID_PARAMETER - The source data is corrupted\r
+\r
+--*/\r
+{\r
+ return GetInfo (Source, SrcSize, DstSize, ScratchSize);\r
+}\r
+\r
+EFI_STATUS\r
+EfiDecompress (\r
+ IN VOID *Source,\r
+ IN UINT32 SrcSize,\r
+ IN OUT VOID *Destination,\r
+ IN UINT32 DstSize,\r
+ IN OUT VOID *Scratch,\r
+ IN UINT32 ScratchSize\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ The implementation of Efi Decompress().\r
+\r
+Arguments:\r
+\r
+ Source - The source buffer containing the compressed data.\r
+ SrcSize - The size of source buffer\r
+ Destination - The destination buffer to store the decompressed data\r
+ DstSize - The size of destination buffer.\r
+ Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.\r
+ ScratchSize - The size of scratch buffer.\r
+\r
+Returns:\r
+\r
+ EFI_SUCCESS - Decompression is successfull\r
+ EFI_INVALID_PARAMETER - The source data is corrupted\r
+\r
+--*/\r
+{\r
+ mPbit = EFIPBIT;\r
+ return Decompress (Source, SrcSize, Destination, DstSize, Scratch, ScratchSize);\r
+}\r
+\r
+EFI_STATUS\r
+TianoDecompress (\r
+ IN VOID *Source,\r
+ IN UINT32 SrcSize,\r
+ IN OUT VOID *Destination,\r
+ IN UINT32 DstSize,\r
+ IN OUT VOID *Scratch,\r
+ IN UINT32 ScratchSize\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ The implementation of Tiano Decompress().\r
+\r
+Arguments:\r
+\r
+ Source - The source buffer containing the compressed data.\r
+ SrcSize - The size of source buffer\r
+ Destination - The destination buffer to store the decompressed data\r
+ DstSize - The size of destination buffer.\r
+ Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.\r
+ ScratchSize - The size of scratch buffer.\r
+\r
+Returns:\r
+\r
+ EFI_SUCCESS - Decompression is successfull\r
+ EFI_INVALID_PARAMETER - The source data is corrupted\r
+\r
+--*/\r
+{\r
+ mPbit = MAXPBIT;\r
+ return Decompress (Source, SrcSize, Destination, DstSize, Scratch, ScratchSize);\r
+}\r
--- /dev/null
+/*++\r
+\r
+Copyright (c) 2006, 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
+ Decompress.h\r
+\r
+Abstract:\r
+\r
+ Header file for compression routine\r
+ \r
+--*/\r
+\r
+#ifndef _EFI_DECOMPRESS_H\r
+#define _EFI_DECOMPRESS_H\r
+\r
+#include <Common/UefiBaseTypes.h>\r
+\r
+EFI_STATUS\r
+EfiGetInfo (\r
+ IN VOID *Source,\r
+ IN UINT32 SrcSize,\r
+ OUT UINT32 *DstSize,\r
+ OUT UINT32 *ScratchSize\r
+ );\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ The implementation Efi Decompress GetInfo().\r
+\r
+Arguments:\r
+\r
+ Source - The source buffer containing the compressed data.\r
+ SrcSize - The size of source buffer\r
+ DstSize - The size of destination buffer.\r
+ ScratchSize - The size of scratch buffer.\r
+\r
+Returns:\r
+\r
+ EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved.\r
+ EFI_INVALID_PARAMETER - The source data is corrupted\r
+\r
+--*/\r
+\r
+EFI_STATUS\r
+EfiDecompress (\r
+ IN VOID *Source,\r
+ IN UINT32 SrcSize,\r
+ IN OUT VOID *Destination,\r
+ IN UINT32 DstSize,\r
+ IN OUT VOID *Scratch,\r
+ IN UINT32 ScratchSize\r
+ );\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ The implementation of Efi Decompress().\r
+\r
+Arguments:\r
+\r
+ Source - The source buffer containing the compressed data.\r
+ SrcSize - The size of source buffer\r
+ Destination - The destination buffer to store the decompressed data\r
+ DstSize - The size of destination buffer.\r
+ Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.\r
+ ScratchSize - The size of scratch buffer.\r
+\r
+Returns:\r
+\r
+ EFI_SUCCESS - Decompression is successfull\r
+ EFI_INVALID_PARAMETER - The source data is corrupted\r
+\r
+--*/\r
+\r
+EFI_STATUS\r
+TianoGetInfo (\r
+ IN VOID *Source,\r
+ IN UINT32 SrcSize,\r
+ OUT UINT32 *DstSize,\r
+ OUT UINT32 *ScratchSize\r
+ );\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ The implementation Tiano Decompress GetInfo().\r
+\r
+Arguments:\r
+\r
+ Source - The source buffer containing the compressed data.\r
+ SrcSize - The size of source buffer\r
+ DstSize - The size of destination buffer.\r
+ ScratchSize - The size of scratch buffer.\r
+\r
+Returns:\r
+\r
+ EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved.\r
+ EFI_INVALID_PARAMETER - The source data is corrupted\r
+\r
+--*/\r
+\r
+EFI_STATUS\r
+TianoDecompress (\r
+ IN VOID *Source,\r
+ IN UINT32 SrcSize,\r
+ IN OUT VOID *Destination,\r
+ IN UINT32 DstSize,\r
+ IN OUT VOID *Scratch,\r
+ IN UINT32 ScratchSize\r
+ );\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ The implementation of Tiano Decompress().\r
+\r
+Arguments:\r
+\r
+ Source - The source buffer containing the compressed data.\r
+ SrcSize - The size of source buffer\r
+ Destination - The destination buffer to store the decompressed data\r
+ DstSize - The size of destination buffer.\r
+ Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.\r
+ ScratchSize - The size of scratch buffer.\r
+\r
+Returns:\r
+\r
+ EFI_SUCCESS - Decompression is successfull\r
+ EFI_INVALID_PARAMETER - The source data is corrupted\r
+\r
+--*/\r
+\r
+typedef\r
+EFI_STATUS\r
+(*GETINFO_FUNCTION) (\r
+ IN VOID *Source,\r
+ IN UINT32 SrcSize,\r
+ OUT UINT32 *DstSize,\r
+ OUT UINT32 *ScratchSize\r
+ );\r
+\r
+typedef\r
+EFI_STATUS\r
+(*DECOMPRESS_FUNCTION) (\r
+ IN VOID *Source,\r
+ IN UINT32 SrcSize,\r
+ IN OUT VOID *Destination,\r
+ IN UINT32 DstSize,\r
+ IN OUT VOID *Scratch,\r
+ IN UINT32 ScratchSize\r
+ );\r
+#endif\r
+++ /dev/null
-/*++\r
-\r
-Copyright (c) 2004, 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
- EfiDecompress.c\r
-\r
-Abstract:\r
-\r
- Decompressor. Algorithm Ported from OPSD code (Decomp.asm)\r
- \r
---*/\r
-\r
-#include "EfiDecompress.h"\r
-\r
-//\r
-// Decompression algorithm begins here\r
-//\r
-#define BITBUFSIZ 32\r
-#define MAXMATCH 256\r
-#define THRESHOLD 3\r
-#define CODE_BIT 16\r
-#define BAD_TABLE - 1\r
-\r
-//\r
-// C: Char&Len Set; P: Position Set; T: exTra Set\r
-//\r
-#define NC (0xff + MAXMATCH + 2 - THRESHOLD)\r
-#define CBIT 9\r
-#define PBIT 5\r
-#define TBIT 5\r
-#define MAXNP ((1U << PBIT) - 1)\r
-#define NT (CODE_BIT + 3)\r
-#if NT > MAXNP\r
-#define NPT NT\r
-#else\r
-#define NPT MAXNP\r
-#endif\r
-\r
-typedef struct {\r
- UINT8 *mSrcBase; // Starting address of compressed data\r
- UINT8 *mDstBase; // Starting address of decompressed data\r
- UINT32 mOutBuf;\r
- UINT32 mInBuf;\r
-\r
- UINT16 mBitCount;\r
- UINT32 mBitBuf;\r
- UINT32 mSubBitBuf;\r
- UINT16 mBlockSize;\r
- UINT32 mCompSize;\r
- UINT32 mOrigSize;\r
-\r
- UINT16 mBadTableFlag;\r
-\r
- UINT16 mLeft[2 * NC - 1];\r
- UINT16 mRight[2 * NC - 1];\r
- UINT8 mCLen[NC];\r
- UINT8 mPTLen[NPT];\r
- UINT16 mCTable[4096];\r
- UINT16 mPTTable[256];\r
-} SCRATCH_DATA;\r
-\r
-STATIC\r
-VOID\r
-FillBuf (\r
- IN SCRATCH_DATA *Sd,\r
- IN UINT16 NumOfBits\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Shift mBitBuf NumOfBits left. Read in NumOfBits of bits from source.\r
-\r
-Arguments:\r
-\r
- Sd - The global scratch data\r
- NumOfBit - The number of bits to shift and read.\r
-\r
-Returns: (VOID)\r
-\r
---*/\r
-{\r
- Sd->mBitBuf = (UINT32) (Sd->mBitBuf << NumOfBits);\r
-\r
- while (NumOfBits > Sd->mBitCount) {\r
-\r
- Sd->mBitBuf |= (UINT32) (Sd->mSubBitBuf << (NumOfBits = (UINT16) (NumOfBits - Sd->mBitCount)));\r
-\r
- if (Sd->mCompSize > 0) {\r
- //\r
- // Get 1 byte into SubBitBuf\r
- //\r
- Sd->mCompSize--;\r
- Sd->mSubBitBuf = 0;\r
- Sd->mSubBitBuf = Sd->mSrcBase[Sd->mInBuf++];\r
- Sd->mBitCount = 8;\r
-\r
- } else {\r
- //\r
- // No more bits from the source, just pad zero bit.\r
- //\r
- Sd->mSubBitBuf = 0;\r
- Sd->mBitCount = 8;\r
-\r
- }\r
- }\r
-\r
- Sd->mBitCount = (UINT16) (Sd->mBitCount - NumOfBits);\r
- Sd->mBitBuf |= Sd->mSubBitBuf >> Sd->mBitCount;\r
-}\r
-\r
-STATIC\r
-UINT32\r
-GetBits (\r
- IN SCRATCH_DATA *Sd,\r
- IN UINT16 NumOfBits\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Get NumOfBits of bits out from mBitBuf. Fill mBitBuf with subsequent \r
- NumOfBits of bits from source. Returns NumOfBits of bits that are \r
- popped out.\r
-\r
-Arguments:\r
-\r
- Sd - The global scratch data.\r
- NumOfBits - The number of bits to pop and read.\r
-\r
-Returns:\r
-\r
- The bits that are popped out.\r
-\r
---*/\r
-{\r
- UINT32 OutBits;\r
-\r
- OutBits = (UINT32) (Sd->mBitBuf >> (BITBUFSIZ - NumOfBits));\r
-\r
- FillBuf (Sd, NumOfBits);\r
-\r
- return OutBits;\r
-}\r
-\r
-STATIC\r
-UINT16\r
-MakeTable (\r
- IN SCRATCH_DATA *Sd,\r
- IN UINT16 NumOfChar,\r
- IN UINT8 *BitLen,\r
- IN UINT16 TableBits,\r
- OUT UINT16 *Table\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Creates Huffman Code mapping table according to code length array.\r
-\r
-Arguments:\r
-\r
- Sd - The global scratch data\r
- NumOfChar - Number of symbols in the symbol set\r
- BitLen - Code length array\r
- TableBits - The width of the mapping table\r
- Table - The table\r
- \r
-Returns:\r
- \r
- 0 - OK.\r
- BAD_TABLE - The table is corrupted.\r
-\r
---*/\r
-{\r
- UINT16 Count[17];\r
- UINT16 Weight[17];\r
- UINT16 Start[18];\r
- UINT16 *Pointer;\r
- UINT16 Index3;\r
- UINT16 Index;\r
- UINT16 Len;\r
- UINT16 Char;\r
- UINT16 JuBits;\r
- UINT16 Avail;\r
- UINT16 NextCode;\r
- UINT16 Mask;\r
-\r
- for (Index = 1; Index <= 16; Index++) {\r
- Count[Index] = 0;\r
- }\r
-\r
- for (Index = 0; Index < NumOfChar; Index++) {\r
- Count[BitLen[Index]]++;\r
- }\r
-\r
- Start[1] = 0;\r
-\r
- for (Index = 1; Index <= 16; Index++) {\r
- Start[Index + 1] = (UINT16) (Start[Index] + (Count[Index] << (16 - Index)));\r
- }\r
-\r
- if (Start[17] != 0) {\r
- /*(1U << 16)*/\r
- return (UINT16) BAD_TABLE;\r
- }\r
-\r
- JuBits = (UINT16) (16 - TableBits);\r
-\r
- for (Index = 1; Index <= TableBits; Index++) {\r
- Start[Index] >>= JuBits;\r
- Weight[Index] = (UINT16) (1U << (TableBits - Index));\r
- }\r
-\r
- while (Index <= 16) {\r
- Weight[Index++] = (UINT16) (1U << (16 - Index));\r
- }\r
-\r
- Index = (UINT16) (Start[TableBits + 1] >> JuBits);\r
-\r
- if (Index != 0) {\r
- Index3 = (UINT16) (1U << TableBits);\r
- while (Index != Index3) {\r
- Table[Index++] = 0;\r
- }\r
- }\r
-\r
- Avail = NumOfChar;\r
- Mask = (UINT16) (1U << (15 - TableBits));\r
-\r
- for (Char = 0; Char < NumOfChar; Char++) {\r
-\r
- Len = BitLen[Char];\r
- if (Len == 0) {\r
- continue;\r
- }\r
-\r
- NextCode = (UINT16) (Start[Len] + Weight[Len]);\r
-\r
- if (Len <= TableBits) {\r
-\r
- for (Index = Start[Len]; Index < NextCode; Index++) {\r
- Table[Index] = Char;\r
- }\r
-\r
- } else {\r
-\r
- Index3 = Start[Len];\r
- Pointer = &Table[Index3 >> JuBits];\r
- Index = (UINT16) (Len - TableBits);\r
-\r
- while (Index != 0) {\r
- if (*Pointer == 0) {\r
- Sd->mRight[Avail] = Sd->mLeft[Avail] = 0;\r
- *Pointer = Avail++;\r
- }\r
-\r
- if (Index3 & Mask) {\r
- Pointer = &Sd->mRight[*Pointer];\r
- } else {\r
- Pointer = &Sd->mLeft[*Pointer];\r
- }\r
-\r
- Index3 <<= 1;\r
- Index--;\r
- }\r
-\r
- *Pointer = Char;\r
-\r
- }\r
-\r
- Start[Len] = NextCode;\r
- }\r
- //\r
- // Succeeds\r
- //\r
- return 0;\r
-}\r
-\r
-STATIC\r
-UINT32\r
-DecodeP (\r
- IN SCRATCH_DATA *Sd\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Decodes a position value.\r
-\r
-Arguments:\r
-\r
- Sd - the global scratch data\r
-\r
-Returns:\r
-\r
- The position value decoded.\r
-\r
---*/\r
-{\r
- UINT16 Val;\r
- UINT32 Mask;\r
- UINT32 Pos;\r
-\r
- Val = Sd->mPTTable[Sd->mBitBuf >> (BITBUFSIZ - 8)];\r
-\r
- if (Val >= MAXNP) {\r
- Mask = 1U << (BITBUFSIZ - 1 - 8);\r
-\r
- do {\r
-\r
- if (Sd->mBitBuf & Mask) {\r
- Val = Sd->mRight[Val];\r
- } else {\r
- Val = Sd->mLeft[Val];\r
- }\r
-\r
- Mask >>= 1;\r
- } while (Val >= MAXNP);\r
- }\r
- //\r
- // Advance what we have read\r
- //\r
- FillBuf (Sd, Sd->mPTLen[Val]);\r
-\r
- Pos = Val;\r
- if (Val > 1) {\r
- Pos = (UINT32) ((1U << (Val - 1)) + GetBits (Sd, (UINT16) (Val - 1)));\r
- }\r
-\r
- return Pos;\r
-}\r
-\r
-STATIC\r
-UINT16\r
-ReadPTLen (\r
- IN SCRATCH_DATA *Sd,\r
- IN UINT16 nn,\r
- IN UINT16 nbit,\r
- IN UINT16 Special\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Reads code lengths for the Extra Set or the Position Set\r
-\r
-Arguments:\r
-\r
- Sd - The global scratch data\r
- nn - Number of symbols\r
- nbit - Number of bits needed to represent nn\r
- Special - The special symbol that needs to be taken care of \r
-\r
-Returns:\r
-\r
- 0 - OK.\r
- BAD_TABLE - Table is corrupted.\r
-\r
---*/\r
-{\r
- UINT16 Number;\r
- UINT16 CharC;\r
- UINT16 Index;\r
- UINT32 Mask;\r
-\r
- Number = (UINT16) GetBits (Sd, nbit);\r
-\r
- if (Number == 0) {\r
- CharC = (UINT16) GetBits (Sd, nbit);\r
-\r
- for (Index = 0; Index < 256; Index++) {\r
- Sd->mPTTable[Index] = CharC;\r
- }\r
-\r
- for (Index = 0; Index < nn; Index++) {\r
- Sd->mPTLen[Index] = 0;\r
- }\r
-\r
- return 0;\r
- }\r
-\r
- Index = 0;\r
-\r
- while (Index < Number) {\r
-\r
- CharC = (UINT16) (Sd->mBitBuf >> (BITBUFSIZ - 3));\r
-\r
- if (CharC == 7) {\r
- Mask = 1U << (BITBUFSIZ - 1 - 3);\r
- while (Mask & Sd->mBitBuf) {\r
- Mask >>= 1;\r
- CharC += 1;\r
- }\r
- }\r
-\r
- FillBuf (Sd, (UINT16) ((CharC < 7) ? 3 : CharC - 3));\r
-\r
- Sd->mPTLen[Index++] = (UINT8) CharC;\r
-\r
- if (Index == Special) {\r
- CharC = (UINT16) GetBits (Sd, 2);\r
- CharC--;\r
- while ((INT16) (CharC) >= 0) {\r
- Sd->mPTLen[Index++] = 0;\r
- CharC--;\r
- }\r
- }\r
- }\r
-\r
- while (Index < nn) {\r
- Sd->mPTLen[Index++] = 0;\r
- }\r
-\r
- return MakeTable (Sd, nn, Sd->mPTLen, 8, Sd->mPTTable);\r
-}\r
-\r
-STATIC\r
-VOID\r
-ReadCLen (\r
- SCRATCH_DATA *Sd\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Reads code lengths for Char&Len Set.\r
-\r
-Arguments:\r
-\r
- Sd - the global scratch data\r
-\r
-Returns: (VOID)\r
-\r
---*/\r
-{\r
- UINT16 Number;\r
- UINT16 CharC;\r
- UINT16 Index;\r
- UINT32 Mask;\r
-\r
- Number = (UINT16) GetBits (Sd, CBIT);\r
-\r
- if (Number == 0) {\r
- CharC = (UINT16) GetBits (Sd, CBIT);\r
-\r
- for (Index = 0; Index < NC; Index++) {\r
- Sd->mCLen[Index] = 0;\r
- }\r
-\r
- for (Index = 0; Index < 4096; Index++) {\r
- Sd->mCTable[Index] = CharC;\r
- }\r
-\r
- return ;\r
- }\r
-\r
- Index = 0;\r
- while (Index < Number) {\r
-\r
- CharC = Sd->mPTTable[Sd->mBitBuf >> (BITBUFSIZ - 8)];\r
- if (CharC >= NT) {\r
- Mask = 1U << (BITBUFSIZ - 1 - 8);\r
-\r
- do {\r
-\r
- if (Mask & Sd->mBitBuf) {\r
- CharC = Sd->mRight[CharC];\r
- } else {\r
- CharC = Sd->mLeft[CharC];\r
- }\r
-\r
- Mask >>= 1;\r
-\r
- } while (CharC >= NT);\r
- }\r
- //\r
- // Advance what we have read\r
- //\r
- FillBuf (Sd, Sd->mPTLen[CharC]);\r
-\r
- if (CharC <= 2) {\r
-\r
- if (CharC == 0) {\r
- CharC = 1;\r
- } else if (CharC == 1) {\r
- CharC = (UINT16) (GetBits (Sd, 4) + 3);\r
- } else if (CharC == 2) {\r
- CharC = (UINT16) (GetBits (Sd, CBIT) + 20);\r
- }\r
-\r
- CharC--;\r
- while ((INT16) (CharC) >= 0) {\r
- Sd->mCLen[Index++] = 0;\r
- CharC--;\r
- }\r
-\r
- } else {\r
-\r
- Sd->mCLen[Index++] = (UINT8) (CharC - 2);\r
-\r
- }\r
- }\r
-\r
- while (Index < NC) {\r
- Sd->mCLen[Index++] = 0;\r
- }\r
-\r
- MakeTable (Sd, NC, Sd->mCLen, 12, Sd->mCTable);\r
-\r
- return ;\r
-}\r
-\r
-STATIC\r
-UINT16\r
-DecodeC (\r
- SCRATCH_DATA *Sd\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Decode a character/length value.\r
-\r
-Arguments:\r
-\r
- Sd - The global scratch data.\r
-\r
-Returns:\r
-\r
- The value decoded.\r
-\r
---*/\r
-{\r
- UINT16 Index2;\r
- UINT32 Mask;\r
-\r
- if (Sd->mBlockSize == 0) {\r
- //\r
- // Starting a new block\r
- //\r
- Sd->mBlockSize = (UINT16) GetBits (Sd, 16);\r
- Sd->mBadTableFlag = ReadPTLen (Sd, NT, TBIT, 3);\r
- if (Sd->mBadTableFlag != 0) {\r
- return 0;\r
- }\r
-\r
- ReadCLen (Sd);\r
-\r
- Sd->mBadTableFlag = ReadPTLen (Sd, MAXNP, PBIT, (UINT16) (-1));\r
- if (Sd->mBadTableFlag != 0) {\r
- return 0;\r
- }\r
- }\r
-\r
- Sd->mBlockSize--;\r
- Index2 = Sd->mCTable[Sd->mBitBuf >> (BITBUFSIZ - 12)];\r
-\r
- if (Index2 >= NC) {\r
- Mask = 1U << (BITBUFSIZ - 1 - 12);\r
-\r
- do {\r
- if (Sd->mBitBuf & Mask) {\r
- Index2 = Sd->mRight[Index2];\r
- } else {\r
- Index2 = Sd->mLeft[Index2];\r
- }\r
-\r
- Mask >>= 1;\r
- } while (Index2 >= NC);\r
- }\r
- //\r
- // Advance what we have read\r
- //\r
- FillBuf (Sd, Sd->mCLen[Index2]);\r
-\r
- return Index2;\r
-}\r
-\r
-STATIC\r
-VOID\r
-Decode (\r
- SCRATCH_DATA *Sd\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Decode the source data and put the resulting data into the destination buffer.\r
-\r
-Arguments:\r
-\r
- Sd - The global scratch data\r
-\r
-Returns: (VOID)\r
-\r
- --*/\r
-{\r
- UINT16 BytesRemain;\r
- UINT32 DataIdx;\r
- UINT16 CharC;\r
-\r
- BytesRemain = (UINT16) (-1);\r
-\r
- DataIdx = 0;\r
-\r
- for (;;) {\r
- CharC = DecodeC (Sd);\r
- if (Sd->mBadTableFlag != 0) {\r
- return ;\r
- }\r
-\r
- if (CharC < 256) {\r
- //\r
- // Process an Original character\r
- //\r
- Sd->mDstBase[Sd->mOutBuf++] = (UINT8) CharC;\r
- if (Sd->mOutBuf >= Sd->mOrigSize) {\r
- return ;\r
- }\r
-\r
- } else {\r
- //\r
- // Process a Pointer\r
- //\r
- CharC = (UINT16) (CharC - (UINT8_MAX + 1 - THRESHOLD));\r
-\r
- BytesRemain = CharC;\r
-\r
- DataIdx = Sd->mOutBuf - DecodeP (Sd) - 1;\r
-\r
- BytesRemain--;\r
- while ((INT16) (BytesRemain) >= 0) {\r
- Sd->mDstBase[Sd->mOutBuf++] = Sd->mDstBase[DataIdx++];\r
- if (Sd->mOutBuf >= Sd->mOrigSize) {\r
- return ;\r
- }\r
-\r
- BytesRemain--;\r
- }\r
- }\r
- }\r
-\r
- return ;\r
-}\r
-\r
-EFI_STATUS\r
-GetInfo (\r
- IN VOID *Source,\r
- IN UINT32 SrcSize,\r
- OUT UINT32 *DstSize,\r
- OUT UINT32 *ScratchSize\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- The implementation of EFI_DECOMPRESS_PROTOCOL.GetInfo().\r
-\r
-Arguments:\r
-\r
- Source - The source buffer containing the compressed data.\r
- SrcSize - The size of source buffer\r
- DstSize - The size of destination buffer.\r
- ScratchSize - The size of scratch buffer.\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved.\r
- EFI_INVALID_PARAMETER - The source data is corrupted\r
-\r
---*/\r
-{\r
- UINT8 *Src;\r
-\r
- *ScratchSize = sizeof (SCRATCH_DATA);\r
-\r
- Src = Source;\r
- if (SrcSize < 8) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- *DstSize = Src[4] + (Src[5] << 8) + (Src[6] << 16) + (Src[7] << 24);\r
- return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-Decompress (\r
- IN VOID *Source,\r
- IN UINT32 SrcSize,\r
- IN OUT VOID *Destination,\r
- IN UINT32 DstSize,\r
- IN OUT VOID *Scratch,\r
- IN UINT32 ScratchSize\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- The implementation of EFI_DECOMPRESS_PROTOCOL.Decompress().\r
-\r
-Arguments:\r
-\r
- This - The protocol instance pointer\r
- Source - The source buffer containing the compressed data.\r
- SrcSize - The size of source buffer\r
- Destination - The destination buffer to store the decompressed data\r
- DstSize - The size of destination buffer.\r
- Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.\r
- ScratchSize - The size of scratch buffer.\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS - Decompression is successfull\r
- EFI_INVALID_PARAMETER - The source data is corrupted\r
-\r
---*/\r
-{\r
- UINT32 Index;\r
- UINT32 CompSize;\r
- UINT32 OrigSize;\r
- EFI_STATUS Status;\r
- SCRATCH_DATA *Sd;\r
- UINT8 *Src;\r
- UINT8 *Dst;\r
-\r
- Status = EFI_SUCCESS;\r
- Src = Source;\r
- Dst = Destination;\r
-\r
- if (ScratchSize < sizeof (SCRATCH_DATA)) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Sd = (SCRATCH_DATA *) Scratch;\r
-\r
- if (SrcSize < 8) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- CompSize = Src[0] + (Src[1] << 8) + (Src[2] << 16) + (Src[3] << 24);\r
- OrigSize = Src[4] + (Src[5] << 8) + (Src[6] << 16) + (Src[7] << 24);\r
-\r
- if (SrcSize < CompSize + 8) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- if (DstSize != OrigSize) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Src = Src + 8;\r
-\r
- for (Index = 0; Index < sizeof (SCRATCH_DATA); Index++) {\r
- ((UINT8 *) Sd)[Index] = 0;\r
- }\r
-\r
- Sd->mSrcBase = Src;\r
- Sd->mDstBase = Dst;\r
- Sd->mCompSize = CompSize;\r
- Sd->mOrigSize = OrigSize;\r
-\r
- //\r
- // Fill the first BITBUFSIZ bits\r
- //\r
- FillBuf (Sd, BITBUFSIZ);\r
-\r
- //\r
- // Decompress it\r
- //\r
- Decode (Sd);\r
-\r
- if (Sd->mBadTableFlag != 0) {\r
- //\r
- // Something wrong with the source\r
- //\r
- Status = EFI_INVALID_PARAMETER;\r
- }\r
-\r
- return Status;\r
-}\r
+++ /dev/null
-/*++\r
-\r
-Copyright (c) 2004, 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
- EfiDecompress.h\r
-\r
-Abstract:\r
-\r
- Header file for compression routine\r
- \r
---*/\r
-\r
-#ifndef _EFI_DECOMPRESS_H\r
-#define _EFI_DECOMPRESS_H\r
-\r
-#include <Common/UefiBaseTypes.h>\r
-\r
-EFI_STATUS\r
-GetInfo (\r
- IN VOID *Source,\r
- IN UINT32 SrcSize,\r
- OUT UINT32 *DstSize,\r
- OUT UINT32 *ScratchSize\r
- );\r
-\r
-/*++\r
-\r
-Routine Description:\r
-\r
- The implementation of EFI_DECOMPRESS_PROTOCOL.GetInfo().\r
-\r
-Arguments:\r
-\r
- Source - The source buffer containing the compressed data.\r
- SrcSize - The size of source buffer\r
- DstSize - The size of destination buffer.\r
- ScratchSize - The size of scratch buffer.\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved.\r
- EFI_INVALID_PARAMETER - The source data is corrupted\r
-\r
---*/\r
-EFI_STATUS\r
-Decompress (\r
- IN VOID *Source,\r
- IN UINT32 SrcSize,\r
- IN OUT VOID *Destination,\r
- IN UINT32 DstSize,\r
- IN OUT VOID *Scratch,\r
- IN UINT32 ScratchSize\r
- )\r
-;\r
-\r
-/*++\r
-\r
-Routine Description:\r
-\r
- The implementation of EFI_DECOMPRESS_PROTOCOL.Decompress().\r
-\r
-Arguments:\r
-\r
- This - The protocol instance pointer\r
- Source - The source buffer containing the compressed data.\r
- SrcSize - The size of source buffer\r
- Destination - The destination buffer to store the decompressed data\r
- DstSize - The size of destination buffer.\r
- Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.\r
- ScratchSize - The size of scratch buffer.\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS - Decompression is successfull\r
- EFI_INVALID_PARAMETER - The source data is corrupted\r
-\r
---*/\r
-typedef\r
-EFI_STATUS\r
-(*GETINFO_FUNCTION) (\r
- IN VOID *Source,\r
- IN UINT32 SrcSize,\r
- OUT UINT32 *DstSize,\r
- OUT UINT32 *ScratchSize\r
- );\r
-\r
-typedef\r
-EFI_STATUS\r
-(*DECOMPRESS_FUNCTION) (\r
- IN VOID *Source,\r
- IN UINT32 SrcSize,\r
- IN OUT VOID *Destination,\r
- IN UINT32 DstSize,\r
- IN OUT VOID *Scratch,\r
- IN UINT32 ScratchSize\r
- );\r
-#endif\r
\r
extern\r
EFI_STATUS\r
-TianoCompress (\r
+EfiCompress (\r
IN UINT8 *SrcBuffer,\r
IN UINT32 SrcSize,\r
IN UINT8 *DstBuffer,\r
// First call compress function and get need buffer size\r
//\r
\r
- Result = TianoCompress (\r
+ Result = EfiCompress (\r
(char*) InputBuffer, \r
SourceSize, \r
DestBuffer,\r
//\r
// Second call compress and get the DestBuffer value\r
//\r
- Result = TianoCompress(\r
- (char*) InputBuffer, \r
+ Result = EfiCompress(\r
+ (char*) InputBuffer, \r
SourceSize, \r
DestBuffer,\r
&DestSize \r
- );\r
+ );\r
\r
//\r
// new a MV array to store the return compressed buffer\r
// Added "Dummy" to keep backward compatibility.\r
//\r
CompressionType = EFI_STANDARD_COMPRESSION;\r
- CompressFunction = (COMPRESS_FUNCTION) TianoCompress;\r
+ CompressFunction = (COMPRESS_FUNCTION) EfiCompress;\r
\r
} else if (strcmpi (Type, "LZH") == 0) {\r
//\r
// EFI stardard compression (LZH)\r
//\r
CompressionType = EFI_STANDARD_COMPRESSION;\r
- CompressFunction = (COMPRESS_FUNCTION) TianoCompress;\r
+ CompressFunction = (COMPRESS_FUNCTION) EfiCompress;\r
\r
} else {\r
//\r
break;\r
\r
case EFI_STANDARD_COMPRESSION:\r
- CompressFunction = (COMPRESS_FUNCTION) TianoCompress;\r
+ CompressFunction = (COMPRESS_FUNCTION) EfiCompress;\r
break;\r
\r
case EFI_CUSTOMIZED_COMPRESSION:\r