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