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