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