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