]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.c
Reviewed the code comments in the Include/Protocol directory for typos, grammar issue...
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / BaseUefiTianoCustomDecompressLib / BaseUefiTianoCustomDecompressLib.c
1 /**@file
2 UEFI and Custom Decompress Library
3 The function of UefiTianoDecompress() is interface for this module,
4 it will do tiano or uefi decompress with different verison parameter.
5 See EFI specification 1.1 Chapter 17 to get LZ77 compress/decompress.
6
7 Copyright (c) 2006, Intel Corporation
8 All rights reserved. This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
12
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15
16 **/
17
18 #include "BaseUefiTianoCustomDecompressLibInternals.h"
19 #include <Guid/CustomDecompress.h>
20
21 /**
22 Shift mBitBuf NumOfBits left. Read in NumOfBits of bits from source.
23
24 @param Sd The global scratch data
25 @param NumOfBits The number of bits to shift and read.
26 **/
27 VOID
28 FillBuf (
29 IN SCRATCH_DATA *Sd,
30 IN UINT16 NumOfBits
31 )
32 {
33 Sd->mBitBuf = (UINT32) (Sd->mBitBuf << NumOfBits);
34
35 while (NumOfBits > Sd->mBitCount) {
36
37 Sd->mBitBuf |= (UINT32) (Sd->mSubBitBuf << (NumOfBits = (UINT16) (NumOfBits - Sd->mBitCount)));
38
39 if (Sd->mCompSize > 0) {
40 //
41 // Get 1 byte into SubBitBuf
42 //
43 Sd->mCompSize--;
44 Sd->mSubBitBuf = 0;
45 Sd->mSubBitBuf = Sd->mSrcBase[Sd->mInBuf++];
46 Sd->mBitCount = 8;
47
48 } else {
49 //
50 // No more bits from the source, just pad zero bit.
51 //
52 Sd->mSubBitBuf = 0;
53 Sd->mBitCount = 8;
54
55 }
56 }
57
58 Sd->mBitCount = (UINT16) (Sd->mBitCount - NumOfBits);
59 Sd->mBitBuf |= Sd->mSubBitBuf >> Sd->mBitCount;
60 }
61
62 /**
63 Get NumOfBits of bits out from mBitBuf
64
65 Get NumOfBits of bits out from mBitBuf. Fill mBitBuf with subsequent
66 NumOfBits of bits from source. Returns NumOfBits of bits that are
67 popped out.
68
69 @param Sd The global scratch data.
70 @param NumOfBits The number of bits to pop and read.
71
72 @return The bits that are popped out.
73
74 **/
75 UINT32
76 GetBits (
77 IN SCRATCH_DATA *Sd,
78 IN UINT16 NumOfBits
79 )
80 {
81 UINT32 OutBits;
82
83 OutBits = (UINT32) (Sd->mBitBuf >> (BITBUFSIZ - NumOfBits));
84
85 FillBuf (Sd, NumOfBits);
86
87 return OutBits;
88 }
89
90 /**
91 Creates Huffman Code mapping table according to code length array.
92
93 Creates Huffman Code mapping table for Extra Set, Char&Len Set
94 and Position Set according to code length array.
95
96 @param Sd The global scratch data
97 @param NumOfChar Number of symbols in the symbol set
98 @param BitLen Code length array
99 @param TableBits The width of the mapping table
100 @param Table The table
101
102 @retval 0 OK.
103 @retval BAD_TABLE The table is corrupted.
104
105 **/
106 UINT16
107 MakeTable (
108 IN SCRATCH_DATA *Sd,
109 IN UINT16 NumOfChar,
110 IN UINT8 *BitLen,
111 IN UINT16 TableBits,
112 OUT UINT16 *Table
113 )
114 {
115 UINT16 Count[17];
116 UINT16 Weight[17];
117 UINT16 Start[18];
118 UINT16 *Pointer;
119 UINT16 Index3;
120 UINT16 Index;
121 UINT16 Len;
122 UINT16 Char;
123 UINT16 JuBits;
124 UINT16 Avail;
125 UINT16 NextCode;
126 UINT16 Mask;
127 UINT16 WordOfStart;
128 UINT16 WordOfCount;
129
130 for (Index = 0; Index <= 16; Index++) {
131 Count[Index] = 0;
132 }
133
134 for (Index = 0; Index < NumOfChar; Index++) {
135 Count[BitLen[Index]]++;
136 }
137
138 Start[0] = 0;
139 Start[1] = 0;
140
141 for (Index = 1; Index <= 16; Index++) {
142 WordOfStart = Start[Index];
143 WordOfCount = Count[Index];
144 Start[Index + 1] = (UINT16) (WordOfStart + (WordOfCount << (16 - Index)));
145 }
146
147 if (Start[17] != 0) {
148 /*(1U << 16)*/
149 return (UINT16) BAD_TABLE;
150 }
151
152 JuBits = (UINT16) (16 - TableBits);
153
154 Weight[0] = 0;
155 for (Index = 1; Index <= TableBits; Index++) {
156 Start[Index] >>= JuBits;
157 Weight[Index] = (UINT16) (1U << (TableBits - Index));
158 }
159
160 while (Index <= 16) {
161 Weight[Index] = (UINT16) (1U << (16 - Index));
162 Index++;
163 }
164
165 Index = (UINT16) (Start[TableBits + 1] >> JuBits);
166
167 if (Index != 0) {
168 Index3 = (UINT16) (1U << TableBits);
169 if (Index < Index3) {
170 SetMem16 (Table + Index, (Index3 - Index) * sizeof (*Table), 0);
171 }
172 }
173
174 Avail = NumOfChar;
175 Mask = (UINT16) (1U << (15 - TableBits));
176
177 for (Char = 0; Char < NumOfChar; Char++) {
178
179 Len = BitLen[Char];
180 if (Len == 0 || Len >= 17) {
181 continue;
182 }
183
184 NextCode = (UINT16) (Start[Len] + Weight[Len]);
185
186 if (Len <= TableBits) {
187
188 for (Index = Start[Len]; Index < NextCode; Index++) {
189 Table[Index] = Char;
190 }
191
192 } else {
193
194 Index3 = Start[Len];
195 Pointer = &Table[Index3 >> JuBits];
196 Index = (UINT16) (Len - TableBits);
197
198 while (Index != 0) {
199 if (*Pointer == 0 && Avail < (2 * NC - 1)) {
200 Sd->mRight[Avail] = Sd->mLeft[Avail] = 0;
201 *Pointer = Avail++;
202 }
203
204 if (*Pointer < (2 * NC - 1)) {
205 if ((Index3 & Mask) != 0) {
206 Pointer = &Sd->mRight[*Pointer];
207 } else {
208 Pointer = &Sd->mLeft[*Pointer];
209 }
210 }
211
212 Index3 <<= 1;
213 Index--;
214 }
215
216 *Pointer = Char;
217
218 }
219
220 Start[Len] = NextCode;
221 }
222 //
223 // Succeeds
224 //
225 return 0;
226 }
227
228 /**
229 Decodes a position value.
230
231 @param Sd the global scratch data
232
233 @return The position value decoded.
234 **/
235 UINT32
236 DecodeP (
237 IN SCRATCH_DATA *Sd
238 )
239 {
240 UINT16 Val;
241 UINT32 Mask;
242 UINT32 Pos;
243
244 Val = Sd->mPTTable[Sd->mBitBuf >> (BITBUFSIZ - 8)];
245
246 if (Val >= MAXNP) {
247 Mask = 1U << (BITBUFSIZ - 1 - 8);
248
249 do {
250
251 if (Sd->mBitBuf & Mask) {
252 Val = Sd->mRight[Val];
253 } else {
254 Val = Sd->mLeft[Val];
255 }
256
257 Mask >>= 1;
258 } while (Val >= MAXNP);
259 }
260 //
261 // Advance what we have read
262 //
263 FillBuf (Sd, Sd->mPTLen[Val]);
264
265 Pos = Val;
266 if (Val > 1) {
267 Pos = (UINT32) ((1U << (Val - 1)) + GetBits (Sd, (UINT16) (Val - 1)));
268 }
269
270 return Pos;
271 }
272
273 /**
274 Reads code lengths for the Extra Set or the Position Set.
275
276 Read in the Extra Set or Pointion Set Length Arrary, then
277 generate the Huffman code mapping for them.
278
279 @param Sd The global scratch data.
280 @param nn Number of symbols.
281 @param nbit Number of bits needed to represent nn.
282 @param Special The special symbol that needs to be taken care of.
283
284 @retval 0 OK.
285 @retval BAD_TABLE Table is corrupted.
286
287 **/
288 UINT16
289 ReadPTLen (
290 IN SCRATCH_DATA *Sd,
291 IN UINT16 nn,
292 IN UINT16 nbit,
293 IN UINT16 Special
294 )
295 {
296 UINT16 Number;
297 UINT16 CharC;
298 UINT16 Index;
299 UINT32 Mask;
300
301 //
302 // Read Extra Set Code Length Array size
303 //
304 Number = (UINT16) GetBits (Sd, nbit);
305
306 if (Number == 0) {
307 //
308 // This represents only Huffman code used
309 //
310 CharC = (UINT16) GetBits (Sd, nbit);
311
312 for (Index = 0; Index < 256; Index++) {
313 Sd->mPTTable[Index] = CharC;
314 }
315
316 SetMem (Sd->mPTLen, nn, 0);
317
318 return 0;
319 }
320
321 Index = 0;
322
323 while (Index < Number && Index < NPT) {
324
325 CharC = (UINT16) (Sd->mBitBuf >> (BITBUFSIZ - 3));
326
327 //
328 // If a code length is less than 7, then it is encoded as a 3-bit
329 // value. Or it is encoded as a series of "1"s followed by a
330 // terminating "0". The number of "1"s = Code length - 4.
331 //
332 if (CharC == 7) {
333 Mask = 1U << (BITBUFSIZ - 1 - 3);
334 while (Mask & Sd->mBitBuf) {
335 Mask >>= 1;
336 CharC += 1;
337 }
338 }
339
340 FillBuf (Sd, (UINT16) ((CharC < 7) ? 3 : CharC - 3));
341
342 Sd->mPTLen[Index++] = (UINT8) CharC;
343
344 //
345 // For Code&Len Set,
346 // After the third length of the code length concatenation,
347 // a 2-bit value is used to indicated the number of consecutive
348 // zero lengths after the third length.
349 //
350 if (Index == Special) {
351 CharC = (UINT16) GetBits (Sd, 2);
352 while ((INT16) (--CharC) >= 0 && Index < NPT) {
353 Sd->mPTLen[Index++] = 0;
354 }
355 }
356 }
357
358 while (Index < nn && Index < NPT) {
359 Sd->mPTLen[Index++] = 0;
360 }
361
362 return MakeTable (Sd, nn, Sd->mPTLen, 8, Sd->mPTTable);
363 }
364
365 /**
366 Reads code lengths for Char&Len Set.
367
368 Read in and decode the Char&Len Set Code Length Array, then
369 generate the Huffman Code mapping table for the Char&Len Set.
370
371 @param Sd the global scratch data
372
373 **/
374 VOID
375 ReadCLen (
376 SCRATCH_DATA *Sd
377 )
378 {
379 UINT16 Number;
380 UINT16 CharC;
381 UINT16 Index;
382 UINT32 Mask;
383
384 Number = (UINT16) GetBits (Sd, CBIT);
385
386 if (Number == 0) {
387 //
388 // This represents only Huffman code used
389 //
390 CharC = (UINT16) GetBits (Sd, CBIT);
391
392 SetMem (Sd->mCLen, NC, 0);
393
394 for (Index = 0; Index < 4096; Index++) {
395 Sd->mCTable[Index] = CharC;
396 }
397
398 return ;
399 }
400
401 Index = 0;
402 while (Index < Number && Index < NC) {
403 CharC = Sd->mPTTable[Sd->mBitBuf >> (BITBUFSIZ - 8)];
404 if (CharC >= NT) {
405 Mask = 1U << (BITBUFSIZ - 1 - 8);
406
407 do {
408
409 if (Mask & Sd->mBitBuf) {
410 CharC = Sd->mRight[CharC];
411 } else {
412 CharC = Sd->mLeft[CharC];
413 }
414
415 Mask >>= 1;
416
417 } while (CharC >= NT);
418 }
419 //
420 // Advance what we have read
421 //
422 FillBuf (Sd, Sd->mPTLen[CharC]);
423
424 if (CharC <= 2) {
425
426 if (CharC == 0) {
427 CharC = 1;
428 } else if (CharC == 1) {
429 CharC = (UINT16) (GetBits (Sd, 4) + 3);
430 } else if (CharC == 2) {
431 CharC = (UINT16) (GetBits (Sd, CBIT) + 20);
432 }
433
434 while ((INT16) (--CharC) >= 0 && Index < NC) {
435 Sd->mCLen[Index++] = 0;
436 }
437
438 } else {
439
440 Sd->mCLen[Index++] = (UINT8) (CharC - 2);
441
442 }
443 }
444
445 SetMem (Sd->mCLen + Index, NC - Index, 0);
446
447 MakeTable (Sd, NC, Sd->mCLen, 12, Sd->mCTable);
448
449 return ;
450 }
451
452 /**
453 Decode a character/length value.
454
455 Read one value from mBitBuf, Get one code from mBitBuf. If it is at block boundary, generates
456 Huffman code mapping table for Extra Set, Code&Len Set and
457 Position Set.
458
459 @param Sd The global scratch data.
460
461 @return The value decoded.
462
463 **/
464 UINT16
465 DecodeC (
466 SCRATCH_DATA *Sd
467 )
468 {
469 UINT16 Index2;
470 UINT32 Mask;
471
472 if (Sd->mBlockSize == 0) {
473 //
474 // Starting a new block
475 //
476 Sd->mBlockSize = (UINT16) GetBits (Sd, 16);
477 Sd->mBadTableFlag = ReadPTLen (Sd, NT, TBIT, 3);
478 if (Sd->mBadTableFlag != 0) {
479 return 0;
480 }
481
482 ReadCLen (Sd);
483
484 Sd->mBadTableFlag = ReadPTLen (Sd, MAXNP, Sd->mPBit, (UINT16) (-1));
485 if (Sd->mBadTableFlag != 0) {
486 return 0;
487 }
488 }
489
490 Sd->mBlockSize--;
491 Index2 = Sd->mCTable[Sd->mBitBuf >> (BITBUFSIZ - 12)];
492
493 if (Index2 >= NC) {
494 Mask = 1U << (BITBUFSIZ - 1 - 12);
495
496 do {
497 if (Sd->mBitBuf & Mask) {
498 Index2 = Sd->mRight[Index2];
499 } else {
500 Index2 = Sd->mLeft[Index2];
501 }
502
503 Mask >>= 1;
504 } while (Index2 >= NC);
505 }
506 //
507 // Advance what we have read
508 //
509 FillBuf (Sd, Sd->mCLen[Index2]);
510
511 return Index2;
512 }
513
514 /**
515 Decode the source data ad put the resulting data into the destination buffer.
516
517 @param Sd - The global scratch data
518 **/
519 VOID
520 Decode (
521 SCRATCH_DATA *Sd
522 )
523 {
524 UINT16 BytesRemain;
525 UINT32 DataIdx;
526 UINT16 CharC;
527
528 BytesRemain = (UINT16) (-1);
529
530 DataIdx = 0;
531
532 for (;;) {
533 CharC = DecodeC (Sd);
534 if (Sd->mBadTableFlag != 0) {
535 goto Done ;
536 }
537
538 if (CharC < 256) {
539 //
540 // Process an Original character
541 //
542 if (Sd->mOutBuf >= Sd->mOrigSize) {
543 goto Done ;
544 } else {
545 Sd->mDstBase[Sd->mOutBuf++] = (UINT8) CharC;
546 }
547
548 } else {
549 //
550 // Process a Pointer
551 //
552 CharC = (UINT16) (CharC - (BIT8 - THRESHOLD));
553
554 BytesRemain = CharC;
555
556 DataIdx = Sd->mOutBuf - DecodeP (Sd) - 1;
557
558 BytesRemain--;
559 while ((INT16) (BytesRemain) >= 0) {
560 Sd->mDstBase[Sd->mOutBuf++] = Sd->mDstBase[DataIdx++];
561 if (Sd->mOutBuf >= Sd->mOrigSize) {
562 goto Done ;
563 }
564
565 BytesRemain--;
566 }
567 }
568 }
569
570 Done:
571 return ;
572 }
573
574 /**
575 The internal implementation of *_DECOMPRESS_PROTOCOL.GetInfo().
576
577 @param Source The source buffer containing the compressed data.
578 @param SourceSize The size of source buffer
579 @param DestinationSize The size of destination buffer.
580 @param ScratchSize The size of scratch buffer.
581
582 @retval RETURN_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved.
583 @retval RETURN_INVALID_PARAMETER - The source data is corrupted
584 **/
585 RETURN_STATUS
586 EFIAPI
587 UefiDecompressGetInfo (
588 IN CONST VOID *Source,
589 IN UINT32 SourceSize,
590 OUT UINT32 *DestinationSize,
591 OUT UINT32 *ScratchSize
592 )
593 {
594 UINT32 CompressedSize;
595
596 ASSERT (Source != NULL);
597 ASSERT (DestinationSize != NULL);
598 ASSERT (ScratchSize != NULL);
599
600 if (SourceSize < 8) {
601 return RETURN_INVALID_PARAMETER;
602 }
603
604 CompressedSize = ReadUnaligned32 ((UINT32 *)Source);
605 if (SourceSize < (CompressedSize + 8)) {
606 return RETURN_INVALID_PARAMETER;
607 }
608
609 *ScratchSize = sizeof (SCRATCH_DATA);
610 *DestinationSize = ReadUnaligned32 ((UINT32 *)Source + 1);
611
612 return RETURN_SUCCESS;
613 }
614
615 /**
616 The internal implementation of *_DECOMPRESS_PROTOCOL.Decompress().
617
618 @param Source The source buffer containing the compressed data.
619 @param Destination The destination buffer to store the decompressed data
620 @param Scratch The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.
621 @param Version 1 for UEFI Decompress algoruthm, 2 for Tiano Decompess algorithm
622
623 @retval RETURN_SUCCESS Decompression is successfull
624 @retval RETURN_INVALID_PARAMETER The source data is corrupted
625 **/
626 RETURN_STATUS
627 EFIAPI
628 UefiTianoDecompress (
629 IN CONST VOID *Source,
630 IN OUT VOID *Destination,
631 IN OUT VOID *Scratch,
632 IN UINT32 Version
633 )
634 {
635 UINT32 CompSize;
636 UINT32 OrigSize;
637 SCRATCH_DATA *Sd;
638 CONST UINT8 *Src;
639 UINT8 *Dst;
640
641 ASSERT (Source != NULL);
642 ASSERT (Destination != NULL);
643 ASSERT (Scratch != NULL);
644
645 Src = Source;
646 Dst = Destination;
647
648 Sd = (SCRATCH_DATA *) Scratch;
649
650 CompSize = Src[0] + (Src[1] << 8) + (Src[2] << 16) + (Src[3] << 24);
651 OrigSize = Src[4] + (Src[5] << 8) + (Src[6] << 16) + (Src[7] << 24);
652
653 //
654 // If compressed file size is 0, return
655 //
656 if (OrigSize == 0) {
657 return RETURN_SUCCESS;
658 }
659
660 Src = Src + 8;
661
662 SetMem (Sd, sizeof (SCRATCH_DATA), 0);
663
664 //
665 // The length of the field 'Position Set Code Length Array Size' in Block Header.
666 // For UEFI 2.0 de/compression algorithm(Version 1), mPBit = 4
667 // For Tiano de/compression algorithm(Version 2), mPBit = 5
668 //
669 switch (Version) {
670 case 1 :
671 Sd->mPBit = 4;
672 break;
673 case 2 :
674 Sd->mPBit = 5;
675 break;
676 default:
677 ASSERT (FALSE);
678 }
679 Sd->mSrcBase = (UINT8 *)Src;
680 Sd->mDstBase = Dst;
681 Sd->mCompSize = CompSize;
682 Sd->mOrigSize = OrigSize;
683
684 //
685 // Fill the first BITBUFSIZ bits
686 //
687 FillBuf (Sd, BITBUFSIZ);
688
689 //
690 // Decompress it
691 //
692 Decode (Sd);
693
694 if (Sd->mBadTableFlag != 0) {
695 //
696 // Something wrong with the source
697 //
698 return RETURN_INVALID_PARAMETER;
699 }
700
701 return RETURN_SUCCESS;
702 }
703
704 /**
705 The internal implementation of *_DECOMPRESS_PROTOCOL.Decompress().
706
707 @param Source - The source buffer containing the compressed data.
708 @param Destination - The destination buffer to store the decompressed data
709 @param Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.
710
711 @retval RETURN_SUCCESS - Decompression is successfull
712 @retval RETURN_INVALID_PARAMETER - The source data is corrupted
713 **/
714 RETURN_STATUS
715 EFIAPI
716 UefiDecompress (
717 IN CONST VOID *Source,
718 IN OUT VOID *Destination,
719 IN OUT VOID *Scratch
720 )
721 {
722 return UefiTianoDecompress (Source, Destination, Scratch, 1);
723 }
724
725 /**
726 The internal implementation of Tiano decompress GetInfo.
727
728 @param InputSection Buffer containing the input GUIDed section to be processed.
729 @param OutputBufferSize The size of OutputBuffer.
730 @param ScratchBufferSize The size of ScratchBuffer.
731 @param SectionAttribute The attribute of the input guided section.
732
733 @retval RETURN_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved.
734 @retval RETURN_INVALID_PARAMETER - The source data is corrupted
735 The GUID in InputSection does not match this instance guid.
736 **/
737 RETURN_STATUS
738 EFIAPI
739 TianoDecompressGetInfo (
740 IN CONST VOID *InputSection,
741 OUT UINT32 *OutputBufferSize,
742 OUT UINT32 *ScratchBufferSize,
743 OUT UINT16 *SectionAttribute
744 )
745
746 {
747 ASSERT (SectionAttribute != NULL);
748
749 if (InputSection == NULL) {
750 return RETURN_INVALID_PARAMETER;
751 }
752
753 if (!CompareGuid (
754 &gTianoCustomDecompressGuid,
755 &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {
756 return RETURN_INVALID_PARAMETER;
757 }
758 //
759 // Get guid attribute of guid section.
760 //
761 *SectionAttribute = ((EFI_GUID_DEFINED_SECTION *) InputSection)->Attributes;
762
763 //
764 // Call Tiano GetInfo to get the required size info.
765 //
766 return UefiDecompressGetInfo (
767 (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
768 (*(UINT32 *) (((EFI_COMMON_SECTION_HEADER *) InputSection)->Size) & 0x00ffffff) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
769 OutputBufferSize,
770 ScratchBufferSize
771 );
772 }
773
774 /**
775 The implementation of Tiano Decompress().
776
777 @param InputSection Buffer containing the input GUIDed section to be processed.
778 @param OutputBuffer OutputBuffer to point to the start of the section's contents.
779 if guided data is not prcessed. Otherwise,
780 OutputBuffer to contain the output data, which is allocated by the caller.
781 @param ScratchBuffer A pointer to a caller-allocated buffer for function internal use.
782 @param AuthenticationStatus A pointer to a caller-allocated UINT32 that indicates the
783 authentication status of the output buffer.
784
785 @retval RETURN_SUCCESS Decompression is successfull
786 @retval RETURN_INVALID_PARAMETER The source data is corrupted, or
787 The GUID in InputSection does not match this instance guid.
788
789 **/
790 RETURN_STATUS
791 EFIAPI
792 TianoDecompress (
793 IN CONST VOID *InputSection,
794 OUT VOID **OutputBuffer,
795 IN VOID *ScratchBuffer, OPTIONAL
796 OUT UINT32 *AuthenticationStatus
797 )
798 {
799 ASSERT (OutputBuffer != NULL);
800
801 if (InputSection == NULL) {
802 return RETURN_INVALID_PARAMETER;
803 }
804
805 if (!CompareGuid (
806 &gTianoCustomDecompressGuid,
807 &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {
808 return RETURN_INVALID_PARAMETER;
809 }
810
811 //
812 // Set Authentication to Zero.
813 //
814 *AuthenticationStatus = 0;
815
816 //
817 // Call Tiano Decompress to get the raw data
818 //
819 return UefiTianoDecompress (
820 (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
821 *OutputBuffer,
822 ScratchBuffer,
823 2
824 );
825 }
826
827 /**
828 Register TianoDecompress handler.
829
830 @retval RETURN_SUCCESS Register successfully.
831 @retval RETURN_OUT_OF_RESOURCES No enough memory to store this handler.
832 **/
833 RETURN_STATUS
834 EFIAPI
835 TianoDecompressLibConstructor (
836 )
837 {
838 return ExtractGuidedSectionRegisterHandlers (
839 &gTianoCustomDecompressGuid,
840 TianoDecompressGetInfo,
841 TianoDecompress
842 );
843 }