]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLibInternals.h
2 Internal data structure defintions for Base UEFI Decompress Library.
4 Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #ifndef __BASE_UEFI_DECOMPRESS_LIB_INTERNALS_H__
10 #define __BASE_UEFI_DECOMPRESS_LIB_INTERNALS_H__
13 #include <Library/BaseLib.h>
14 #include <Library/DebugLib.h>
15 #include <Library/BaseMemoryLib.h>
16 #include <Library/UefiDecompressLib.h>
18 // Decompression algorithm begins here
27 // C: Char&Len Set; P: Position Set; T: exTra Set
29 #define NC (0xff + MAXMATCH + 2 - THRESHOLD)
33 #define MAXNP ((1U << MAXPBIT) - 1)
34 #define NT (CODE_BIT + 3)
42 UINT8
*mSrcBase
; // The starting address of compressed data
43 UINT8
*mDstBase
; // The starting address of decompressed data
56 UINT16 mLeft
[2 * NC
- 1];
57 UINT16 mRight
[2 * NC
- 1];
64 /// The length of the field 'Position Set Code Length Array Size' in Block Header.
65 /// For UEFI 2.0 de/compression algorithm, mPBit = 4.
66 /// For Tiano de/compression algorithm, mPBit = 5.
72 Read NumOfBit of bits from source into mBitBuf.
74 Shift mBitBuf NumOfBits left. Read in NumOfBits of bits from source.
76 @param Sd The global scratch data.
77 @param NumOfBits The number of bits to shift and read.
87 Get NumOfBits of bits out from mBitBuf.
89 Get NumOfBits of bits out from mBitBuf. Fill mBitBuf with subsequent
90 NumOfBits of bits from source. Returns NumOfBits of bits that are
93 @param Sd The global scratch data.
94 @param NumOfBits The number of bits to pop and read.
96 @return The bits that are popped out.
106 Creates Huffman Code mapping table according to code length array.
108 Creates Huffman Code mapping table for Extra Set, Char&Len Set
109 and Position Set according to code length array.
110 If TableBits > 16, then ASSERT ().
112 @param Sd The global scratch data.
113 @param NumOfChar The number of symbols in the symbol set.
114 @param BitLen Code length array.
115 @param TableBits The width of the mapping table.
116 @param Table The table to be created.
119 @retval BAD_TABLE The table is corrupted.
132 Decodes a position value.
134 Get a position value according to Position Huffman Table.
136 @param Sd The global scratch data.
138 @return The position value decoded.
147 Reads code lengths for the Extra Set or the Position Set.
149 Read in the Extra Set or Position Set Length Array, then
150 generate the Huffman code mapping for them.
152 @param Sd The global scratch data.
153 @param nn The number of symbols.
154 @param nbit The number of bits needed to represent nn.
155 @param Special The special symbol that needs to be taken care of.
158 @retval BAD_TABLE Table is corrupted.
170 Reads code lengths for Char&Len Set.
172 Read in and decode the Char&Len Set Code Length Array, then
173 generate the Huffman Code mapping table for the Char&Len Set.
175 @param Sd The global scratch data.
184 Decode a character/length value.
186 Read one value from mBitBuf, Get one code from mBitBuf. If it is at block boundary, generates
187 Huffman code mapping table for Extra Set, Code&Len Set and
190 @param Sd The global scratch data.
192 @return The value decoded.
201 Decode the source data and put the resulting data into the destination buffer.
203 @param Sd The global scratch data.
212 Decompresses a compressed source buffer.
214 Extracts decompressed data to its original form.
215 This function is designed so that the decompression algorithm can be implemented
216 without using any memory services. As a result, this function is not allowed to
217 call any memory allocation services in its implementation. It is the caller's
218 responsibility to allocate and free the Destination and Scratch buffers.
219 If the compressed source data specified by Source is successfully decompressed
220 into Destination, then RETURN_SUCCESS is returned. If the compressed source data
221 specified by Source is not in a valid compressed data format,
222 then RETURN_INVALID_PARAMETER is returned.
224 If Source is NULL, then ASSERT().
225 If Destination is NULL, then ASSERT().
226 If the required scratch buffer size > 0 and Scratch is NULL, then ASSERT().
228 @param Source The source buffer containing the compressed data.
229 @param Destination The destination buffer to store the decompressed data.
230 @param Scratch A temporary scratch buffer that is used to perform the decompression.
231 This is an optional parameter that may be NULL if the
232 required scratch buffer size is 0.
233 @param Version 1 for UEFI Decompress algoruthm, 2 for Tiano Decompess algorithm.
235 @retval RETURN_SUCCESS Decompression completed successfully, and
236 the uncompressed buffer is returned in Destination.
237 @retval RETURN_INVALID_PARAMETER
238 The source buffer specified by Source is corrupted
239 (not in a valid compressed format).
242 UefiTianoDecompress (
243 IN CONST VOID
*Source
,
244 IN OUT VOID
*Destination
,
245 IN OUT VOID
*Scratch
,