30 Sd->mBitBuf = (UINT32)
LShiftU64 (((UINT64)Sd->mBitBuf), NumOfBits);
35 while (NumOfBits > Sd->mBitCount) {
36 NumOfBits = (UINT16)(NumOfBits - Sd->mBitCount);
37 Sd->mBitBuf |= (UINT32)
LShiftU64 (((UINT64)Sd->mSubBitBuf), NumOfBits);
39 if (Sd->mCompSize > 0) {
44 Sd->mSubBitBuf = Sd->mSrcBase[Sd->mInBuf++];
58 Sd->mBitCount = (UINT16)(Sd->mBitCount - NumOfBits);
63 Sd->mBitBuf |= Sd->mSubBitBuf >> Sd->mBitCount;
90 OutBits = (UINT32)(Sd->mBitBuf >> (BITBUFSIZ - NumOfBits));
140 UINT16 MaxTableLength;
146 ASSERT (TableBits <= 16);
148 for (Index = 0; Index <= 16; Index++) {
152 for (Index = 0; Index < NumOfChar; Index++) {
153 if (BitLen[Index] > 16) {
154 return (UINT16)BAD_TABLE;
157 Count[BitLen[Index]]++;
163 for (Index = 1; Index <= 16; Index++) {
164 WordOfStart = Start[Index];
165 WordOfCount = Count[Index];
166 Start[Index + 1] = (UINT16)(WordOfStart + (WordOfCount << (16 - Index)));
169 if (Start[17] != 0) {
171 return (UINT16)BAD_TABLE;
174 JuBits = (UINT16)(16 - TableBits);
177 for (Index = 1; Index <= TableBits; Index++) {
178 Start[Index] >>= JuBits;
179 Weight[Index] = (UINT16)(1U << (TableBits - Index));
182 while (Index <= 16) {
183 Weight[Index] = (UINT16)(1U << (16 - Index));
187 Index = (UINT16)(Start[TableBits + 1] >> JuBits);
190 Index3 = (UINT16)(1U << TableBits);
191 if (Index < Index3) {
192 SetMem16 (Table + Index, (Index3 - Index) *
sizeof (*Table), 0);
197 Mask = (UINT16)(1U << (15 - TableBits));
198 MaxTableLength = (UINT16)(1U << TableBits);
200 for (Char = 0; Char < NumOfChar; Char++) {
202 if ((Len == 0) || (Len >= 17)) {
206 NextCode = (UINT16)(Start[Len] + Weight[Len]);
208 if (Len <= TableBits) {
209 if ((Start[Len] >= NextCode) || (NextCode > MaxTableLength)) {
210 return (UINT16)BAD_TABLE;
213 for (Index = Start[Len]; Index < NextCode; Index++) {
218 Pointer = &Table[Index3 >> JuBits];
219 Index = (UINT16)(Len - TableBits);
222 if ((*Pointer == 0) && (Avail < (2 * NC - 1))) {
223 Sd->mRight[Avail] = Sd->mLeft[Avail] = 0;
227 if (*Pointer < (2 * NC - 1)) {
228 if ((Index3 & Mask) != 0) {
229 Pointer = &Sd->mRight[*Pointer];
231 Pointer = &Sd->mLeft[*Pointer];
242 Start[Len] = NextCode;
270 Val = Sd->mPTTable[Sd->mBitBuf >> (BITBUFSIZ - 8)];
273 Mask = 1U << (BITBUFSIZ - 1 - 8);
276 if ((Sd->mBitBuf & Mask) != 0) {
277 Val = Sd->mRight[Val];
279 Val = Sd->mLeft[Val];
283 }
while (Val >= MAXNP);
293 Pos = (UINT32)((1U << (Val - 1)) +
GetBits (Sd, (UINT16)(Val - 1)));
331 Number = (UINT16)
GetBits (Sd, nbit);
337 CharC = (UINT16)
GetBits (Sd, nbit);
339 SetMem16 (&Sd->mPTTable[0], sizeof (Sd->mPTTable), CharC);
341 SetMem (Sd->mPTLen, nn, 0);
348 while (Index < Number && Index < NPT) {
349 CharC = (UINT16)(Sd->mBitBuf >> (BITBUFSIZ - 3));
357 Mask = 1U << (BITBUFSIZ - 1 - 3);
358 while (Mask & Sd->mBitBuf) {
364 FillBuf (Sd, (UINT16)((CharC < 7) ? 3 : CharC - 3));
366 Sd->mPTLen[Index++] = (UINT8)CharC;
374 if (Index == Special) {
375 CharC = (UINT16)
GetBits (Sd, 2);
376 while ((INT16)(--CharC) >= 0 && Index < NPT) {
377 Sd->mPTLen[Index++] = 0;
382 while (Index < nn && Index < NPT) {
383 Sd->mPTLen[Index++] = 0;
386 return MakeTable (Sd, nn, Sd->mPTLen, 8, Sd->mPTTable);
408 Number = (UINT16)
GetBits (Sd, CBIT);
414 CharC = (UINT16)
GetBits (Sd, CBIT);
416 SetMem (Sd->mCLen, NC, 0);
417 SetMem16 (&Sd->mCTable[0], sizeof (Sd->mCTable), CharC);
423 while (Index < Number && Index < NC) {
424 CharC = Sd->mPTTable[Sd->mBitBuf >> (BITBUFSIZ - 8)];
426 Mask = 1U << (BITBUFSIZ - 1 - 8);
429 if (Mask & Sd->mBitBuf) {
430 CharC = Sd->mRight[CharC];
432 CharC = Sd->mLeft[CharC];
436 }
while (CharC >= NT);
442 FillBuf (Sd, Sd->mPTLen[CharC]);
447 }
else if (CharC == 1) {
448 CharC = (UINT16)(
GetBits (Sd, 4) + 3);
449 }
else if (CharC == 2) {
450 CharC = (UINT16)(
GetBits (Sd, CBIT) + 20);
453 while ((INT16)(--CharC) >= 0 && Index < NC) {
454 Sd->mCLen[Index++] = 0;
457 Sd->mCLen[Index++] = (UINT8)(CharC - 2);
461 SetMem (Sd->mCLen + Index, NC - Index, 0);
463 MakeTable (Sd, NC, Sd->mCLen, 12, Sd->mCTable);
488 if (Sd->mBlockSize == 0) {
493 Sd->mBlockSize = (UINT16)
GetBits (Sd, 16);
499 Sd->mBadTableFlag =
ReadPTLen (Sd, NT, TBIT, 3);
500 if (Sd->mBadTableFlag != 0) {
514 Sd->mBadTableFlag =
ReadPTLen (Sd, MAXNP, Sd->
mPBit, (UINT16)(-1));
515 if (Sd->mBadTableFlag != 0) {
524 Index2 = Sd->mCTable[Sd->mBitBuf >> (BITBUFSIZ - 12)];
527 Mask = 1U << (BITBUFSIZ - 1 - 12);
530 if ((Sd->mBitBuf & Mask) != 0) {
531 Index2 = Sd->mRight[Index2];
533 Index2 = Sd->mLeft[Index2];
537 }
while (Index2 >= NC);
543 FillBuf (Sd, Sd->mCLen[Index2]);
563 BytesRemain = (UINT16)(-1);
572 if (Sd->mBadTableFlag != 0) {
580 if (Sd->mOutBuf >= Sd->mOrigSize) {
586 Sd->mDstBase[Sd->mOutBuf++] = (UINT8)CharC;
592 CharC = (UINT16)(CharC - (BIT8 - THRESHOLD));
602 DataIdx = Sd->mOutBuf -
DecodeP (Sd) - 1;
609 while ((INT16)(BytesRemain) >= 0) {
610 if (Sd->mOutBuf >= Sd->mOrigSize) {
614 if (DataIdx >= Sd->mOrigSize) {
615 Sd->mBadTableFlag = (UINT16)BAD_TABLE;
619 Sd->mDstBase[Sd->mOutBuf++] = Sd->mDstBase[DataIdx++];
627 if (Sd->mOutBuf >= Sd->mOrigSize) {
680 IN UINT32 SourceSize,
681 OUT UINT32 *DestinationSize,
682 OUT UINT32 *ScratchSize
685 UINT32 CompressedSize;
687 ASSERT (Source !=
NULL);
688 ASSERT (DestinationSize !=
NULL);
689 ASSERT (ScratchSize !=
NULL);
691 if (SourceSize < 8) {
696 if ((SourceSize < (CompressedSize + 8)) || ((CompressedSize + 8) < 8)) {
740 IN OUT VOID *Destination,
741 IN OUT VOID *Scratch,
751 ASSERT (Source !=
NULL);
752 ASSERT (Destination !=
NULL);
753 ASSERT (Scratch !=
NULL);
754 ASSERT (Version == 1 || Version == 2);
761 CompSize = Src[0] + (Src[1] << 8) + (Src[2] << 16) + (Src[3] << 24);
762 OrigSize = Src[4] + (Src[5] << 8) + (Src[6] << 16) + (Src[7] << 24);
790 Sd->mSrcBase = (UINT8 *)Src;
795 Sd->mCompSize = CompSize;
796 Sd->mOrigSize = OrigSize;
808 if (Sd->mBadTableFlag != 0) {
851 IN OUT VOID *Destination,
852 IN OUT VOID *Scratch OPTIONAL
UINT64 EFIAPI LShiftU64(IN UINT64 Operand, IN UINTN Count)
UINT32 EFIAPI ReadUnaligned32(IN CONST UINT32 *Buffer)
VOID *EFIAPI SetMem16(OUT VOID *Buffer, IN UINTN Length, IN UINT16 Value)
VOID *EFIAPI SetMem(OUT VOID *Buffer, IN UINTN Length, IN UINT8 Value)
VOID FillBuf(IN SCRATCH_DATA *Sd, IN UINT16 NumOfBits)
RETURN_STATUS UefiTianoDecompress(IN CONST VOID *Source, IN OUT VOID *Destination, IN OUT VOID *Scratch, IN UINT32 Version)
UINT32 GetBits(IN SCRATCH_DATA *Sd, IN UINT16 NumOfBits)
VOID ReadCLen(SCRATCH_DATA *Sd)
UINT32 DecodeP(IN SCRATCH_DATA *Sd)
UINT16 ReadPTLen(IN SCRATCH_DATA *Sd, IN UINT16 nn, IN UINT16 nbit, IN UINT16 Special)
RETURN_STATUS EFIAPI UefiDecompress(IN CONST VOID *Source, IN OUT VOID *Destination, IN OUT VOID *Scratch OPTIONAL)
UINT16 MakeTable(IN SCRATCH_DATA *Sd, IN UINT16 NumOfChar, IN UINT8 *BitLen, IN UINT16 TableBits, OUT UINT16 *Table)
VOID Decode(SCRATCH_DATA *Sd)
RETURN_STATUS EFIAPI UefiDecompressGetInfo(IN CONST VOID *Source, IN UINT32 SourceSize, OUT UINT32 *DestinationSize, OUT UINT32 *ScratchSize)
UINT16 DecodeC(SCRATCH_DATA *Sd)
#define RETURN_INVALID_PARAMETER