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