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