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