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