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