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