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