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