]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.c
IntelFrameworkModulePkg: Fix MSFT C4255 warning
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / BaseUefiTianoCustomDecompressLib / BaseUefiTianoCustomDecompressLib.c
index dbac719aeaf79c9f4b15399c6e11ab85206076d1..cb009e7771bb815fa6ee3d157f26098319ccf476 100644 (file)
@@ -1,9 +1,9 @@
 /** @file\r
   UEFI and Tiano Custom Decompress Library \r
-  Tt will do Tiano or UEFI decompress with different verison parameter.\r
+  It will do Tiano or UEFI decompress with different verison parameter.\r
   \r
-Copyright (c) 2006 - 2009, Intel Corporation                                                         \r
-All rights reserved. This program and the accompanying materials                          \r
+Copyright (c) 2006 - 2015, 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
@@ -30,14 +30,14 @@ FillBuf (
   //\r
   // Left shift NumOfBits of bits in advance\r
   //\r
-  Sd->mBitBuf = (UINT32) (Sd->mBitBuf << NumOfBits);\r
+  Sd->mBitBuf = (UINT32) LShiftU64 (((UINT64)Sd->mBitBuf), NumOfBits);\r
 \r
   //\r
   // Copy data needed in bytes into mSbuBitBuf\r
   //\r
   while (NumOfBits > Sd->mBitCount) {\r
-\r
-    Sd->mBitBuf |= (UINT32) (Sd->mSubBitBuf << (NumOfBits = (UINT16) (NumOfBits - Sd->mBitCount)));\r
+    NumOfBits = (UINT16) (NumOfBits - Sd->mBitCount);\r
+    Sd->mBitBuf |= (UINT32) LShiftU64 (((UINT64)Sd->mSubBitBuf), NumOfBits);\r
 \r
     if (Sd->mCompSize > 0) {\r
       //\r
@@ -59,7 +59,7 @@ FillBuf (
   }\r
 \r
   //\r
-  // Caculate additional bit count read to update mBitCount\r
+  // Calculate additional bit count read to update mBitCount\r
   //\r
   Sd->mBitCount = (UINT16) (Sd->mBitCount - NumOfBits);\r
   \r
@@ -108,6 +108,7 @@ GetBits (
 \r
   Creates Huffman Code mapping table for Extra Set, Char&Len Set \r
   and Position Set according to code length array.\r
+  If TableBits > 16, then ASSERT ().\r
 \r
   @param  Sd        The global scratch data\r
   @param  NumOfChar Number of symbols in the symbol set\r
@@ -143,6 +144,12 @@ MakeTable (
   UINT16  WordOfStart;\r
   UINT16  WordOfCount;\r
 \r
+  //\r
+  // The maximum mapping table width supported by this internal\r
+  // working function is 16.\r
+  //\r
+  ASSERT (TableBits <= 16);\r
+\r
   for (Index = 0; Index <= 16; Index++) {\r
     Count[Index] = 0;\r
   }\r
@@ -291,7 +298,7 @@ DecodeP (
 /**\r
   Reads code lengths for the Extra Set or the Position Set.\r
 \r
-  Read in the Extra Set or Pointion Set Length Arrary, then\r
+  Read in the Extra Set or Position Set Length Array, then\r
   generate the Huffman code mapping for them.\r
 \r
   @param  Sd      The global scratch data.\r
@@ -316,6 +323,7 @@ ReadPTLen (
   UINT16  Index;\r
   UINT32  Mask;\r
 \r
+  ASSERT (nn <= NPT);\r
   //\r
   // Read Extra Set Code Length Array size \r
   //\r
@@ -495,7 +503,7 @@ DecodeC (
     Sd->mBlockSize    = (UINT16) GetBits (Sd, 16);\r
 \r
     //\r
-    // Read in the Extra Set Code Length Arrary,\r
+    // Read in the Extra Set Code Length Array,\r
     // Generate the Huffman code mapping table for Extra Set.\r
     //\r
     Sd->mBadTableFlag = ReadPTLen (Sd, NT, TBIT, 3);\r
@@ -504,13 +512,13 @@ DecodeC (
     }\r
 \r
     //\r
-    // Read in and decode the Char&Len Set Code Length Arrary,\r
+    // Read in and decode the Char&Len Set Code Length Array,\r
     // Generate the Huffman code mapping table for Char&Len Set.\r
     //\r
     ReadCLen (Sd);\r
 \r
     //\r
-    // Read in the Position Set Code Length Arrary, \r
+    // Read in the Position Set Code Length Array,\r
     // Generate the Huffman code mapping table for the Position Set.\r
     //\r
     Sd->mBadTableFlag = ReadPTLen (Sd, MAXNP, Sd->mPBit, (UINT16) (-1));\r
@@ -776,7 +784,7 @@ UefiTianoDecompress (
   Sd->mSrcBase  = (UINT8 *)Src;\r
   Sd->mDstBase  = Dst;\r
   //\r
-  // CompSize and OrigSize are caculated in bytes\r
+  // CompSize and OrigSize are calculated in bytes\r
   //\r
   Sd->mCompSize = CompSize;\r
   Sd->mOrigSize = OrigSize;\r
@@ -890,25 +898,47 @@ TianoDecompressGetInfo (
     return RETURN_INVALID_PARAMETER;\r
   }\r
 \r
-  if (!CompareGuid (\r
-        &gTianoCustomDecompressGuid, \r
+  if (IS_SECTION2 (InputSection)) {\r
+    if (!CompareGuid (\r
+        &gTianoCustomDecompressGuid,\r
+        &(((EFI_GUID_DEFINED_SECTION2 *) InputSection)->SectionDefinitionGuid))) {\r
+      return RETURN_INVALID_PARAMETER;\r
+    }\r
+    //\r
+    // Get guid attribute of guid section. \r
+    //\r
+    *SectionAttribute = ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->Attributes;\r
+\r
+    //\r
+    // Call Tiano GetInfo to get the required size info.\r
+    //\r
+    return UefiDecompressGetInfo (\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
+        &gTianoCustomDecompressGuid,\r
         &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
-    return RETURN_INVALID_PARAMETER;\r
-  }\r
-  //\r
-  // Get guid attribute of guid section. \r
-  //\r
-  *SectionAttribute = ((EFI_GUID_DEFINED_SECTION *) InputSection)->Attributes;\r
+      return RETURN_INVALID_PARAMETER;\r
+    }\r
+    //\r
+    // Get guid attribute of guid section. \r
+    //\r
+    *SectionAttribute = ((EFI_GUID_DEFINED_SECTION *) InputSection)->Attributes;\r
 \r
-  //\r
-  // Call Tiano GetInfo to get the required size info.\r
-  //\r
-  return UefiDecompressGetInfo (\r
-          (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
-          (*(UINT32 *) (((EFI_COMMON_SECTION_HEADER *) InputSection)->Size) & 0x00ffffff) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
-          OutputBufferSize,\r
-          ScratchBufferSize\r
-         );\r
+    //\r
+    // Call Tiano GetInfo to get the required size info.\r
+    //\r
+    return UefiDecompressGetInfo (\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
@@ -956,26 +986,49 @@ TianoDecompress (
   ASSERT (OutputBuffer != NULL);\r
   ASSERT (InputSection != NULL);\r
 \r
-  if (!CompareGuid (\r
-        &gTianoCustomDecompressGuid, \r
+  if (IS_SECTION2 (InputSection)) {\r
+    if (!CompareGuid (\r
+        &gTianoCustomDecompressGuid,\r
+        &(((EFI_GUID_DEFINED_SECTION2 *) InputSection)->SectionDefinitionGuid))) {\r
+      return RETURN_INVALID_PARAMETER;\r
+    }\r
+\r
+    //\r
+    // Set Authentication to Zero.\r
+    //\r
+    *AuthenticationStatus = 0;\r
+\r
+    //\r
+    // Call Tiano Decompress to get the raw data\r
+    //\r
+    return UefiTianoDecompress (\r
+             (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,\r
+             *OutputBuffer,\r
+             ScratchBuffer,\r
+             2\r
+           );\r
+  } else {\r
+    if (!CompareGuid (\r
+        &gTianoCustomDecompressGuid,\r
         &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
-    return RETURN_INVALID_PARAMETER;\r
-  }\r
+      return RETURN_INVALID_PARAMETER;\r
+    }\r
 \r
-  //\r
-  // Set Authentication to Zero.\r
-  //\r
-  *AuthenticationStatus = 0;\r
-  \r
-  //\r
-  // Call Tiano Decompress to get the raw data\r
-  //\r
-  return UefiTianoDecompress (\r
-          (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
-          *OutputBuffer,\r
-          ScratchBuffer,\r
-          2\r
-         );\r
+    //\r
+    // Set Authentication to Zero.\r
+    //\r
+    *AuthenticationStatus = 0;\r
+\r
+    //\r
+    // Call Tiano Decompress to get the raw data\r
+    //\r
+    return UefiTianoDecompress (\r
+             (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
+             *OutputBuffer,\r
+             ScratchBuffer,\r
+             2\r
+           );\r
+  }\r
 }\r
 \r
 /**\r
@@ -987,11 +1040,12 @@ TianoDecompress (
 RETURN_STATUS\r
 EFIAPI\r
 TianoDecompressLibConstructor (\r
+  VOID\r
 )\r
 {\r
   return ExtractGuidedSectionRegisterHandlers (\r
           &gTianoCustomDecompressGuid,\r
           TianoDecompressGetInfo,\r
           TianoDecompress\r
-          );      \r
+          );\r
 }\r