Vishal Bhoj | 82c8071 | 2015-12-15 21:13:33 +0530 | [diff] [blame^] | 1 | /** @file
|
| 2 | Internal data structure defintions for Base UEFI Decompress Libary.
|
| 3 |
|
| 4 | Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
|
| 5 | This program and the accompanying materials
|
| 6 | are licensed and made available under the terms and conditions of the BSD License
|
| 7 | which accompanies this distribution. The full text of the license may be found at
|
| 8 | http://opensource.org/licenses/bsd-license.php.
|
| 9 |
|
| 10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
| 11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
| 12 |
|
| 13 | **/
|
| 14 |
|
| 15 | #ifndef __BASE_UEFI_DECOMPRESS_LIB_INTERNALS_H__
|
| 16 | #define __BASE_UEFI_DECOMPRESS_LIB_INTERNALS_H__
|
| 17 |
|
| 18 | //
|
| 19 | // Decompression algorithm begins here
|
| 20 | //
|
| 21 | #define BITBUFSIZ 32
|
| 22 | #define MAXMATCH 256
|
| 23 | #define THRESHOLD 3
|
| 24 | #define CODE_BIT 16
|
| 25 | #define BAD_TABLE - 1
|
| 26 |
|
| 27 | //
|
| 28 | // C: Char&Len Set; P: Position Set; T: exTra Set
|
| 29 | //
|
| 30 | #define NC (0xff + MAXMATCH + 2 - THRESHOLD)
|
| 31 | #define CBIT 9
|
| 32 | #define MAXPBIT 5
|
| 33 | #define TBIT 5
|
| 34 | #define MAXNP ((1U << MAXPBIT) - 1)
|
| 35 | #define NT (CODE_BIT + 3)
|
| 36 | #if NT > MAXNP
|
| 37 | #define NPT NT
|
| 38 | #else
|
| 39 | #define NPT MAXNP
|
| 40 | #endif
|
| 41 |
|
| 42 | typedef struct {
|
| 43 | UINT8 *mSrcBase; // The starting address of compressed data
|
| 44 | UINT8 *mDstBase; // The starting address of decompressed data
|
| 45 | UINT32 mOutBuf;
|
| 46 | UINT32 mInBuf;
|
| 47 |
|
| 48 | UINT16 mBitCount;
|
| 49 | UINT32 mBitBuf;
|
| 50 | UINT32 mSubBitBuf;
|
| 51 | UINT16 mBlockSize;
|
| 52 | UINT32 mCompSize;
|
| 53 | UINT32 mOrigSize;
|
| 54 |
|
| 55 | UINT16 mBadTableFlag;
|
| 56 |
|
| 57 | UINT16 mLeft[2 * NC - 1];
|
| 58 | UINT16 mRight[2 * NC - 1];
|
| 59 | UINT8 mCLen[NC];
|
| 60 | UINT8 mPTLen[NPT];
|
| 61 | UINT16 mCTable[4096];
|
| 62 | UINT16 mPTTable[256];
|
| 63 |
|
| 64 | ///
|
| 65 | /// The length of the field 'Position Set Code Length Array Size' in Block Header.
|
| 66 | /// For UEFI 2.0 de/compression algorithm, mPBit = 4.
|
| 67 | ///
|
| 68 | UINT8 mPBit;
|
| 69 | } SCRATCH_DATA;
|
| 70 |
|
| 71 | /**
|
| 72 | Read NumOfBit of bits from source into mBitBuf.
|
| 73 |
|
| 74 | Shift mBitBuf NumOfBits left. Read in NumOfBits of bits from source.
|
| 75 |
|
| 76 | @param Sd The global scratch data.
|
| 77 | @param NumOfBits The number of bits to shift and read.
|
| 78 |
|
| 79 | **/
|
| 80 | VOID
|
| 81 | FillBuf (
|
| 82 | IN SCRATCH_DATA *Sd,
|
| 83 | IN UINT16 NumOfBits
|
| 84 | );
|
| 85 |
|
| 86 | /**
|
| 87 | Get NumOfBits of bits out from mBitBuf.
|
| 88 |
|
| 89 | Get NumOfBits of bits out from mBitBuf. Fill mBitBuf with subsequent
|
| 90 | NumOfBits of bits from source. Returns NumOfBits of bits that are
|
| 91 | popped out.
|
| 92 |
|
| 93 | @param Sd The global scratch data.
|
| 94 | @param NumOfBits The number of bits to pop and read.
|
| 95 |
|
| 96 | @return The bits that are popped out.
|
| 97 |
|
| 98 | **/
|
| 99 | UINT32
|
| 100 | GetBits (
|
| 101 | IN SCRATCH_DATA *Sd,
|
| 102 | IN UINT16 NumOfBits
|
| 103 | );
|
| 104 |
|
| 105 | /**
|
| 106 | Creates Huffman Code mapping table according to code length array.
|
| 107 |
|
| 108 | Creates Huffman Code mapping table for Extra Set, Char&Len Set
|
| 109 | and Position Set according to code length array.
|
| 110 | If TableBits > 16, then ASSERT ().
|
| 111 |
|
| 112 | @param Sd The global scratch data.
|
| 113 | @param NumOfChar The number of symbols in the symbol set.
|
| 114 | @param BitLen Code length array.
|
| 115 | @param TableBits The width of the mapping table.
|
| 116 | @param Table The table to be created.
|
| 117 |
|
| 118 | @retval 0 OK.
|
| 119 | @retval BAD_TABLE The table is corrupted.
|
| 120 |
|
| 121 | **/
|
| 122 | UINT16
|
| 123 | MakeTable (
|
| 124 | IN SCRATCH_DATA *Sd,
|
| 125 | IN UINT16 NumOfChar,
|
| 126 | IN UINT8 *BitLen,
|
| 127 | IN UINT16 TableBits,
|
| 128 | OUT UINT16 *Table
|
| 129 | );
|
| 130 |
|
| 131 | /**
|
| 132 | Decodes a position value.
|
| 133 |
|
| 134 | Get a position value according to Position Huffman Table.
|
| 135 |
|
| 136 | @param Sd The global scratch data.
|
| 137 |
|
| 138 | @return The position value decoded.
|
| 139 |
|
| 140 | **/
|
| 141 | UINT32
|
| 142 | DecodeP (
|
| 143 | IN SCRATCH_DATA *Sd
|
| 144 | );
|
| 145 |
|
| 146 | /**
|
| 147 | Reads code lengths for the Extra Set or the Position Set.
|
| 148 |
|
| 149 | Read in the Extra Set or Pointion Set Length Arrary, then
|
| 150 | generate the Huffman code mapping for them.
|
| 151 |
|
| 152 | @param Sd The global scratch data.
|
| 153 | @param nn The number of symbols.
|
| 154 | @param nbit The number of bits needed to represent nn.
|
| 155 | @param Special The special symbol that needs to be taken care of.
|
| 156 |
|
| 157 | @retval 0 OK.
|
| 158 | @retval BAD_TABLE Table is corrupted.
|
| 159 |
|
| 160 | **/
|
| 161 | UINT16
|
| 162 | ReadPTLen (
|
| 163 | IN SCRATCH_DATA *Sd,
|
| 164 | IN UINT16 nn,
|
| 165 | IN UINT16 nbit,
|
| 166 | IN UINT16 Special
|
| 167 | );
|
| 168 |
|
| 169 | /**
|
| 170 | Reads code lengths for Char&Len Set.
|
| 171 |
|
| 172 | Read in and decode the Char&Len Set Code Length Array, then
|
| 173 | generate the Huffman Code mapping table for the Char&Len Set.
|
| 174 |
|
| 175 | @param Sd The global scratch data.
|
| 176 |
|
| 177 | **/
|
| 178 | VOID
|
| 179 | ReadCLen (
|
| 180 | SCRATCH_DATA *Sd
|
| 181 | );
|
| 182 |
|
| 183 | /**
|
| 184 | Decode a character/length value.
|
| 185 |
|
| 186 | Read one value from mBitBuf, Get one code from mBitBuf. If it is at block boundary, generates
|
| 187 | Huffman code mapping table for Extra Set, Code&Len Set and
|
| 188 | Position Set.
|
| 189 |
|
| 190 | @param Sd The global scratch data.
|
| 191 |
|
| 192 | @return The value decoded.
|
| 193 |
|
| 194 | **/
|
| 195 | UINT16
|
| 196 | DecodeC (
|
| 197 | SCRATCH_DATA *Sd
|
| 198 | );
|
| 199 |
|
| 200 | /**
|
| 201 | Decode the source data and put the resulting data into the destination buffer.
|
| 202 |
|
| 203 | @param Sd The global scratch data.
|
| 204 |
|
| 205 | **/
|
| 206 | VOID
|
| 207 | Decode (
|
| 208 | SCRATCH_DATA *Sd
|
| 209 | );
|
| 210 |
|
| 211 | #endif
|