]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLibInternals.h
Updated headers to follow coding standard
[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
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
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 EFI 1.1 de/compression algorithm, mPBit = 4\r
67 /// For Tiano de/compression algorithm, mPBit = 5\r
68 ///\r
69 UINT8 mPBit;\r
70} SCRATCH_DATA;\r
71\r
72/**\r
73 Read NumOfBit of bits from source into mBitBuf\r
74\r
75 Shift mBitBuf NumOfBits left. Read in NumOfBits of bits from source.\r
76\r
77 @param Sd The global scratch data\r
78 @param NumOfBits The number of bits to shift and read.\r
79\r
80**/\r
81VOID\r
82FillBuf (\r
83 IN SCRATCH_DATA *Sd,\r
84 IN UINT16 NumOfBits\r
85 );\r
86\r
87/**\r
88 Get NumOfBits of bits out from mBitBuf\r
89\r
8693ca5d 90 Get NumOfBits of bits out from mBitBuf. Fill mBitBuf with subsequent\r
91 NumOfBits of bits from source. Returns NumOfBits of bits that are\r
e1f414b6 92 popped out.\r
93\r
94 @param Sd The global scratch data.\r
95 @param NumOfBits The number of bits to pop and read.\r
96\r
97 @return The bits that are popped out.\r
98\r
99**/\r
100UINT32\r
101GetBits (\r
102 IN SCRATCH_DATA *Sd,\r
103 IN UINT16 NumOfBits\r
104 );\r
105\r
106/**\r
107 Creates Huffman Code mapping table according to code length array.\r
108\r
8693ca5d 109 Creates Huffman Code mapping table for Extra Set, Char&Len Set\r
e1f414b6 110 and Position Set according to code length array.\r
111\r
112 @param Sd The global scratch data\r
113 @param NumOfChar 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
116 @param Table The table\r
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
e1f414b6 136 @param Sd the global scratch data\r
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
149 Read in the Extra Set or Pointion Set Length Arrary, then\r
150 generate the Huffman code mapping for them.\r
151\r
152 @param Sd The global scratch data.\r
153 @param nn Number of symbols.\r
154 @param nbit Number of bits needed to represent nn.\r
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
175 @param Sd the global scratch data\r
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
203 Decode the source data and put the resulting data into the destination buffer.\r
8693ca5d 204\r
e1f414b6 205 @param Sd The global scratch data\r
206\r
207**/\r
208VOID\r
209Decode (\r
210 SCRATCH_DATA *Sd\r
211 );\r
212\r
213#endif\r