**/\r
\r
//\r
-// Decompression algorithm begins here\r
+// The package level header files this module uses\r
+//\r
+#include <Base.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\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
+// The Library classes this module consumes\r
//\r
-#define NC (0xff + MAXMATCH + 2 - THRESHOLD)\r
-#define CBIT 9\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
-\r
- ///\r
- /// The length of the field 'Position Set Code Length Array Size' in Block Header.\r
- /// For EFI 1.1 de/compression algorithm, mPBit = 4\r
- /// For Tiano de/compression algorithm, mPBit = 5\r
- ///\r
- UINT8 mPBit;\r
-} SCRATCH_DATA;\r
+#include <Library/UefiDecompressLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+\r
+#include "BaseUefiDecompressLibInternals.h"\r
\r
/**\r
Read NumOfBit of bits from source into mBitBuf\r
UINT16 Avail;\r
UINT16 NextCode;\r
UINT16 Mask;\r
+ UINT16 WordOfStart;\r
+ UINT16 WordOfCount;\r
+\r
\r
for (Index = 1; Index <= 16; Index++) {\r
Count[Index] = 0;\r
Start[1] = 0;\r
\r
for (Index = 1; Index <= 16; Index++) {\r
- Start[Index + 1] = (UINT16) (Start[Index] + (Count[Index] << (16 - Index)));\r
+ WordOfStart = Start[Index];\r
+ WordOfCount = Count[Index];\r
+ Start[Index + 1] = (UINT16) (WordOfStart + (WordOfCount << (16 - Index)));\r
}\r
\r
if (Start[17] != 0) {\r
// \r
CharC = DecodeC (Sd);\r
if (Sd->mBadTableFlag != 0) {\r
- return ;\r
+ goto Done;\r
}\r
\r
if (CharC < 256) {\r
// Process an Original character\r
//\r
if (Sd->mOutBuf >= Sd->mOrigSize) {\r
- return ;\r
+ goto Done;\r
} else {\r
//\r
// Write orignal character into mDstBase\r
while ((INT16) (BytesRemain) >= 0) {\r
Sd->mDstBase[Sd->mOutBuf++] = Sd->mDstBase[DataIdx++];\r
if (Sd->mOutBuf >= Sd->mOrigSize) {\r
- return ;\r
+ goto Done;\r
}\r
\r
BytesRemain--;\r
}\r
}\r
\r
+Done:\r
return ;\r
}\r
\r
\r
This function is designed so that the decompression algorithm can be implemented\r
without using any memory services. As a result, this function is not allowed to\r
- call any memory allocation services in its implementation. It is the caller¡¯s r\r
+ call any memory allocation services in its implementation. It is the caller's r\r
esponsibility to allocate and free the Destination and Scratch buffers.\r
If the compressed source data specified by Source is sucessfully decompressed \r
into Destination, then RETURN_SUCCESS is returned. If the compressed source data \r