X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=DuetPkg%2FEfiLdr%2FTianoDecompress.c;h=695f5162fcbf58a96d76d02a407cf5d9e36c99de;hp=9a9ab70be449380881cccec0717fd7eece9765cb;hb=76c09700edc67686b29662e81a3ca7d947594ce5;hpb=3da85e633e2589a312fb3646660ef68e6a0bf18b diff --git a/DuetPkg/EfiLdr/TianoDecompress.c b/DuetPkg/EfiLdr/TianoDecompress.c index 9a9ab70be4..695f5162fc 100644 --- a/DuetPkg/EfiLdr/TianoDecompress.c +++ b/DuetPkg/EfiLdr/TianoDecompress.c @@ -1,7 +1,7 @@ /*++ -Copyright (c) 2004 - 2006, Intel Corporation -All rights reserved. This program and the accompanying materials +Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.
+This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php @@ -26,7 +26,6 @@ Abstract: #define MAXMATCH 256 #define THRESHOLD 3 #define CODE_BIT 16 -#define UINT8_MAX 0xff #define BAD_TABLE - 1 // @@ -74,7 +73,6 @@ typedef struct { UINT8 mPBit; } SCRATCH_DATA; -STATIC VOID FillBuf ( IN SCRATCH_DATA *Sd, @@ -95,11 +93,11 @@ Returns: (VOID) --*/ { - Sd->mBitBuf = (UINT32) (Sd->mBitBuf << NumOfBits); + Sd->mBitBuf = (UINT32) LShiftU64 (((UINT64)Sd->mBitBuf), NumOfBits); while (NumOfBits > Sd->mBitCount) { - - Sd->mBitBuf |= (UINT32) (Sd->mSubBitBuf << (NumOfBits = (UINT16) (NumOfBits - Sd->mBitCount))); + NumOfBits = (UINT16) (NumOfBits - Sd->mBitCount); + Sd->mBitBuf |= (UINT32) LShiftU64 (((UINT64)Sd->mSubBitBuf), NumOfBits); if (Sd->mCompSize > 0) { // @@ -124,7 +122,6 @@ Returns: (VOID) Sd->mBitBuf |= Sd->mSubBitBuf >> Sd->mBitCount; } -STATIC UINT32 GetBits ( IN SCRATCH_DATA *Sd, @@ -158,7 +155,6 @@ Returns: return OutBits; } -STATIC UINT16 MakeTable ( IN SCRATCH_DATA *Sd, @@ -193,17 +189,19 @@ Returns: UINT16 Start[18]; UINT16 *Pointer; UINT16 Index3; - UINT16 Index; + volatile UINT16 Index; UINT16 Len; UINT16 Char; UINT16 JuBits; UINT16 Avail; UINT16 NextCode; UINT16 Mask; + UINT16 WordOfStart; + UINT16 WordOfCount; for (Index = 1; Index <= 16; Index++) { Count[Index] = 0; - } + } for (Index = 0; Index < NumOfChar; Index++) { Count[BitLen[Index]]++; @@ -212,7 +210,9 @@ Returns: Start[1] = 0; for (Index = 1; Index <= 16; Index++) { - Start[Index + 1] = (UINT16) (Start[Index] + (Count[Index] << (16 - Index))); + WordOfStart = Start[Index]; + WordOfCount = Count[Index]; + Start[Index + 1] = (UINT16) (WordOfStart + (WordOfCount << (16 - Index))); } if (Start[17] != 0) { @@ -228,7 +228,8 @@ Returns: } while (Index <= 16) { - Weight[Index++] = (UINT16) (1U << (16 - Index)); + Weight[Index] = (UINT16) (1U << (16 - Index)); + Index++; } Index = (UINT16) (Start[TableBits + 1] >> JuBits); @@ -292,7 +293,6 @@ Returns: return 0; } -STATIC UINT32 DecodeP ( IN SCRATCH_DATA *Sd @@ -346,7 +346,6 @@ Returns: return Pos; } -STATIC UINT16 ReadPTLen ( IN SCRATCH_DATA *Sd, @@ -376,7 +375,7 @@ Returns: { UINT16 Number; UINT16 CharC; - UINT16 Index; + volatile UINT16 Index; UINT32 Mask; Number = (UINT16) GetBits (Sd, nbit); @@ -428,7 +427,6 @@ Returns: return MakeTable (Sd, nn, Sd->mPTLen, 8, Sd->mPTTable); } -STATIC VOID ReadCLen ( SCRATCH_DATA *Sd @@ -449,7 +447,7 @@ Returns: (VOID) { UINT16 Number; UINT16 CharC; - UINT16 Index; + volatile UINT16 Index; UINT32 Mask; Number = (UINT16) GetBits (Sd, CBIT); @@ -522,7 +520,6 @@ Returns: (VOID) return ; } -STATIC UINT16 DecodeC ( SCRATCH_DATA *Sd @@ -588,7 +585,6 @@ Returns: return Index2; } -STATIC VOID Decode ( SCRATCH_DATA *Sd @@ -618,7 +614,7 @@ Returns: (VOID) for (;;) { CharC = DecodeC (Sd); if (Sd->mBadTableFlag != 0) { - return ; + goto Done ; } if (CharC < 256) { @@ -626,7 +622,7 @@ Returns: (VOID) // Process an Original character // if (Sd->mOutBuf >= Sd->mOrigSize) { - return ; + goto Done ; } else { Sd->mDstBase[Sd->mOutBuf++] = (UINT8) CharC; } @@ -635,7 +631,7 @@ Returns: (VOID) // // Process a Pointer // - CharC = (UINT16) (CharC - (UINT8_MAX + 1 - THRESHOLD)); + CharC = (UINT16) (CharC - (BIT8 - THRESHOLD)); BytesRemain = CharC; @@ -645,7 +641,7 @@ Returns: (VOID) while ((INT16) (BytesRemain) >= 0) { Sd->mDstBase[Sd->mOutBuf++] = Sd->mDstBase[DataIdx++]; if (Sd->mOutBuf >= Sd->mOrigSize) { - return ; + goto Done ; } BytesRemain--; @@ -653,6 +649,7 @@ Returns: (VOID) } } +Done: return ; } @@ -678,7 +675,7 @@ Arguments: Returns: - EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved. + EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successfully retrieved. EFI_INVALID_PARAMETER - The source data is corrupted --*/ @@ -731,14 +728,14 @@ Returns: --*/ { - UINT32 Index; UINT32 CompSize; UINT32 OrigSize; EFI_STATUS Status; SCRATCH_DATA *Sd; UINT8 *Src; UINT8 *Dst; - + volatile UINT32 Index; + Status = EFI_SUCCESS; Src = Source; Dst = Destination; @@ -776,6 +773,7 @@ Returns: for (Index = 0; Index < sizeof (SCRATCH_DATA); Index++) { ((UINT8 *) Sd)[Index] = 0; } + // // The length of the field 'Position Set Code Length Array Size' in Block Header. // For EFI 1.1 de/compression algorithm(Version 1), mPBit = 4 @@ -846,7 +844,7 @@ Arguments: Returns: - EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved. + EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successfully retrieved. EFI_INVALID_PARAMETER - The source data is corrupted --*/ @@ -930,7 +928,7 @@ Arguments: Returns: - EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved. + EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successfully retrieved. EFI_INVALID_PARAMETER - The source data is corrupted --*/