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