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