]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLibInternals.h
PI 1.1 SMM Feature Check-in
[mirror_edk2.git] / MdePkg / Library / BaseUefiDecompressLib / BaseUefiDecompressLibInternals.h
... / ...
CommitLineData
1/** @file\r
2 Internal data structure defintions for Base UEFI Decompress Libary.\r
3\r
4 Copyright (c) 2006 - 2008, 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**/\r
14\r
15#ifndef __BASE_UEFI_DECOMPRESS_LIB_INTERNALS_H__\r
16#define __BASE_UEFI_DECOMPRESS_LIB_INTERNALS_H__\r
17\r
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
43 UINT8 *mSrcBase; // Starting address of compressed data\r
44 UINT8 *mDstBase; // Starting address of decompressed data\r
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
66 /// For UEFI 2.0 de/compression algorithm, mPBit = 4\r
67 ///\r
68 UINT8 mPBit;\r
69} SCRATCH_DATA;\r
70\r
71/**\r
72 Read NumOfBit of bits from source into mBitBuf.\r
73\r
74 Shift mBitBuf NumOfBits left. Read in NumOfBits of bits from source.\r
75\r
76 @param Sd The global scratch data\r
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
87 Get NumOfBits of bits out from mBitBuf.\r
88\r
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
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
108 Creates Huffman Code mapping table for Extra Set, Char&Len Set\r
109 and Position Set according to code length array.\r
110\r
111 @param Sd The global scratch data\r
112 @param NumOfChar Number of symbols in the symbol set\r
113 @param BitLen Code length array\r
114 @param TableBits The width of the mapping table\r
115 @param Table The table to be created.\r
116\r
117 @retval 0 OK.\r
118 @retval BAD_TABLE The table is corrupted.\r
119\r
120**/\r
121UINT16\r
122MakeTable (\r
123 IN SCRATCH_DATA *Sd,\r
124 IN UINT16 NumOfChar,\r
125 IN UINT8 *BitLen,\r
126 IN UINT16 TableBits,\r
127 OUT UINT16 *Table\r
128 );\r
129\r
130/**\r
131 Decodes a position value.\r
132\r
133 Get a position value according to Position Huffman Table.\r
134\r
135 @param Sd the global scratch data\r
136\r
137 @return The position value decoded.\r
138\r
139**/\r
140UINT32\r
141DecodeP (\r
142 IN SCRATCH_DATA *Sd\r
143 );\r
144\r
145/**\r
146 Reads code lengths for the Extra Set or the Position Set.\r
147\r
148 Read in the Extra Set or Pointion Set Length Arrary, then\r
149 generate the Huffman code mapping for them.\r
150\r
151 @param Sd The global scratch data.\r
152 @param nn Number of symbols.\r
153 @param nbit Number of bits needed to represent nn.\r
154 @param Special The special symbol that needs to be taken care of.\r
155\r
156 @retval 0 OK.\r
157 @retval BAD_TABLE Table is corrupted.\r
158\r
159**/\r
160UINT16\r
161ReadPTLen (\r
162 IN SCRATCH_DATA *Sd,\r
163 IN UINT16 nn,\r
164 IN UINT16 nbit,\r
165 IN UINT16 Special\r
166 );\r
167\r
168/**\r
169 Reads code lengths for Char&Len Set.\r
170\r
171 Read in and decode the Char&Len Set Code Length Array, then\r
172 generate the Huffman Code mapping table for the Char&Len Set.\r
173\r
174 @param Sd the global scratch data\r
175\r
176**/\r
177VOID\r
178ReadCLen (\r
179 SCRATCH_DATA *Sd\r
180 );\r
181\r
182/**\r
183 Decode a character/length value.\r
184\r
185 Read one value from mBitBuf, Get one code from mBitBuf. If it is at block boundary, generates\r
186 Huffman code mapping table for Extra Set, Code&Len Set and\r
187 Position Set.\r
188\r
189 @param Sd The global scratch data.\r
190\r
191 @return The value decoded.\r
192\r
193**/\r
194UINT16\r
195DecodeC (\r
196 SCRATCH_DATA *Sd\r
197 );\r
198\r
199/**\r
200 Decode the source data and put the resulting data into the destination buffer.\r
201\r
202 @param Sd The global scratch data\r
203\r
204**/\r
205VOID\r
206Decode (\r
207 SCRATCH_DATA *Sd\r
208 );\r
209\r
210#endif\r