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