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