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