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