]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Sample/Tools/Source/Common/Decompress.c
Update the copyright notice format
[mirror_edk2.git] / EdkCompatibilityPkg / Sample / Tools / Source / Common / Decompress.c
CommitLineData
3eb9473e 1/*++\r
2\r
4b1e1121
HT
3Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>\r
4This program and the accompanying materials \r
3eb9473e 5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 Decompress.c\r
15\r
16Abstract:\r
17\r
18 Decompressor. Algorithm Ported from OPSD code (Decomp.asm)\r
19 \r
20--*/\r
21\r
22#include "TianoCommon.h"\r
23\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 UINT8_MAX 0xff\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
80STATIC\r
81VOID\r
82FillBuf (\r
83 IN SCRATCH_DATA *Sd,\r
84 IN UINT16 NumOfBits\r
85 )\r
86/*++\r
87\r
88Routine Description:\r
89\r
90 Shift mBitBuf NumOfBits left. Read in NumOfBits of bits from source.\r
91\r
92Arguments:\r
93\r
94 Sd - The global scratch data\r
95 NumOfBits - The number of bits to shift and read.\r
96\r
97Returns: (VOID)\r
98\r
99--*/\r
100{\r
101 Sd->mBitBuf = (UINT32) (Sd->mBitBuf << NumOfBits);\r
102\r
103 while (NumOfBits > Sd->mBitCount) {\r
104\r
105 Sd->mBitBuf |= (UINT32) (Sd->mSubBitBuf << (NumOfBits = (UINT16) (NumOfBits - Sd->mBitCount)));\r
106\r
107 if (Sd->mCompSize > 0) {\r
108 //\r
109 // Get 1 byte into SubBitBuf\r
110 //\r
111 Sd->mCompSize--;\r
112 Sd->mSubBitBuf = 0;\r
113 Sd->mSubBitBuf = Sd->mSrcBase[Sd->mInBuf++];\r
114 Sd->mBitCount = 8;\r
115\r
116 } else {\r
117 //\r
118 // No more bits from the source, just pad zero bit.\r
119 //\r
120 Sd->mSubBitBuf = 0;\r
121 Sd->mBitCount = 8;\r
122\r
123 }\r
124 }\r
125\r
126 Sd->mBitCount = (UINT16) (Sd->mBitCount - NumOfBits);\r
127 Sd->mBitBuf |= Sd->mSubBitBuf >> Sd->mBitCount;\r
128}\r
129\r
130STATIC\r
131UINT32\r
132GetBits (\r
133 IN SCRATCH_DATA *Sd,\r
134 IN UINT16 NumOfBits\r
135 )\r
136/*++\r
137\r
138Routine Description:\r
139\r
140 Get NumOfBits of bits out from mBitBuf. Fill mBitBuf with subsequent \r
141 NumOfBits of bits from source. Returns NumOfBits of bits that are \r
142 popped out.\r
143\r
144Arguments:\r
145\r
146 Sd - The global scratch data.\r
147 NumOfBits - The number of bits to pop and read.\r
148\r
149Returns:\r
150\r
151 The bits that are popped out.\r
152\r
153--*/\r
154{\r
155 UINT32 OutBits;\r
156\r
157 OutBits = (UINT32) (Sd->mBitBuf >> (BITBUFSIZ - NumOfBits));\r
158\r
159 FillBuf (Sd, NumOfBits);\r
160\r
161 return OutBits;\r
162}\r
163\r
164STATIC\r
165UINT16\r
166MakeTable (\r
167 IN SCRATCH_DATA *Sd,\r
168 IN UINT16 NumOfChar,\r
169 IN UINT8 *BitLen,\r
170 IN UINT16 TableBits,\r
171 OUT UINT16 *Table\r
172 )\r
173/*++\r
174\r
175Routine Description:\r
176\r
177 Creates Huffman Code mapping table according to code length array.\r
178\r
179Arguments:\r
180\r
181 Sd - The global scratch data\r
182 NumOfChar - Number of symbols in the symbol set\r
183 BitLen - Code length array\r
184 TableBits - The width of the mapping table\r
185 Table - The table\r
186 \r
187Returns:\r
188 \r
189 0 - OK.\r
190 BAD_TABLE - The table is corrupted.\r
191\r
192--*/\r
193{\r
194 UINT16 Count[17];\r
195 UINT16 Weight[17];\r
196 UINT16 Start[18];\r
197 UINT16 *Pointer;\r
198 UINT16 Index3;\r
199 UINT16 Index;\r
200 UINT16 Len;\r
201 UINT16 Char;\r
202 UINT16 JuBits;\r
203 UINT16 Avail;\r
204 UINT16 NextCode;\r
205 UINT16 Mask;\r
206\r
207 for (Index = 1; Index <= 16; Index++) {\r
208 Count[Index] = 0;\r
209 }\r
210\r
211 for (Index = 0; Index < NumOfChar; Index++) {\r
212 Count[BitLen[Index]]++;\r
213 }\r
214\r
215 Start[1] = 0;\r
216\r
217 for (Index = 1; Index <= 16; Index++) {\r
218 Start[Index + 1] = (UINT16) (Start[Index] + (Count[Index] << (16 - Index)));\r
219 }\r
220\r
221 if (Start[17] != 0) {\r
222 /*(1U << 16)*/\r
223 return (UINT16) BAD_TABLE;\r
224 }\r
225\r
226 JuBits = (UINT16) (16 - TableBits);\r
227\r
228 for (Index = 1; Index <= TableBits; Index++) {\r
229 Start[Index] >>= JuBits;\r
230 Weight[Index] = (UINT16) (1U << (TableBits - Index));\r
231 }\r
232\r
233 while (Index <= 16) {\r
234 Weight[Index++] = (UINT16) (1U << (16 - Index));\r
235 }\r
236\r
237 Index = (UINT16) (Start[TableBits + 1] >> JuBits);\r
238\r
239 if (Index != 0) {\r
240 Index3 = (UINT16) (1U << TableBits);\r
241 while (Index != Index3) {\r
242 Table[Index++] = 0;\r
243 }\r
244 }\r
245\r
246 Avail = NumOfChar;\r
247 Mask = (UINT16) (1U << (15 - TableBits));\r
248\r
249 for (Char = 0; Char < NumOfChar; Char++) {\r
250\r
251 Len = BitLen[Char];\r
252 if (Len == 0) {\r
253 continue;\r
254 }\r
255\r
256 NextCode = (UINT16) (Start[Len] + Weight[Len]);\r
257\r
258 if (Len <= TableBits) {\r
259\r
260 for (Index = Start[Len]; Index < NextCode; Index++) {\r
261 Table[Index] = Char;\r
262 }\r
263\r
264 } else {\r
265\r
266 Index3 = Start[Len];\r
267 Pointer = &Table[Index3 >> JuBits];\r
268 Index = (UINT16) (Len - TableBits);\r
269\r
270 while (Index != 0) {\r
271 if (*Pointer == 0) {\r
272 Sd->mRight[Avail] = Sd->mLeft[Avail] = 0;\r
273 *Pointer = Avail++;\r
274 }\r
275\r
276 if (Index3 & Mask) {\r
277 Pointer = &Sd->mRight[*Pointer];\r
278 } else {\r
279 Pointer = &Sd->mLeft[*Pointer];\r
280 }\r
281\r
282 Index3 <<= 1;\r
283 Index--;\r
284 }\r
285\r
286 *Pointer = Char;\r
287\r
288 }\r
289\r
290 Start[Len] = NextCode;\r
291 }\r
292 //\r
293 // Succeeds\r
294 //\r
295 return 0;\r
296}\r
297\r
298STATIC\r
299UINT32\r
300DecodeP (\r
301 IN SCRATCH_DATA *Sd\r
302 )\r
303/*++\r
304\r
305Routine Description:\r
306\r
307 Decodes a position value.\r
308\r
309Arguments:\r
310\r
311 Sd - the global scratch data\r
312\r
313Returns:\r
314\r
315 The position value decoded.\r
316\r
317--*/\r
318{\r
319 UINT16 Val;\r
320 UINT32 Mask;\r
321 UINT32 Pos;\r
322\r
323 Val = Sd->mPTTable[Sd->mBitBuf >> (BITBUFSIZ - 8)];\r
324\r
325 if (Val >= MAXNP) {\r
326 Mask = 1U << (BITBUFSIZ - 1 - 8);\r
327\r
328 do {\r
329\r
330 if (Sd->mBitBuf & Mask) {\r
331 Val = Sd->mRight[Val];\r
332 } else {\r
333 Val = Sd->mLeft[Val];\r
334 }\r
335\r
336 Mask >>= 1;\r
337 } while (Val >= MAXNP);\r
338 }\r
339 //\r
340 // Advance what we have read\r
341 //\r
342 FillBuf (Sd, Sd->mPTLen[Val]);\r
343\r
344 Pos = Val;\r
345 if (Val > 1) {\r
346 Pos = (UINT32) ((1U << (Val - 1)) + GetBits (Sd, (UINT16) (Val - 1)));\r
347 }\r
348\r
349 return Pos;\r
350}\r
351\r
352STATIC\r
353UINT16\r
354ReadPTLen (\r
355 IN SCRATCH_DATA *Sd,\r
356 IN UINT16 nn,\r
357 IN UINT16 nbit,\r
358 IN UINT16 Special\r
359 )\r
360/*++\r
361\r
362Routine Description:\r
363\r
364 Reads code lengths for the Extra Set or the Position Set\r
365\r
366Arguments:\r
367\r
368 Sd - The global scratch data\r
369 nn - Number of symbols\r
370 nbit - Number of bits needed to represent nn\r
371 Special - The special symbol that needs to be taken care of \r
372\r
373Returns:\r
374\r
375 0 - OK.\r
376 BAD_TABLE - Table is corrupted.\r
377\r
378--*/\r
379{\r
380 UINT16 Number;\r
381 UINT16 CharC;\r
382 UINT16 Index;\r
383 UINT32 Mask;\r
384\r
385 Number = (UINT16) GetBits (Sd, nbit);\r
386\r
387 if (Number == 0) {\r
388 CharC = (UINT16) GetBits (Sd, nbit);\r
389\r
390 for (Index = 0; Index < 256; Index++) {\r
391 Sd->mPTTable[Index] = CharC;\r
392 }\r
393\r
394 for (Index = 0; Index < nn; Index++) {\r
395 Sd->mPTLen[Index] = 0;\r
396 }\r
397\r
398 return 0;\r
399 }\r
400\r
401 Index = 0;\r
402\r
403 while (Index < Number) {\r
404\r
405 CharC = (UINT16) (Sd->mBitBuf >> (BITBUFSIZ - 3));\r
406\r
407 if (CharC == 7) {\r
408 Mask = 1U << (BITBUFSIZ - 1 - 3);\r
409 while (Mask & Sd->mBitBuf) {\r
410 Mask >>= 1;\r
411 CharC += 1;\r
412 }\r
413 }\r
414\r
415 FillBuf (Sd, (UINT16) ((CharC < 7) ? 3 : CharC - 3));\r
416\r
417 Sd->mPTLen[Index++] = (UINT8) CharC;\r
418\r
419 if (Index == Special) {\r
420 CharC = (UINT16) GetBits (Sd, 2);\r
421 while ((INT16) (--CharC) >= 0) {\r
422 Sd->mPTLen[Index++] = 0;\r
423 }\r
424 }\r
425 }\r
426\r
427 while (Index < nn) {\r
428 Sd->mPTLen[Index++] = 0;\r
429 }\r
430\r
431 return MakeTable (Sd, nn, Sd->mPTLen, 8, Sd->mPTTable);\r
432}\r
433\r
434STATIC\r
435VOID\r
436ReadCLen (\r
437 SCRATCH_DATA *Sd\r
438 )\r
439/*++\r
440\r
441Routine Description:\r
442\r
443 Reads code lengths for Char&Len Set.\r
444\r
445Arguments:\r
446\r
447 Sd - the global scratch data\r
448\r
449Returns: (VOID)\r
450\r
451--*/\r
452{\r
453 UINT16 Number;\r
454 UINT16 CharC;\r
455 UINT16 Index;\r
456 UINT32 Mask;\r
457\r
458 Number = (UINT16) GetBits (Sd, CBIT);\r
459\r
460 if (Number == 0) {\r
461 CharC = (UINT16) GetBits (Sd, CBIT);\r
462\r
463 for (Index = 0; Index < NC; Index++) {\r
464 Sd->mCLen[Index] = 0;\r
465 }\r
466\r
467 for (Index = 0; Index < 4096; Index++) {\r
468 Sd->mCTable[Index] = CharC;\r
469 }\r
470\r
471 return ;\r
472 }\r
473\r
474 Index = 0;\r
475 while (Index < Number) {\r
476\r
477 CharC = Sd->mPTTable[Sd->mBitBuf >> (BITBUFSIZ - 8)];\r
478 if (CharC >= NT) {\r
479 Mask = 1U << (BITBUFSIZ - 1 - 8);\r
480\r
481 do {\r
482\r
483 if (Mask & Sd->mBitBuf) {\r
484 CharC = Sd->mRight[CharC];\r
485 } else {\r
486 CharC = Sd->mLeft[CharC];\r
487 }\r
488\r
489 Mask >>= 1;\r
490\r
491 } while (CharC >= NT);\r
492 }\r
493 //\r
494 // Advance what we have read\r
495 //\r
496 FillBuf (Sd, Sd->mPTLen[CharC]);\r
497\r
498 if (CharC <= 2) {\r
499\r
500 if (CharC == 0) {\r
501 CharC = 1;\r
502 } else if (CharC == 1) {\r
503 CharC = (UINT16) (GetBits (Sd, 4) + 3);\r
504 } else if (CharC == 2) {\r
505 CharC = (UINT16) (GetBits (Sd, CBIT) + 20);\r
506 }\r
507\r
508 while ((INT16) (--CharC) >= 0) {\r
509 Sd->mCLen[Index++] = 0;\r
510 }\r
511\r
512 } else {\r
513\r
514 Sd->mCLen[Index++] = (UINT8) (CharC - 2);\r
515\r
516 }\r
517 }\r
518\r
519 while (Index < NC) {\r
520 Sd->mCLen[Index++] = 0;\r
521 }\r
522\r
523 MakeTable (Sd, NC, Sd->mCLen, 12, Sd->mCTable);\r
524\r
525 return ;\r
526}\r
527\r
528STATIC\r
529UINT16\r
530DecodeC (\r
531 SCRATCH_DATA *Sd\r
532 )\r
533/*++\r
534\r
535Routine Description:\r
536\r
537 Decode a character/length value.\r
538\r
539Arguments:\r
540\r
541 Sd - The global scratch data.\r
542\r
543Returns:\r
544\r
545 The value decoded.\r
546\r
547--*/\r
548{\r
549 UINT16 Index2;\r
550 UINT32 Mask;\r
551\r
552 if (Sd->mBlockSize == 0) {\r
553 //\r
554 // Starting a new block\r
555 //\r
556 Sd->mBlockSize = (UINT16) GetBits (Sd, 16);\r
557 Sd->mBadTableFlag = ReadPTLen (Sd, NT, TBIT, 3);\r
558 if (Sd->mBadTableFlag != 0) {\r
559 return 0;\r
560 }\r
561\r
562 ReadCLen (Sd);\r
563\r
564 Sd->mBadTableFlag = ReadPTLen (Sd, MAXNP, Sd->mPBit, (UINT16) (-1));\r
565 if (Sd->mBadTableFlag != 0) {\r
566 return 0;\r
567 }\r
568 }\r
569\r
570 Sd->mBlockSize--;\r
571 Index2 = Sd->mCTable[Sd->mBitBuf >> (BITBUFSIZ - 12)];\r
572\r
573 if (Index2 >= NC) {\r
574 Mask = 1U << (BITBUFSIZ - 1 - 12);\r
575\r
576 do {\r
577 if (Sd->mBitBuf & Mask) {\r
578 Index2 = Sd->mRight[Index2];\r
579 } else {\r
580 Index2 = Sd->mLeft[Index2];\r
581 }\r
582\r
583 Mask >>= 1;\r
584 } while (Index2 >= NC);\r
585 }\r
586 //\r
587 // Advance what we have read\r
588 //\r
589 FillBuf (Sd, Sd->mCLen[Index2]);\r
590\r
591 return Index2;\r
592}\r
593\r
594STATIC\r
595VOID\r
596Decode (\r
597 SCRATCH_DATA *Sd\r
598 )\r
599/*++\r
600\r
601Routine Description:\r
602\r
603 Decode the source data and put the resulting data into the destination buffer.\r
604\r
605Arguments:\r
606\r
607 Sd - The global scratch data\r
608\r
609Returns: (VOID)\r
610\r
611 --*/\r
612{\r
613 UINT16 BytesRemain;\r
614 UINT32 DataIdx;\r
615 UINT16 CharC;\r
616\r
617 BytesRemain = (UINT16) (-1);\r
618\r
619 DataIdx = 0;\r
620\r
621 for (;;) {\r
622 CharC = DecodeC (Sd);\r
623 if (Sd->mBadTableFlag != 0) {\r
624 return ;\r
625 }\r
626\r
627 if (CharC < 256) {\r
628 //\r
629 // Process an Original character\r
630 //\r
631 if (Sd->mOutBuf >= Sd->mOrigSize) {\r
632 return ;\r
633 } else {\r
634 Sd->mDstBase[Sd->mOutBuf++] = (UINT8) CharC;\r
635 }\r
636\r
637 } else {\r
638 //\r
639 // Process a Pointer\r
640 //\r
641 CharC = (UINT16) (CharC - (UINT8_MAX + 1 - THRESHOLD));\r
642\r
643 BytesRemain = CharC;\r
644\r
645 DataIdx = Sd->mOutBuf - DecodeP (Sd) - 1;\r
646\r
647 BytesRemain--;\r
648 while ((INT16) (BytesRemain) >= 0) {\r
649 Sd->mDstBase[Sd->mOutBuf++] = Sd->mDstBase[DataIdx++];\r
650 if (Sd->mOutBuf >= Sd->mOrigSize) {\r
651 return ;\r
652 }\r
653\r
654 BytesRemain--;\r
655 }\r
656 }\r
657 }\r
658\r
659 return ;\r
660}\r
661\r
662EFI_STATUS\r
663GetInfo (\r
664 IN VOID *Source,\r
665 IN UINT32 SrcSize,\r
666 OUT UINT32 *DstSize,\r
667 OUT UINT32 *ScratchSize\r
668 )\r
669/*++\r
670\r
671Routine Description:\r
672\r
673 The internal implementation of *_DECOMPRESS_PROTOCOL.GetInfo().\r
674\r
675Arguments:\r
676\r
677 Source - The source buffer containing the compressed data.\r
678 SrcSize - The size of source buffer\r
679 DstSize - The size of destination buffer.\r
680 ScratchSize - The size of scratch buffer.\r
681\r
682Returns:\r
683\r
684 EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved.\r
685 EFI_INVALID_PARAMETER - The source data is corrupted\r
686\r
687--*/\r
688{\r
689 UINT8 *Src;\r
690\r
691 *ScratchSize = sizeof (SCRATCH_DATA);\r
692\r
693 Src = Source;\r
694 if (SrcSize < 8) {\r
695 return EFI_INVALID_PARAMETER;\r
696 }\r
697\r
698 *DstSize = Src[4] + (Src[5] << 8) + (Src[6] << 16) + (Src[7] << 24);\r
699 return EFI_SUCCESS;\r
700}\r
701\r
702EFI_STATUS\r
703Decompress (\r
704 IN VOID *Source,\r
705 IN UINT32 SrcSize,\r
706 IN OUT VOID *Destination,\r
707 IN UINT32 DstSize,\r
708 IN OUT VOID *Scratch,\r
709 IN UINT32 ScratchSize,\r
710 IN UINT8 Version\r
711 )\r
712/*++\r
713\r
714Routine Description:\r
715\r
716 The internal implementation of *_DECOMPRESS_PROTOCOL.Decompress().\r
717\r
718Arguments:\r
719\r
720 Source - The source buffer containing the compressed data.\r
721 SrcSize - The size of source buffer\r
722 Destination - The destination buffer to store the decompressed data\r
723 DstSize - The size of destination buffer.\r
724 Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.\r
725 ScratchSize - The size of scratch buffer.\r
726 Version - The version of de/compression algorithm.\r
727 Version 1 for EFI 1.1 de/compression algorithm.\r
728 Version 2 for Tiano de/compression algorithm.\r
729\r
730Returns:\r
731\r
732 EFI_SUCCESS - Decompression is successfull\r
733 EFI_INVALID_PARAMETER - The source data is corrupted\r
734\r
735--*/\r
736{\r
737 UINT32 Index;\r
738 UINT32 CompSize;\r
739 UINT32 OrigSize;\r
740 EFI_STATUS Status;\r
741 SCRATCH_DATA *Sd;\r
742 UINT8 *Src;\r
743 UINT8 *Dst;\r
744\r
745 Status = EFI_SUCCESS;\r
746 Src = Source;\r
747 Dst = Destination;\r
748\r
749 if (ScratchSize < sizeof (SCRATCH_DATA)) {\r
750 return EFI_INVALID_PARAMETER;\r
751 }\r
752\r
753 Sd = (SCRATCH_DATA *) Scratch;\r
754\r
755 if (SrcSize < 8) {\r
756 return EFI_INVALID_PARAMETER;\r
757 }\r
758\r
759 CompSize = Src[0] + (Src[1] << 8) + (Src[2] << 16) + (Src[3] << 24);\r
760 OrigSize = Src[4] + (Src[5] << 8) + (Src[6] << 16) + (Src[7] << 24);\r
761\r
762 //\r
763 // If compressed file size is 0, return\r
764 //\r
765 if (OrigSize == 0) {\r
766 return Status;\r
767 }\r
768\r
769 if (SrcSize < CompSize + 8) {\r
770 return EFI_INVALID_PARAMETER;\r
771 }\r
772\r
773 if (DstSize != OrigSize) {\r
774 return EFI_INVALID_PARAMETER;\r
775 }\r
776\r
777 Src = Src + 8;\r
778\r
779 for (Index = 0; Index < sizeof (SCRATCH_DATA); Index++) {\r
780 ((UINT8 *) Sd)[Index] = 0;\r
781 }\r
782 //\r
783 // The length of the field 'Position Set Code Length Array Size' in Block Header.\r
784 // For EFI 1.1 de/compression algorithm(Version 1), mPBit = 4\r
785 // For Tiano de/compression algorithm(Version 2), mPBit = 5\r
786 //\r
787 switch (Version) {\r
788 case 1:\r
789 Sd->mPBit = 4;\r
790 break;\r
791\r
792 case 2:\r
793 Sd->mPBit = 5;\r
794 break;\r
795\r
796 default:\r
797 //\r
798 // Currently, only have 2 versions\r
799 //\r
800 return EFI_INVALID_PARAMETER;\r
801 }\r
802\r
803 Sd->mSrcBase = Src;\r
804 Sd->mDstBase = Dst;\r
805 Sd->mCompSize = CompSize;\r
806 Sd->mOrigSize = OrigSize;\r
807\r
808 //\r
809 // Fill the first BITBUFSIZ bits\r
810 //\r
811 FillBuf (Sd, BITBUFSIZ);\r
812\r
813 //\r
814 // Decompress it\r
815 //\r
816 Decode (Sd);\r
817\r
818 if (Sd->mBadTableFlag != 0) {\r
819 //\r
820 // Something wrong with the source\r
821 //\r
822 Status = EFI_INVALID_PARAMETER;\r
823 }\r
824\r
825 return Status;\r
826}\r
827\r
828EFI_STATUS\r
829EFIAPI\r
830EfiGetInfo (\r
831 IN VOID *Source,\r
832 IN UINT32 SrcSize,\r
833 OUT UINT32 *DstSize,\r
834 OUT UINT32 *ScratchSize\r
835 )\r
836/*++\r
837\r
838Routine Description:\r
839\r
840 The implementation is same as that of EFI_DECOMPRESS_PROTOCOL.GetInfo().\r
841\r
842Arguments:\r
843\r
844 This - The protocol instance pointer\r
845 Source - The source buffer containing the compressed data.\r
846 SrcSize - The size of source buffer\r
847 DstSize - The size of destination buffer.\r
848 ScratchSize - The size of scratch buffer.\r
849\r
850Returns:\r
851\r
852 EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved.\r
853 EFI_INVALID_PARAMETER - The source data is corrupted\r
854\r
855--*/\r
856{\r
857 return GetInfo (\r
858 Source,\r
859 SrcSize,\r
860 DstSize,\r
861 ScratchSize\r
862 );\r
863}\r
864\r
865EFI_STATUS\r
866EFIAPI\r
867EfiDecompress (\r
868 IN VOID *Source,\r
869 IN UINT32 SrcSize,\r
870 IN OUT VOID *Destination,\r
871 IN UINT32 DstSize,\r
872 IN OUT VOID *Scratch,\r
873 IN UINT32 ScratchSize\r
874 )\r
875/*++\r
876\r
877Routine Description:\r
878\r
879 The implementation is same as that of EFI_DECOMPRESS_PROTOCOL.Decompress().\r
880\r
881Arguments:\r
882\r
883 This - The protocol instance pointer\r
884 Source - The source buffer containing the compressed data.\r
885 SrcSize - The size of source buffer\r
886 Destination - The destination buffer to store the decompressed data\r
887 DstSize - The size of destination buffer.\r
888 Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.\r
889 ScratchSize - The size of scratch buffer.\r
890\r
891Returns:\r
892\r
893 EFI_SUCCESS - Decompression is successfull\r
894 EFI_INVALID_PARAMETER - The source data is corrupted\r
895\r
896--*/\r
897{\r
898 //\r
899 // For EFI 1.1 de/compression algorithm, the version is 1.\r
900 //\r
901 return Decompress (\r
902 Source,\r
903 SrcSize,\r
904 Destination,\r
905 DstSize,\r
906 Scratch,\r
907 ScratchSize,\r
908 1\r
909 );\r
910}\r
911\r
912EFI_STATUS\r
913EFIAPI\r
914TianoGetInfo (\r
915 IN VOID *Source,\r
916 IN UINT32 SrcSize,\r
917 OUT UINT32 *DstSize,\r
918 OUT UINT32 *ScratchSize\r
919 )\r
920/*++\r
921\r
922Routine Description:\r
923\r
924 The implementation is same as that of EFI_TIANO_DECOMPRESS_PROTOCOL.GetInfo().\r
925\r
926Arguments:\r
927\r
928 This - The protocol instance pointer\r
929 Source - The source buffer containing the compressed data.\r
930 SrcSize - The size of source buffer\r
931 DstSize - The size of destination buffer.\r
932 ScratchSize - The size of scratch buffer.\r
933\r
934Returns:\r
935\r
936 EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved.\r
937 EFI_INVALID_PARAMETER - The source data is corrupted\r
938\r
939--*/\r
940{\r
941 return GetInfo (\r
942 Source,\r
943 SrcSize,\r
944 DstSize,\r
945 ScratchSize\r
946 );\r
947}\r
948\r
949EFI_STATUS\r
950EFIAPI\r
951TianoDecompress (\r
952 IN VOID *Source,\r
953 IN UINT32 SrcSize,\r
954 IN OUT VOID *Destination,\r
955 IN UINT32 DstSize,\r
956 IN OUT VOID *Scratch,\r
957 IN UINT32 ScratchSize\r
958 )\r
959/*++\r
960\r
961Routine Description:\r
962\r
963 The implementation is same as that of EFI_TIANO_DECOMPRESS_PROTOCOL.Decompress().\r
964\r
965Arguments:\r
966\r
967 This - The protocol instance pointer\r
968 Source - The source buffer containing the compressed data.\r
969 SrcSize - The size of source buffer\r
970 Destination - The destination buffer to store the decompressed data\r
971 DstSize - The size of destination buffer.\r
972 Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.\r
973 ScratchSize - The size of scratch buffer.\r
974\r
975Returns:\r
976\r
977 EFI_SUCCESS - Decompression is successfull\r
978 EFI_INVALID_PARAMETER - The source data is corrupted\r
979\r
980--*/\r
981{\r
982 //\r
983 // For Tiano de/compression algorithm, the version is 2.\r
984 //\r
985 return Decompress (\r
986 Source,\r
987 SrcSize,\r
988 Destination,\r
989 DstSize,\r
990 Scratch,\r
991 ScratchSize,\r
992 2\r
993 );\r
994}\r
995\r