More moves for Tool Packages
authorlhauch <lhauch@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 5 Oct 2006 23:24:16 +0000 (23:24 +0000)
committerlhauch <lhauch@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 5 Oct 2006 23:24:16 +0000 (23:24 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1676 6f19259b-4bc3-4df7-8a09-765794883524

552 files changed:
Tools/CCode/Source/Common/CommonLib.c [new file with mode: 0644]
Tools/CCode/Source/Common/CommonLib.h [new file with mode: 0644]
Tools/CCode/Source/Common/Crc32.c [new file with mode: 0644]
Tools/CCode/Source/Common/Crc32.h [new file with mode: 0644]
Tools/CCode/Source/Common/EfiCompress.c [new file with mode: 0644]
Tools/CCode/Source/Common/EfiCompress.h [new file with mode: 0644]
Tools/CCode/Source/Common/EfiCustomizedCompress.h [new file with mode: 0644]
Tools/CCode/Source/Common/EfiDecompress.c [new file with mode: 0644]
Tools/CCode/Source/Common/EfiDecompress.h [new file with mode: 0644]
Tools/CCode/Source/Common/EfiUtilityMsgs.c [new file with mode: 0644]
Tools/CCode/Source/Common/EfiUtilityMsgs.h [new file with mode: 0644]
Tools/CCode/Source/Common/FvLib.c [new file with mode: 0644]
Tools/CCode/Source/Common/FvLib.h [new file with mode: 0644]
Tools/CCode/Source/Common/MyAlloc.c [new file with mode: 0644]
Tools/CCode/Source/Common/MyAlloc.h [new file with mode: 0644]
Tools/CCode/Source/Common/ParseInf.c [new file with mode: 0644]
Tools/CCode/Source/Common/ParseInf.h [new file with mode: 0644]
Tools/CCode/Source/Common/SimpleFileParsing.c [new file with mode: 0644]
Tools/CCode/Source/Common/SimpleFileParsing.h [new file with mode: 0644]
Tools/CCode/Source/Common/WinNtInclude.h [new file with mode: 0644]
Tools/CCode/Source/Common/build.xml [new file with mode: 0644]
Tools/CCode/Source/CompressDll/CompressDll.c [new file with mode: 0644]
Tools/CCode/Source/CompressDll/CompressDll.h [new file with mode: 0644]
Tools/CCode/Source/CompressDll/build.xml [new file with mode: 0644]
Tools/CCode/Source/CreateMtFile/CreateMtFile.c [new file with mode: 0644]
Tools/CCode/Source/CreateMtFile/build.xml [new file with mode: 0644]
Tools/CCode/Source/CustomizedCompress/CustomizedCompress.c [new file with mode: 0644]
Tools/CCode/Source/CustomizedCompress/build.xml [new file with mode: 0644]
Tools/CCode/Source/EfiCompress/EfiCompressMain.c [new file with mode: 0644]
Tools/CCode/Source/EfiCompress/build.xml [new file with mode: 0644]
Tools/CCode/Source/EfiRom/EfiRom.c [new file with mode: 0644]
Tools/CCode/Source/EfiRom/build.xml [new file with mode: 0644]
Tools/CCode/Source/FlashMap/FlashDefFile.c [new file with mode: 0644]
Tools/CCode/Source/FlashMap/FlashDefFile.h [new file with mode: 0644]
Tools/CCode/Source/FlashMap/FlashMap.c [new file with mode: 0644]
Tools/CCode/Source/FlashMap/Microcode.c [new file with mode: 0644]
Tools/CCode/Source/FlashMap/Microcode.h [new file with mode: 0644]
Tools/CCode/Source/FlashMap/Symbols.c [new file with mode: 0644]
Tools/CCode/Source/FlashMap/Symbols.h [new file with mode: 0644]
Tools/CCode/Source/FlashMap/build.xml [new file with mode: 0644]
Tools/CCode/Source/FwImage/build.xml [new file with mode: 0644]
Tools/CCode/Source/FwImage/fwimage.c [new file with mode: 0644]
Tools/CCode/Source/GenAcpiTable/GenAcpiTable.c [new file with mode: 0644]
Tools/CCode/Source/GenAcpiTable/build.xml [new file with mode: 0644]
Tools/CCode/Source/GenCRC32Section/GenCRC32Section.c [new file with mode: 0644]
Tools/CCode/Source/GenCRC32Section/GenCRC32Section.h [new file with mode: 0644]
Tools/CCode/Source/GenCRC32Section/build.xml [new file with mode: 0644]
Tools/CCode/Source/GenCapsuleHdr/CreateGuid.c [new file with mode: 0644]
Tools/CCode/Source/GenCapsuleHdr/GenCapsuleHdr.c [new file with mode: 0644]
Tools/CCode/Source/GenCapsuleHdr/build.xml [new file with mode: 0644]
Tools/CCode/Source/GenDepex/DepexParser.c [new file with mode: 0644]
Tools/CCode/Source/GenDepex/DepexParser.h [new file with mode: 0644]
Tools/CCode/Source/GenDepex/GenDepex.c [new file with mode: 0644]
Tools/CCode/Source/GenDepex/GenDepex.h [new file with mode: 0644]
Tools/CCode/Source/GenDepex/build.xml [new file with mode: 0644]
Tools/CCode/Source/GenFfsFile/GenFfsFile.c [new file with mode: 0644]
Tools/CCode/Source/GenFfsFile/GenFfsFile.h [new file with mode: 0644]
Tools/CCode/Source/GenFfsFile/SimpleFileParsing.c [new file with mode: 0644]
Tools/CCode/Source/GenFfsFile/build.xml [new file with mode: 0644]
Tools/CCode/Source/GenFvImage/Ebc/PeCoffLoaderEx.c [new file with mode: 0644]
Tools/CCode/Source/GenFvImage/GenFvImageExe.c [new file with mode: 0644]
Tools/CCode/Source/GenFvImage/GenFvImageExe.h [new file with mode: 0644]
Tools/CCode/Source/GenFvImage/GenFvImageLib.c [new file with mode: 0644]
Tools/CCode/Source/GenFvImage/GenFvImageLib.h [new file with mode: 0644]
Tools/CCode/Source/GenFvImage/GenFvImageLibInternal.h [new file with mode: 0644]
Tools/CCode/Source/GenFvImage/build.xml [new file with mode: 0644]
Tools/CCode/Source/GenSection/GenSection.c [new file with mode: 0644]
Tools/CCode/Source/GenSection/GenSection.h [new file with mode: 0644]
Tools/CCode/Source/GenSection/build.xml [new file with mode: 0644]
Tools/CCode/Source/GenTEImage/GenTEImage.c [new file with mode: 0644]
Tools/CCode/Source/GenTEImage/build.xml [new file with mode: 0644]
Tools/CCode/Source/GuidChk/CommonUtils.h [new file with mode: 0644]
Tools/CCode/Source/GuidChk/FileSearch.c [new file with mode: 0644]
Tools/CCode/Source/GuidChk/FileSearch.h [new file with mode: 0644]
Tools/CCode/Source/GuidChk/GuidChk.c [new file with mode: 0644]
Tools/CCode/Source/GuidChk/GuidList.c [new file with mode: 0644]
Tools/CCode/Source/GuidChk/UtilsMsgs.c [new file with mode: 0644]
Tools/CCode/Source/GuidChk/UtilsMsgs.h [new file with mode: 0644]
Tools/CCode/Source/GuidChk/build.xml [new file with mode: 0644]
Tools/CCode/Source/Include/Common/BaseTypes.h [new file with mode: 0644]
Tools/CCode/Source/Include/Common/Capsule.h [new file with mode: 0644]
Tools/CCode/Source/Include/Common/Dependency.h [new file with mode: 0644]
Tools/CCode/Source/Include/Common/EfiImage.h [new file with mode: 0644]
Tools/CCode/Source/Include/Common/FirmwareFileSystem.h [new file with mode: 0644]
Tools/CCode/Source/Include/Common/FirmwareVolumeHeader.h [new file with mode: 0644]
Tools/CCode/Source/Include/Common/FirmwareVolumeImageFormat.h [new file with mode: 0644]
Tools/CCode/Source/Include/Common/InternalFormRepresentation.h [new file with mode: 0644]
Tools/CCode/Source/Include/Common/MultiPhase.h [new file with mode: 0644]
Tools/CCode/Source/Include/Common/UefiBaseTypes.h [new file with mode: 0644]
Tools/CCode/Source/Include/Common/Variable.h [new file with mode: 0644]
Tools/CCode/Source/Include/Common/WorkingBlockHeader.h [new file with mode: 0644]
Tools/CCode/Source/Include/Guid/AcpiTableStorage.h [new file with mode: 0644]
Tools/CCode/Source/Include/Guid/Apriori.h [new file with mode: 0644]
Tools/CCode/Source/Include/Guid/Capsule.h [new file with mode: 0644]
Tools/CCode/Source/Include/Guid/FirmwareFileSystem.h [new file with mode: 0644]
Tools/CCode/Source/Include/Ia32/ProcessorBind.h [new file with mode: 0644]
Tools/CCode/Source/Include/IndustryStandard/pci22.h [new file with mode: 0644]
Tools/CCode/Source/Include/Library/PeCoffLib.h [new file with mode: 0644]
Tools/CCode/Source/Include/Library/PrintLib.h [new file with mode: 0644]
Tools/CCode/Source/Include/Protocol/DevicePath.h [new file with mode: 0644]
Tools/CCode/Source/Include/Protocol/GuidedSectionExtraction.h [new file with mode: 0644]
Tools/CCode/Source/Include/Protocol/Hii.h [new file with mode: 0644]
Tools/CCode/Source/Include/Protocol/UgaDraw.h [new file with mode: 0644]
Tools/CCode/Source/Include/X64/ProcessorBind.h [new file with mode: 0644]
Tools/CCode/Source/MakeDeps/MakeDeps.c [new file with mode: 0755]
Tools/CCode/Source/MakeDeps/build.xml [new file with mode: 0755]
Tools/CCode/Source/ModifyInf/ModifyInf.c [new file with mode: 0755]
Tools/CCode/Source/ModifyInf/build.xml [new file with mode: 0644]
Tools/CCode/Source/Pccts/CHANGES_FROM_131.txt [new file with mode: 0644]
Tools/CCode/Source/Pccts/CHANGES_FROM_133.txt [new file with mode: 0644]
Tools/CCode/Source/Pccts/CHANGES_FROM_133_BEFORE_MR13.txt [new file with mode: 0644]
Tools/CCode/Source/Pccts/CHANGES_SUMMARY.txt [new file with mode: 0644]
Tools/CCode/Source/Pccts/KNOWN_PROBLEMS.txt [new file with mode: 0644]
Tools/CCode/Source/Pccts/MPW_Read_Me [new file with mode: 0644]
Tools/CCode/Source/Pccts/NOTES.bcc [new file with mode: 0644]
Tools/CCode/Source/Pccts/NOTES.msvc [new file with mode: 0644]
Tools/CCode/Source/Pccts/README [new file with mode: 0644]
Tools/CCode/Source/Pccts/RIGHTS [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/AntlrMS.mak [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/AntlrPPC.mak [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/README [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/antlr.1 [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/antlr.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/antlr.g [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/antlr.r [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/antlr1.txt [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/bits.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/build.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/build.xml [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/dumpcycles.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/dumpnode.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/egman.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/err.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/fcache.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/fset.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/fset2.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/gen.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/generic.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/globals.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/hash.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/hash.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/lex.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/main.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/makefile [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/makefile.cygwin [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/makefile1 [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/misc.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/mode.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/mrhoist.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/parser.dlg [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/pred.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/proto.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/scan.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/stdpccts.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/syn.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/antlr/tokens.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/build.xml [new file with mode: 0644]
Tools/CCode/Source/Pccts/dlg/DlgMS.mak [new file with mode: 0644]
Tools/CCode/Source/Pccts/dlg/DlgPPC.mak [new file with mode: 0644]
Tools/CCode/Source/Pccts/dlg/automata.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/dlg/build.xml [new file with mode: 0644]
Tools/CCode/Source/Pccts/dlg/dlg.1 [new file with mode: 0644]
Tools/CCode/Source/Pccts/dlg/dlg.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/dlg/dlg.r [new file with mode: 0644]
Tools/CCode/Source/Pccts/dlg/dlg1.txt [new file with mode: 0644]
Tools/CCode/Source/Pccts/dlg/dlg_a.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/dlg/dlg_p.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/dlg/dlg_p.g [new file with mode: 0644]
Tools/CCode/Source/Pccts/dlg/err.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/dlg/main.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/dlg/makefile [new file with mode: 0644]
Tools/CCode/Source/Pccts/dlg/makefile.cygwin [new file with mode: 0644]
Tools/CCode/Source/Pccts/dlg/makefile1 [new file with mode: 0644]
Tools/CCode/Source/Pccts/dlg/mode.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/dlg/output.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/dlg/parser.dlg [new file with mode: 0644]
Tools/CCode/Source/Pccts/dlg/relabel.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/dlg/stdpccts.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/dlg/support.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/dlg/tokens.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/AParser.cpp [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/AParser.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/ASTBase.cpp [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/ASTBase.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/ATokPtr.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/ATokPtrImpl.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/AToken.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/ATokenBuffer.cpp [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/ATokenBuffer.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/ATokenStream.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/BufFileInput.cpp [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/BufFileInput.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/DLG_stream_input.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/DLexer.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/DLexerBase.cpp [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/DLexerBase.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/PBlackBox.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/PCCTSAST.cpp [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/PCCTSAST.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/SList.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/antlr.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/ast.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/ast.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/charbuf.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/charptr.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/charptr.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/config.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/dlgauto.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/dlgdef.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/err.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/int.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/pccts_assert.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/pccts_iostream.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/pccts_istream.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/pccts_setjmp.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/pccts_stdarg.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/pccts_stdio.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/pccts_stdlib.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/pccts_string.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/pcctscfg.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/pcnames.bat [new file with mode: 0644]
Tools/CCode/Source/Pccts/h/slist.cpp [new file with mode: 0644]
Tools/CCode/Source/Pccts/history.ps [new file with mode: 0644]
Tools/CCode/Source/Pccts/history.txt [new file with mode: 0644]
Tools/CCode/Source/Pccts/makefile [new file with mode: 0644]
Tools/CCode/Source/Pccts/support/genmk/genmk.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/support/genmk/genmk_old.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/support/genmk/makefile [new file with mode: 0644]
Tools/CCode/Source/Pccts/support/rexpr/makefile [new file with mode: 0644]
Tools/CCode/Source/Pccts/support/rexpr/rexpr.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/support/rexpr/rexpr.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/support/rexpr/test.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/support/set/set.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/support/set/set.h [new file with mode: 0644]
Tools/CCode/Source/Pccts/support/sym/sym.c [new file with mode: 0644]
Tools/CCode/Source/Pccts/support/sym/template.h [new file with mode: 0644]
Tools/CCode/Source/PeCoffLoader/BasePeCoff.c [new file with mode: 0644]
Tools/CCode/Source/PeCoffLoader/Common/EfiImage.h [new file with mode: 0644]
Tools/CCode/Source/PeCoffLoader/Ia32/PeCoffLoaderEx.c [new file with mode: 0644]
Tools/CCode/Source/PeCoffLoader/Ipf/PeCoffLoaderEx.c [new file with mode: 0644]
Tools/CCode/Source/PeCoffLoader/X64/PeCoffLoaderEx.c [new file with mode: 0644]
Tools/CCode/Source/PeCoffLoader/build.xml [new file with mode: 0644]
Tools/CCode/Source/PeiRebase/PeiRebaseExe.c [new file with mode: 0644]
Tools/CCode/Source/PeiRebase/PeiRebaseExe.h [new file with mode: 0644]
Tools/CCode/Source/PeiRebase/build.xml [new file with mode: 0644]
Tools/CCode/Source/SecApResetVectorFixup/SecApResetVectorFixup.c [new file with mode: 0644]
Tools/CCode/Source/SecApResetVectorFixup/SecApResetVectorFixup.h [new file with mode: 0644]
Tools/CCode/Source/SecApResetVectorFixup/build.xml [new file with mode: 0644]
Tools/CCode/Source/SecFixup/SecFixup.c [new file with mode: 0644]
Tools/CCode/Source/SecFixup/SecFixup.h [new file with mode: 0644]
Tools/CCode/Source/SecFixup/build.xml [new file with mode: 0644]
Tools/CCode/Source/SetStamp/SetStamp.c [new file with mode: 0644]
Tools/CCode/Source/SetStamp/build.xml [new file with mode: 0644]
Tools/CCode/Source/SplitFile/SplitFile.c [new file with mode: 0644]
Tools/CCode/Source/SplitFile/build.xml [new file with mode: 0644]
Tools/CCode/Source/StrGather/StrGather.c [new file with mode: 0644]
Tools/CCode/Source/StrGather/StrGather.h [new file with mode: 0644]
Tools/CCode/Source/StrGather/StringDB.c [new file with mode: 0644]
Tools/CCode/Source/StrGather/StringDB.h [new file with mode: 0644]
Tools/CCode/Source/StrGather/build.xml [new file with mode: 0644]
Tools/CCode/Source/String/PrintLib.c [new file with mode: 0644]
Tools/CCode/Source/String/PrintLibInternal.c [new file with mode: 0644]
Tools/CCode/Source/String/PrintLibInternal.h [new file with mode: 0644]
Tools/CCode/Source/String/String.c [new file with mode: 0644]
Tools/CCode/Source/String/build.xml [new file with mode: 0644]
Tools/CCode/Source/Strip/Strip.c [new file with mode: 0644]
Tools/CCode/Source/Strip/build.xml [new file with mode: 0644]
Tools/CCode/Source/TianoTools.msa [new file with mode: 0644]
Tools/CCode/Source/VfrCompile/EfiVfr.h [new file with mode: 0644]
Tools/CCode/Source/VfrCompile/VfrCompile.g [new file with mode: 0644]
Tools/CCode/Source/VfrCompile/VfrServices.cpp [new file with mode: 0644]
Tools/CCode/Source/VfrCompile/VfrServices.h [new file with mode: 0644]
Tools/CCode/Source/VfrCompile/build.xml [new file with mode: 0644]
Tools/CCode/Source/ZeroDebugData/ZeroDebugData.c [new file with mode: 0644]
Tools/CCode/Source/ZeroDebugData/build.xml [new file with mode: 0644]
Tools/CCode/Source/build.xml [new file with mode: 0644]
Tools/CodeTools/Source/Common/CommonLib.c [deleted file]
Tools/CodeTools/Source/Common/CommonLib.h [deleted file]
Tools/CodeTools/Source/Common/Crc32.c [deleted file]
Tools/CodeTools/Source/Common/Crc32.h [deleted file]
Tools/CodeTools/Source/Common/EfiCompress.c [deleted file]
Tools/CodeTools/Source/Common/EfiCompress.h [deleted file]
Tools/CodeTools/Source/Common/EfiCustomizedCompress.h [deleted file]
Tools/CodeTools/Source/Common/EfiDecompress.c [deleted file]
Tools/CodeTools/Source/Common/EfiDecompress.h [deleted file]
Tools/CodeTools/Source/Common/EfiUtilityMsgs.c [deleted file]
Tools/CodeTools/Source/Common/EfiUtilityMsgs.h [deleted file]
Tools/CodeTools/Source/Common/FvLib.c [deleted file]
Tools/CodeTools/Source/Common/FvLib.h [deleted file]
Tools/CodeTools/Source/Common/MyAlloc.c [deleted file]
Tools/CodeTools/Source/Common/MyAlloc.h [deleted file]
Tools/CodeTools/Source/Common/ParseInf.c [deleted file]
Tools/CodeTools/Source/Common/ParseInf.h [deleted file]
Tools/CodeTools/Source/Common/SimpleFileParsing.c [deleted file]
Tools/CodeTools/Source/Common/SimpleFileParsing.h [deleted file]
Tools/CodeTools/Source/Common/WinNtInclude.h [deleted file]
Tools/CodeTools/Source/Common/build.xml [deleted file]
Tools/CodeTools/Source/CompressDll/CompressDll.c [deleted file]
Tools/CodeTools/Source/CompressDll/CompressDll.h [deleted file]
Tools/CodeTools/Source/CompressDll/build.xml [deleted file]
Tools/CodeTools/Source/CreateMtFile/CreateMtFile.c [deleted file]
Tools/CodeTools/Source/CreateMtFile/build.xml [deleted file]
Tools/CodeTools/Source/CustomizedCompress/CustomizedCompress.c [deleted file]
Tools/CodeTools/Source/CustomizedCompress/build.xml [deleted file]
Tools/CodeTools/Source/EfiCompress/EfiCompressMain.c [deleted file]
Tools/CodeTools/Source/EfiCompress/build.xml [deleted file]
Tools/CodeTools/Source/EfiRom/EfiRom.c [deleted file]
Tools/CodeTools/Source/EfiRom/build.xml [deleted file]
Tools/CodeTools/Source/FlashMap/FlashDefFile.c [deleted file]
Tools/CodeTools/Source/FlashMap/FlashDefFile.h [deleted file]
Tools/CodeTools/Source/FlashMap/FlashMap.c [deleted file]
Tools/CodeTools/Source/FlashMap/Microcode.c [deleted file]
Tools/CodeTools/Source/FlashMap/Microcode.h [deleted file]
Tools/CodeTools/Source/FlashMap/Symbols.c [deleted file]
Tools/CodeTools/Source/FlashMap/Symbols.h [deleted file]
Tools/CodeTools/Source/FlashMap/build.xml [deleted file]
Tools/CodeTools/Source/FwImage/build.xml [deleted file]
Tools/CodeTools/Source/FwImage/fwimage.c [deleted file]
Tools/CodeTools/Source/GenAcpiTable/GenAcpiTable.c [deleted file]
Tools/CodeTools/Source/GenAcpiTable/build.xml [deleted file]
Tools/CodeTools/Source/GenCRC32Section/GenCRC32Section.c [deleted file]
Tools/CodeTools/Source/GenCRC32Section/GenCRC32Section.h [deleted file]
Tools/CodeTools/Source/GenCRC32Section/build.xml [deleted file]
Tools/CodeTools/Source/GenCapsuleHdr/CreateGuid.c [deleted file]
Tools/CodeTools/Source/GenCapsuleHdr/GenCapsuleHdr.c [deleted file]
Tools/CodeTools/Source/GenCapsuleHdr/build.xml [deleted file]
Tools/CodeTools/Source/GenDepex/DepexParser.c [deleted file]
Tools/CodeTools/Source/GenDepex/DepexParser.h [deleted file]
Tools/CodeTools/Source/GenDepex/GenDepex.c [deleted file]
Tools/CodeTools/Source/GenDepex/GenDepex.h [deleted file]
Tools/CodeTools/Source/GenDepex/build.xml [deleted file]
Tools/CodeTools/Source/GenFfsFile/GenFfsFile.c [deleted file]
Tools/CodeTools/Source/GenFfsFile/GenFfsFile.h [deleted file]
Tools/CodeTools/Source/GenFfsFile/SimpleFileParsing.c [deleted file]
Tools/CodeTools/Source/GenFfsFile/build.xml [deleted file]
Tools/CodeTools/Source/GenFvImage/Ebc/PeCoffLoaderEx.c [deleted file]
Tools/CodeTools/Source/GenFvImage/GenFvImageExe.c [deleted file]
Tools/CodeTools/Source/GenFvImage/GenFvImageExe.h [deleted file]
Tools/CodeTools/Source/GenFvImage/GenFvImageLib.c [deleted file]
Tools/CodeTools/Source/GenFvImage/GenFvImageLib.h [deleted file]
Tools/CodeTools/Source/GenFvImage/GenFvImageLibInternal.h [deleted file]
Tools/CodeTools/Source/GenFvImage/build.xml [deleted file]
Tools/CodeTools/Source/GenSection/GenSection.c [deleted file]
Tools/CodeTools/Source/GenSection/GenSection.h [deleted file]
Tools/CodeTools/Source/GenSection/build.xml [deleted file]
Tools/CodeTools/Source/GenTEImage/GenTEImage.c [deleted file]
Tools/CodeTools/Source/GenTEImage/build.xml [deleted file]
Tools/CodeTools/Source/GuidChk/CommonUtils.h [deleted file]
Tools/CodeTools/Source/GuidChk/FileSearch.c [deleted file]
Tools/CodeTools/Source/GuidChk/FileSearch.h [deleted file]
Tools/CodeTools/Source/GuidChk/GuidChk.c [deleted file]
Tools/CodeTools/Source/GuidChk/GuidList.c [deleted file]
Tools/CodeTools/Source/GuidChk/UtilsMsgs.c [deleted file]
Tools/CodeTools/Source/GuidChk/UtilsMsgs.h [deleted file]
Tools/CodeTools/Source/GuidChk/build.xml [deleted file]
Tools/CodeTools/Source/Include/Common/BaseTypes.h [deleted file]
Tools/CodeTools/Source/Include/Common/Capsule.h [deleted file]
Tools/CodeTools/Source/Include/Common/Dependency.h [deleted file]
Tools/CodeTools/Source/Include/Common/EfiImage.h [deleted file]
Tools/CodeTools/Source/Include/Common/FirmwareFileSystem.h [deleted file]
Tools/CodeTools/Source/Include/Common/FirmwareVolumeHeader.h [deleted file]
Tools/CodeTools/Source/Include/Common/FirmwareVolumeImageFormat.h [deleted file]
Tools/CodeTools/Source/Include/Common/InternalFormRepresentation.h [deleted file]
Tools/CodeTools/Source/Include/Common/MultiPhase.h [deleted file]
Tools/CodeTools/Source/Include/Common/UefiBaseTypes.h [deleted file]
Tools/CodeTools/Source/Include/Common/Variable.h [deleted file]
Tools/CodeTools/Source/Include/Common/WorkingBlockHeader.h [deleted file]
Tools/CodeTools/Source/Include/Guid/AcpiTableStorage.h [deleted file]
Tools/CodeTools/Source/Include/Guid/Apriori.h [deleted file]
Tools/CodeTools/Source/Include/Guid/Capsule.h [deleted file]
Tools/CodeTools/Source/Include/Guid/FirmwareFileSystem.h [deleted file]
Tools/CodeTools/Source/Include/Ia32/ProcessorBind.h [deleted file]
Tools/CodeTools/Source/Include/IndustryStandard/pci22.h [deleted file]
Tools/CodeTools/Source/Include/Library/PeCoffLib.h [deleted file]
Tools/CodeTools/Source/Include/Library/PrintLib.h [deleted file]
Tools/CodeTools/Source/Include/Protocol/DevicePath.h [deleted file]
Tools/CodeTools/Source/Include/Protocol/GuidedSectionExtraction.h [deleted file]
Tools/CodeTools/Source/Include/Protocol/Hii.h [deleted file]
Tools/CodeTools/Source/Include/Protocol/UgaDraw.h [deleted file]
Tools/CodeTools/Source/Include/X64/ProcessorBind.h [deleted file]
Tools/CodeTools/Source/MakeDeps/MakeDeps.c [deleted file]
Tools/CodeTools/Source/MakeDeps/build.xml [deleted file]
Tools/CodeTools/Source/ModifyInf/ModifyInf.c [deleted file]
Tools/CodeTools/Source/ModifyInf/build.xml [deleted file]
Tools/CodeTools/Source/Pccts/CHANGES_FROM_131.txt [deleted file]
Tools/CodeTools/Source/Pccts/CHANGES_FROM_133.txt [deleted file]
Tools/CodeTools/Source/Pccts/CHANGES_FROM_133_BEFORE_MR13.txt [deleted file]
Tools/CodeTools/Source/Pccts/CHANGES_SUMMARY.txt [deleted file]
Tools/CodeTools/Source/Pccts/KNOWN_PROBLEMS.txt [deleted file]
Tools/CodeTools/Source/Pccts/MPW_Read_Me [deleted file]
Tools/CodeTools/Source/Pccts/NOTES.bcc [deleted file]
Tools/CodeTools/Source/Pccts/NOTES.msvc [deleted file]
Tools/CodeTools/Source/Pccts/README [deleted file]
Tools/CodeTools/Source/Pccts/RIGHTS [deleted file]
Tools/CodeTools/Source/Pccts/antlr/AntlrMS.mak [deleted file]
Tools/CodeTools/Source/Pccts/antlr/AntlrPPC.mak [deleted file]
Tools/CodeTools/Source/Pccts/antlr/README [deleted file]
Tools/CodeTools/Source/Pccts/antlr/antlr.1 [deleted file]
Tools/CodeTools/Source/Pccts/antlr/antlr.c [deleted file]
Tools/CodeTools/Source/Pccts/antlr/antlr.g [deleted file]
Tools/CodeTools/Source/Pccts/antlr/antlr.r [deleted file]
Tools/CodeTools/Source/Pccts/antlr/antlr1.txt [deleted file]
Tools/CodeTools/Source/Pccts/antlr/bits.c [deleted file]
Tools/CodeTools/Source/Pccts/antlr/build.c [deleted file]
Tools/CodeTools/Source/Pccts/antlr/build.xml [deleted file]
Tools/CodeTools/Source/Pccts/antlr/dumpcycles.c [deleted file]
Tools/CodeTools/Source/Pccts/antlr/dumpnode.c [deleted file]
Tools/CodeTools/Source/Pccts/antlr/egman.c [deleted file]
Tools/CodeTools/Source/Pccts/antlr/err.c [deleted file]
Tools/CodeTools/Source/Pccts/antlr/fcache.c [deleted file]
Tools/CodeTools/Source/Pccts/antlr/fset.c [deleted file]
Tools/CodeTools/Source/Pccts/antlr/fset2.c [deleted file]
Tools/CodeTools/Source/Pccts/antlr/gen.c [deleted file]
Tools/CodeTools/Source/Pccts/antlr/generic.h [deleted file]
Tools/CodeTools/Source/Pccts/antlr/globals.c [deleted file]
Tools/CodeTools/Source/Pccts/antlr/hash.c [deleted file]
Tools/CodeTools/Source/Pccts/antlr/hash.h [deleted file]
Tools/CodeTools/Source/Pccts/antlr/lex.c [deleted file]
Tools/CodeTools/Source/Pccts/antlr/main.c [deleted file]
Tools/CodeTools/Source/Pccts/antlr/makefile [deleted file]
Tools/CodeTools/Source/Pccts/antlr/makefile.cygwin [deleted file]
Tools/CodeTools/Source/Pccts/antlr/makefile1 [deleted file]
Tools/CodeTools/Source/Pccts/antlr/misc.c [deleted file]
Tools/CodeTools/Source/Pccts/antlr/mode.h [deleted file]
Tools/CodeTools/Source/Pccts/antlr/mrhoist.c [deleted file]
Tools/CodeTools/Source/Pccts/antlr/parser.dlg [deleted file]
Tools/CodeTools/Source/Pccts/antlr/pred.c [deleted file]
Tools/CodeTools/Source/Pccts/antlr/proto.h [deleted file]
Tools/CodeTools/Source/Pccts/antlr/scan.c [deleted file]
Tools/CodeTools/Source/Pccts/antlr/stdpccts.h [deleted file]
Tools/CodeTools/Source/Pccts/antlr/syn.h [deleted file]
Tools/CodeTools/Source/Pccts/antlr/tokens.h [deleted file]
Tools/CodeTools/Source/Pccts/build.xml [deleted file]
Tools/CodeTools/Source/Pccts/dlg/DlgMS.mak [deleted file]
Tools/CodeTools/Source/Pccts/dlg/DlgPPC.mak [deleted file]
Tools/CodeTools/Source/Pccts/dlg/automata.c [deleted file]
Tools/CodeTools/Source/Pccts/dlg/build.xml [deleted file]
Tools/CodeTools/Source/Pccts/dlg/dlg.1 [deleted file]
Tools/CodeTools/Source/Pccts/dlg/dlg.h [deleted file]
Tools/CodeTools/Source/Pccts/dlg/dlg.r [deleted file]
Tools/CodeTools/Source/Pccts/dlg/dlg1.txt [deleted file]
Tools/CodeTools/Source/Pccts/dlg/dlg_a.c [deleted file]
Tools/CodeTools/Source/Pccts/dlg/dlg_p.c [deleted file]
Tools/CodeTools/Source/Pccts/dlg/dlg_p.g [deleted file]
Tools/CodeTools/Source/Pccts/dlg/err.c [deleted file]
Tools/CodeTools/Source/Pccts/dlg/main.c [deleted file]
Tools/CodeTools/Source/Pccts/dlg/makefile [deleted file]
Tools/CodeTools/Source/Pccts/dlg/makefile.cygwin [deleted file]
Tools/CodeTools/Source/Pccts/dlg/makefile1 [deleted file]
Tools/CodeTools/Source/Pccts/dlg/mode.h [deleted file]
Tools/CodeTools/Source/Pccts/dlg/output.c [deleted file]
Tools/CodeTools/Source/Pccts/dlg/parser.dlg [deleted file]
Tools/CodeTools/Source/Pccts/dlg/relabel.c [deleted file]
Tools/CodeTools/Source/Pccts/dlg/stdpccts.h [deleted file]
Tools/CodeTools/Source/Pccts/dlg/support.c [deleted file]
Tools/CodeTools/Source/Pccts/dlg/tokens.h [deleted file]
Tools/CodeTools/Source/Pccts/h/AParser.cpp [deleted file]
Tools/CodeTools/Source/Pccts/h/AParser.h [deleted file]
Tools/CodeTools/Source/Pccts/h/ASTBase.cpp [deleted file]
Tools/CodeTools/Source/Pccts/h/ASTBase.h [deleted file]
Tools/CodeTools/Source/Pccts/h/ATokPtr.h [deleted file]
Tools/CodeTools/Source/Pccts/h/ATokPtrImpl.h [deleted file]
Tools/CodeTools/Source/Pccts/h/AToken.h [deleted file]
Tools/CodeTools/Source/Pccts/h/ATokenBuffer.cpp [deleted file]
Tools/CodeTools/Source/Pccts/h/ATokenBuffer.h [deleted file]
Tools/CodeTools/Source/Pccts/h/ATokenStream.h [deleted file]
Tools/CodeTools/Source/Pccts/h/BufFileInput.cpp [deleted file]
Tools/CodeTools/Source/Pccts/h/BufFileInput.h [deleted file]
Tools/CodeTools/Source/Pccts/h/DLG_stream_input.h [deleted file]
Tools/CodeTools/Source/Pccts/h/DLexer.h [deleted file]
Tools/CodeTools/Source/Pccts/h/DLexerBase.cpp [deleted file]
Tools/CodeTools/Source/Pccts/h/DLexerBase.h [deleted file]
Tools/CodeTools/Source/Pccts/h/PBlackBox.h [deleted file]
Tools/CodeTools/Source/Pccts/h/PCCTSAST.cpp [deleted file]
Tools/CodeTools/Source/Pccts/h/PCCTSAST.h [deleted file]
Tools/CodeTools/Source/Pccts/h/SList.h [deleted file]
Tools/CodeTools/Source/Pccts/h/antlr.h [deleted file]
Tools/CodeTools/Source/Pccts/h/ast.c [deleted file]
Tools/CodeTools/Source/Pccts/h/ast.h [deleted file]
Tools/CodeTools/Source/Pccts/h/charbuf.h [deleted file]
Tools/CodeTools/Source/Pccts/h/charptr.c [deleted file]
Tools/CodeTools/Source/Pccts/h/charptr.h [deleted file]
Tools/CodeTools/Source/Pccts/h/config.h [deleted file]
Tools/CodeTools/Source/Pccts/h/dlgauto.h [deleted file]
Tools/CodeTools/Source/Pccts/h/dlgdef.h [deleted file]
Tools/CodeTools/Source/Pccts/h/err.h [deleted file]
Tools/CodeTools/Source/Pccts/h/int.h [deleted file]
Tools/CodeTools/Source/Pccts/h/pccts_assert.h [deleted file]
Tools/CodeTools/Source/Pccts/h/pccts_iostream.h [deleted file]
Tools/CodeTools/Source/Pccts/h/pccts_istream.h [deleted file]
Tools/CodeTools/Source/Pccts/h/pccts_setjmp.h [deleted file]
Tools/CodeTools/Source/Pccts/h/pccts_stdarg.h [deleted file]
Tools/CodeTools/Source/Pccts/h/pccts_stdio.h [deleted file]
Tools/CodeTools/Source/Pccts/h/pccts_stdlib.h [deleted file]
Tools/CodeTools/Source/Pccts/h/pccts_string.h [deleted file]
Tools/CodeTools/Source/Pccts/h/pcctscfg.h [deleted file]
Tools/CodeTools/Source/Pccts/h/pcnames.bat [deleted file]
Tools/CodeTools/Source/Pccts/h/slist.cpp [deleted file]
Tools/CodeTools/Source/Pccts/history.ps [deleted file]
Tools/CodeTools/Source/Pccts/history.txt [deleted file]
Tools/CodeTools/Source/Pccts/makefile [deleted file]
Tools/CodeTools/Source/Pccts/support/genmk/genmk.c [deleted file]
Tools/CodeTools/Source/Pccts/support/genmk/genmk_old.c [deleted file]
Tools/CodeTools/Source/Pccts/support/genmk/makefile [deleted file]
Tools/CodeTools/Source/Pccts/support/rexpr/makefile [deleted file]
Tools/CodeTools/Source/Pccts/support/rexpr/rexpr.c [deleted file]
Tools/CodeTools/Source/Pccts/support/rexpr/rexpr.h [deleted file]
Tools/CodeTools/Source/Pccts/support/rexpr/test.c [deleted file]
Tools/CodeTools/Source/Pccts/support/set/set.c [deleted file]
Tools/CodeTools/Source/Pccts/support/set/set.h [deleted file]
Tools/CodeTools/Source/Pccts/support/sym/sym.c [deleted file]
Tools/CodeTools/Source/Pccts/support/sym/template.h [deleted file]
Tools/CodeTools/Source/PeCoffLoader/BasePeCoff.c [deleted file]
Tools/CodeTools/Source/PeCoffLoader/Common/EfiImage.h [deleted file]
Tools/CodeTools/Source/PeCoffLoader/Ia32/PeCoffLoaderEx.c [deleted file]
Tools/CodeTools/Source/PeCoffLoader/Ipf/PeCoffLoaderEx.c [deleted file]
Tools/CodeTools/Source/PeCoffLoader/X64/PeCoffLoaderEx.c [deleted file]
Tools/CodeTools/Source/PeCoffLoader/build.xml [deleted file]
Tools/CodeTools/Source/PeiRebase/PeiRebaseExe.c [deleted file]
Tools/CodeTools/Source/PeiRebase/PeiRebaseExe.h [deleted file]
Tools/CodeTools/Source/PeiRebase/build.xml [deleted file]
Tools/CodeTools/Source/SecApResetVectorFixup/SecApResetVectorFixup.c [deleted file]
Tools/CodeTools/Source/SecApResetVectorFixup/SecApResetVectorFixup.h [deleted file]
Tools/CodeTools/Source/SecApResetVectorFixup/build.xml [deleted file]
Tools/CodeTools/Source/SecFixup/SecFixup.c [deleted file]
Tools/CodeTools/Source/SecFixup/SecFixup.h [deleted file]
Tools/CodeTools/Source/SecFixup/build.xml [deleted file]
Tools/CodeTools/Source/SetStamp/SetStamp.c [deleted file]
Tools/CodeTools/Source/SetStamp/build.xml [deleted file]
Tools/CodeTools/Source/SplitFile/SplitFile.c [deleted file]
Tools/CodeTools/Source/SplitFile/build.xml [deleted file]
Tools/CodeTools/Source/StrGather/StrGather.c [deleted file]
Tools/CodeTools/Source/StrGather/StrGather.h [deleted file]
Tools/CodeTools/Source/StrGather/StringDB.c [deleted file]
Tools/CodeTools/Source/StrGather/StringDB.h [deleted file]
Tools/CodeTools/Source/StrGather/build.xml [deleted file]
Tools/CodeTools/Source/String/PrintLib.c [deleted file]
Tools/CodeTools/Source/String/PrintLibInternal.c [deleted file]
Tools/CodeTools/Source/String/PrintLibInternal.h [deleted file]
Tools/CodeTools/Source/String/String.c [deleted file]
Tools/CodeTools/Source/String/build.xml [deleted file]
Tools/CodeTools/Source/Strip/Strip.c [deleted file]
Tools/CodeTools/Source/Strip/build.xml [deleted file]
Tools/CodeTools/Source/TianoTools.msa [deleted file]
Tools/CodeTools/Source/VfrCompile/EfiVfr.h [deleted file]
Tools/CodeTools/Source/VfrCompile/VfrCompile.g [deleted file]
Tools/CodeTools/Source/VfrCompile/VfrServices.cpp [deleted file]
Tools/CodeTools/Source/VfrCompile/VfrServices.h [deleted file]
Tools/CodeTools/Source/VfrCompile/build.xml [deleted file]
Tools/CodeTools/Source/ZeroDebugData/ZeroDebugData.c [deleted file]
Tools/CodeTools/Source/ZeroDebugData/build.xml [deleted file]
Tools/CodeTools/Source/build.xml [deleted file]

diff --git a/Tools/CCode/Source/Common/CommonLib.c b/Tools/CCode/Source/Common/CommonLib.c
new file mode 100644 (file)
index 0000000..4d1663a
--- /dev/null
@@ -0,0 +1,508 @@
+/*++\r
+\r
+Copyright (c) 2004, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  CommonLib.c\r
+\r
+Abstract:\r
+\r
+  Common Library Functions\r
\r
+--*/\r
+\r
+#include <stdio.h>\r
+#include <string.h>\r
+#include <stdlib.h>\r
+#include "CommonLib.h"\r
+\r
+VOID\r
+PeiZeroMem (\r
+  IN VOID   *Buffer,\r
+  IN UINTN  Size\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Set Buffer to zero for Size bytes.\r
+\r
+Arguments:\r
+\r
+  Buffer  - Memory to set.\r
+\r
+  Size    - Number of bytes to set\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  INT8  *Ptr;\r
+\r
+  Ptr = Buffer;\r
+  while (Size--) {\r
+    *(Ptr++) = 0;\r
+  }\r
+}\r
+\r
+VOID\r
+PeiCopyMem (\r
+  IN VOID   *Destination,\r
+  IN VOID   *Source,\r
+  IN UINTN  Length\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Copy Length bytes from Source to Destination.\r
+\r
+Arguments:\r
+\r
+  Destination - Target of copy\r
+\r
+  Source      - Place to copy from\r
+\r
+  Length      - Number of bytes to copy\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  CHAR8 *Destination8;\r
+  CHAR8 *Source8;\r
+\r
+  Destination8  = Destination;\r
+  Source8       = Source;\r
+  while (Length--) {\r
+    *(Destination8++) = *(Source8++);\r
+  }\r
+}\r
+\r
+VOID\r
+ZeroMem (\r
+  IN VOID   *Buffer,\r
+  IN UINTN  Size\r
+  )\r
+{\r
+  PeiZeroMem (Buffer, Size);\r
+}\r
+\r
+VOID\r
+CopyMem (\r
+  IN VOID   *Destination,\r
+  IN VOID   *Source,\r
+  IN UINTN  Length\r
+  )\r
+{\r
+  PeiCopyMem (Destination, Source, Length);\r
+}\r
+\r
+INTN\r
+CompareGuid (\r
+  IN EFI_GUID     *Guid1,\r
+  IN EFI_GUID     *Guid2\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Compares to GUIDs\r
+\r
+Arguments:\r
+\r
+  Guid1 - guid to compare\r
+  Guid2 - guid to compare\r
+\r
+Returns:\r
+  =  0  if Guid1 == Guid2\r
+  != 0  if Guid1 != Guid2 \r
+\r
+--*/\r
+{\r
+  INT32 *g1;\r
+  INT32 *g2;\r
+  INT32 r;\r
+\r
+  //\r
+  // Compare 32 bits at a time\r
+  //\r
+  g1  = (INT32 *) Guid1;\r
+  g2  = (INT32 *) Guid2;\r
+\r
+  r   = g1[0] - g2[0];\r
+  r |= g1[1] - g2[1];\r
+  r |= g1[2] - g2[2];\r
+  r |= g1[3] - g2[3];\r
+\r
+  return r;\r
+}\r
+\r
+EFI_STATUS\r
+GetFileImage (\r
+  IN CHAR8    *InputFileName,\r
+  OUT CHAR8   **InputFileImage,\r
+  OUT UINT32  *BytesRead\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This function opens a file and reads it into a memory buffer.  The function \r
+  will allocate the memory buffer and returns the size of the buffer.\r
+\r
+Arguments:\r
+\r
+  InputFileName     The name of the file to read.\r
+  InputFileImage    A pointer to the memory buffer.\r
+  BytesRead         The size of the memory buffer.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS              The function completed successfully.\r
+  EFI_INVALID_PARAMETER    One of the input parameters was invalid.\r
+  EFI_ABORTED              An error occurred.\r
+  EFI_OUT_OF_RESOURCES     No resource to complete operations.\r
+\r
+--*/\r
+{\r
+  FILE    *InputFile;\r
+  UINT32  FileSize;\r
+\r
+  //\r
+  // Verify input parameters.\r
+  //\r
+  if (InputFileName == NULL || strlen (InputFileName) == 0 || InputFileImage == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  //\r
+  // Open the file and copy contents into a memory buffer.\r
+  //\r
+  //\r
+  // Open the file\r
+  //\r
+  InputFile = fopen (InputFileName, "rb");\r
+  if (InputFile == NULL) {\r
+    printf ("ERROR: Could not open input file \"%s\".\n", InputFileName);\r
+    return EFI_ABORTED;\r
+  }\r
+  //\r
+  // Go to the end so that we can determine the file size\r
+  //\r
+  if (fseek (InputFile, 0, SEEK_END)) {\r
+    printf ("ERROR: System error reading input file \"%s\".\n", InputFileName);\r
+    fclose (InputFile);\r
+    return EFI_ABORTED;\r
+  }\r
+  //\r
+  // Get the file size\r
+  //\r
+  FileSize = ftell (InputFile);\r
+  if (FileSize == -1) {\r
+    printf ("ERROR: System error parsing input file \"%s\".\n", InputFileName);\r
+    fclose (InputFile);\r
+    return EFI_ABORTED;\r
+  }\r
+  //\r
+  // Allocate a buffer\r
+  //\r
+  *InputFileImage = malloc (FileSize);\r
+  if (*InputFileImage == NULL) {\r
+    fclose (InputFile);\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  //\r
+  // Reset to the beginning of the file\r
+  //\r
+  if (fseek (InputFile, 0, SEEK_SET)) {\r
+    printf ("ERROR: System error reading input file \"%s\".\n", InputFileName);\r
+    fclose (InputFile);\r
+    free (*InputFileImage);\r
+    *InputFileImage = NULL;\r
+    return EFI_ABORTED;\r
+  }\r
+  //\r
+  // Read all of the file contents.\r
+  //\r
+  *BytesRead = fread (*InputFileImage, sizeof (UINT8), FileSize, InputFile);\r
+  if (*BytesRead != sizeof (UINT8) * FileSize) {\r
+    printf ("ERROR: Reading file \"%s\"%i.\n", InputFileName);\r
+    fclose (InputFile);\r
+    free (*InputFileImage);\r
+    *InputFileImage = NULL;\r
+    return EFI_ABORTED;\r
+  }\r
+  //\r
+  // Close the file\r
+  //\r
+  fclose (InputFile);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+UINT8\r
+CalculateChecksum8 (\r
+  IN UINT8        *Buffer,\r
+  IN UINTN        Size\r
+  )\r
+/*++\r
+  \r
+Routine Description:\r
+\r
+  This function calculates the value needed for a valid UINT8 checksum\r
+\r
+Arguments:\r
+\r
+  Buffer      Pointer to buffer containing byte data of component.\r
+  Size        Size of the buffer\r
+\r
+Returns:\r
+\r
+  The 8 bit checksum value needed.\r
+\r
+--*/\r
+{\r
+  return (UINT8) (0x100 - CalculateSum8 (Buffer, Size));\r
+}\r
+\r
+UINT8\r
+CalculateSum8 (\r
+  IN UINT8  *Buffer,\r
+  IN UINTN  Size\r
+  )\r
+/*++\r
+  \r
+Routine Description::\r
+\r
+  This function calculates the UINT8 sum for the requested region.\r
+\r
+Arguments:\r
+\r
+  Buffer      Pointer to buffer containing byte data of component.\r
+  Size        Size of the buffer\r
+\r
+Returns:\r
+\r
+  The 8 bit checksum value needed.\r
+\r
+--*/\r
+{\r
+  UINTN Index;\r
+  UINT8 Sum;\r
+\r
+  Sum = 0;\r
+\r
+  //\r
+  // Perform the byte sum for buffer\r
+  //\r
+  for (Index = 0; Index < Size; Index++) {\r
+    Sum = (UINT8) (Sum + Buffer[Index]);\r
+  }\r
+\r
+  return Sum;\r
+}\r
+\r
+UINT16\r
+CalculateChecksum16 (\r
+  IN UINT16       *Buffer,\r
+  IN UINTN        Size\r
+  )\r
+/*++\r
+  \r
+Routine Description::\r
+\r
+  This function calculates the value needed for a valid UINT16 checksum\r
+\r
+Arguments:\r
+\r
+  Buffer      Pointer to buffer containing byte data of component.\r
+  Size        Size of the buffer\r
+\r
+Returns:\r
+\r
+  The 16 bit checksum value needed.\r
+\r
+--*/\r
+{\r
+  return (UINT16) (0x10000 - CalculateSum16 (Buffer, Size));\r
+}\r
+\r
+UINT16\r
+CalculateSum16 (\r
+  IN UINT16       *Buffer,\r
+  IN UINTN        Size\r
+  )\r
+/*++\r
+  \r
+Routine Description:\r
+\r
+  This function calculates the UINT16 sum for the requested region.\r
+\r
+Arguments:\r
+\r
+  Buffer      Pointer to buffer containing byte data of component.\r
+  Size        Size of the buffer\r
+\r
+Returns:\r
+\r
+  The 16 bit checksum\r
+\r
+--*/\r
+{\r
+  UINTN   Index;\r
+  UINT16  Sum;\r
+\r
+  Sum = 0;\r
+\r
+  //\r
+  // Perform the word sum for buffer\r
+  //\r
+  for (Index = 0; Index < Size; Index++) {\r
+    Sum = (UINT16) (Sum + Buffer[Index]);\r
+  }\r
+\r
+  return (UINT16) Sum;\r
+}\r
+\r
+EFI_STATUS\r
+PrintGuid (\r
+  IN EFI_GUID *Guid\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This function prints a GUID to STDOUT.\r
+\r
+Arguments:\r
+\r
+  Guid    Pointer to a GUID to print.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS             The GUID was printed.\r
+  EFI_INVALID_PARAMETER   The input was NULL.\r
+\r
+--*/\r
+{\r
+  if (Guid == NULL) {\r
+    printf ("ERROR: PrintGuid called with a NULL value.\n");\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  printf (\r
+    "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",\r
+    Guid->Data1,\r
+    Guid->Data2,\r
+    Guid->Data3,\r
+    Guid->Data4[0],\r
+    Guid->Data4[1],\r
+    Guid->Data4[2],\r
+    Guid->Data4[3],\r
+    Guid->Data4[4],\r
+    Guid->Data4[5],\r
+    Guid->Data4[6],\r
+    Guid->Data4[7]\r
+    );\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+PrintGuidToBuffer (\r
+  IN EFI_GUID     *Guid,\r
+  IN OUT UINT8    *Buffer,\r
+  IN UINT32       BufferLen,\r
+  IN BOOLEAN      Uppercase\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This function prints a GUID to a buffer\r
+\r
+Arguments:\r
+\r
+  Guid      - Pointer to a GUID to print.\r
+  Buffer    - Pointer to a user-provided buffer to print to\r
+  BufferLen - Size of the Buffer\r
+  Uppercase - If use upper case.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS             The GUID was printed.\r
+  EFI_INVALID_PARAMETER   The input was NULL.\r
+  EFI_BUFFER_TOO_SMALL    The input buffer was not big enough\r
+  \r
+--*/\r
+{\r
+  if (Guid == NULL) {\r
+    printf ("ERROR: PrintGuidToBuffer() called with a NULL value\n");\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (BufferLen < PRINTED_GUID_BUFFER_SIZE) {\r
+    printf ("ERORR: PrintGuidToBuffer() called with invalid buffer size\n");\r
+    return EFI_BUFFER_TOO_SMALL;\r
+  }\r
+\r
+  if (Uppercase) {\r
+    sprintf (\r
+      Buffer,\r
+      "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",\r
+      Guid->Data1,\r
+      Guid->Data2,\r
+      Guid->Data3,\r
+      Guid->Data4[0],\r
+      Guid->Data4[1],\r
+      Guid->Data4[2],\r
+      Guid->Data4[3],\r
+      Guid->Data4[4],\r
+      Guid->Data4[5],\r
+      Guid->Data4[6],\r
+      Guid->Data4[7]\r
+      );\r
+  } else {\r
+    sprintf (\r
+      Buffer,\r
+      "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",\r
+      Guid->Data1,\r
+      Guid->Data2,\r
+      Guid->Data3,\r
+      Guid->Data4[0],\r
+      Guid->Data4[1],\r
+      Guid->Data4[2],\r
+      Guid->Data4[3],\r
+      Guid->Data4[4],\r
+      Guid->Data4[5],\r
+      Guid->Data4[6],\r
+      Guid->Data4[7]\r
+      );\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+#ifdef __GNUC__\r
+#ifndef __CYGWIN__\r
+char *strlwr(char *s)\r
+{\r
+  char *p = s;\r
+  for(;*s;s++) {\r
+    *s = tolower(*s);\r
+  }\r
+  return p;\r
+}\r
+#endif\r
+#endif\r
diff --git a/Tools/CCode/Source/Common/CommonLib.h b/Tools/CCode/Source/Common/CommonLib.h
new file mode 100644 (file)
index 0000000..46f0cba
--- /dev/null
@@ -0,0 +1,135 @@
+/*++\r
+\r
+Copyright (c) 2004, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  CommonLib.h\r
+\r
+Abstract:\r
+\r
+  Common library assistance routines.\r
+\r
+--*/\r
+\r
+#ifndef _EFI_COMMON_LIB_H\r
+#define _EFI_COMMON_LIB_H\r
+\r
+#include <Common/UefiBaseTypes.h>\r
+\r
+#ifndef _MAX_PATH\r
+#define _MAX_PATH 500\r
+#endif\r
+\r
+#define PRINTED_GUID_BUFFER_SIZE  37  // including null-termination\r
+//\r
+// Function declarations\r
+//\r
+VOID\r
+PeiZeroMem (\r
+  IN VOID   *Buffer,\r
+  IN UINTN  Size\r
+  )\r
+;\r
+\r
+VOID\r
+PeiCopyMem (\r
+  IN VOID   *Destination,\r
+  IN VOID   *Source,\r
+  IN UINTN  Length\r
+  )\r
+;\r
+\r
+VOID\r
+ZeroMem (\r
+  IN VOID   *Buffer,\r
+  IN UINTN  Size\r
+  )\r
+;\r
+\r
+VOID\r
+CopyMem (\r
+  IN VOID   *Destination,\r
+  IN VOID   *Source,\r
+  IN UINTN  Length\r
+  )\r
+;\r
+\r
+INTN\r
+CompareGuid (\r
+  IN EFI_GUID     *Guid1,\r
+  IN EFI_GUID     *Guid2\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+GetFileImage (\r
+  IN CHAR8    *InputFileName,\r
+  OUT CHAR8   **InputFileImage,\r
+  OUT UINT32  *BytesRead\r
+  )\r
+;\r
+\r
+UINT8\r
+CalculateChecksum8 (\r
+  IN UINT8        *Buffer,\r
+  IN UINTN        Size\r
+  )\r
+;\r
+\r
+UINT8\r
+CalculateSum8 (\r
+  IN UINT8        *Buffer,\r
+  IN UINTN        Size\r
+  )\r
+;\r
+\r
+UINT16\r
+CalculateChecksum16 (\r
+  IN UINT16       *Buffer,\r
+  IN UINTN        Size\r
+  )\r
+;\r
+\r
+UINT16\r
+CalculateSum16 (\r
+  IN UINT16       *Buffer,\r
+  IN UINTN        Size\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+PrintGuid (\r
+  IN EFI_GUID                     *Guid\r
+  )\r
+;\r
+\r
+#define PRINTED_GUID_BUFFER_SIZE  37  // including null-termination\r
+EFI_STATUS\r
+PrintGuidToBuffer (\r
+  IN EFI_GUID     *Guid,\r
+  IN OUT UINT8    *Buffer,\r
+  IN UINT32       BufferLen,\r
+  IN BOOLEAN      Uppercase\r
+  )\r
+;\r
+\r
+#define ASSERT(x) assert(x)\r
+\r
+#ifdef __GNUC__\r
+#define stricmp strcasecmp\r
+#define strnicmp strncasecmp\r
+#define strcmpi strcasecmp\r
+#ifndef __CYGWIN__\r
+char *strlwr(char *s);\r
+#endif\r
+#endif\r
+\r
+#endif\r
diff --git a/Tools/CCode/Source/Common/Crc32.c b/Tools/CCode/Source/Common/Crc32.c
new file mode 100644 (file)
index 0000000..4ae5eb4
--- /dev/null
@@ -0,0 +1,326 @@
+/*++\r
+\r
+Copyright (c) 2004, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  crc32.c\r
+\r
+Abstract:\r
+\r
+  CalcuateCrc32 routine.\r
+  \r
+--*/\r
+\r
+#include <stdlib.h>\r
+#include "Crc32.h"\r
+\r
+UINT32  mCrcTable[256] = {\r
+  0x00000000,\r
+  0x77073096,\r
+  0xEE0E612C,\r
+  0x990951BA,\r
+  0x076DC419,\r
+  0x706AF48F,\r
+  0xE963A535,\r
+  0x9E6495A3,\r
+  0x0EDB8832,\r
+  0x79DCB8A4,\r
+  0xE0D5E91E,\r
+  0x97D2D988,\r
+  0x09B64C2B,\r
+  0x7EB17CBD,\r
+  0xE7B82D07,\r
+  0x90BF1D91,\r
+  0x1DB71064,\r
+  0x6AB020F2,\r
+  0xF3B97148,\r
+  0x84BE41DE,\r
+  0x1ADAD47D,\r
+  0x6DDDE4EB,\r
+  0xF4D4B551,\r
+  0x83D385C7,\r
+  0x136C9856,\r
+  0x646BA8C0,\r
+  0xFD62F97A,\r
+  0x8A65C9EC,\r
+  0x14015C4F,\r
+  0x63066CD9,\r
+  0xFA0F3D63,\r
+  0x8D080DF5,\r
+  0x3B6E20C8,\r
+  0x4C69105E,\r
+  0xD56041E4,\r
+  0xA2677172,\r
+  0x3C03E4D1,\r
+  0x4B04D447,\r
+  0xD20D85FD,\r
+  0xA50AB56B,\r
+  0x35B5A8FA,\r
+  0x42B2986C,\r
+  0xDBBBC9D6,\r
+  0xACBCF940,\r
+  0x32D86CE3,\r
+  0x45DF5C75,\r
+  0xDCD60DCF,\r
+  0xABD13D59,\r
+  0x26D930AC,\r
+  0x51DE003A,\r
+  0xC8D75180,\r
+  0xBFD06116,\r
+  0x21B4F4B5,\r
+  0x56B3C423,\r
+  0xCFBA9599,\r
+  0xB8BDA50F,\r
+  0x2802B89E,\r
+  0x5F058808,\r
+  0xC60CD9B2,\r
+  0xB10BE924,\r
+  0x2F6F7C87,\r
+  0x58684C11,\r
+  0xC1611DAB,\r
+  0xB6662D3D,\r
+  0x76DC4190,\r
+  0x01DB7106,\r
+  0x98D220BC,\r
+  0xEFD5102A,\r
+  0x71B18589,\r
+  0x06B6B51F,\r
+  0x9FBFE4A5,\r
+  0xE8B8D433,\r
+  0x7807C9A2,\r
+  0x0F00F934,\r
+  0x9609A88E,\r
+  0xE10E9818,\r
+  0x7F6A0DBB,\r
+  0x086D3D2D,\r
+  0x91646C97,\r
+  0xE6635C01,\r
+  0x6B6B51F4,\r
+  0x1C6C6162,\r
+  0x856530D8,\r
+  0xF262004E,\r
+  0x6C0695ED,\r
+  0x1B01A57B,\r
+  0x8208F4C1,\r
+  0xF50FC457,\r
+  0x65B0D9C6,\r
+  0x12B7E950,\r
+  0x8BBEB8EA,\r
+  0xFCB9887C,\r
+  0x62DD1DDF,\r
+  0x15DA2D49,\r
+  0x8CD37CF3,\r
+  0xFBD44C65,\r
+  0x4DB26158,\r
+  0x3AB551CE,\r
+  0xA3BC0074,\r
+  0xD4BB30E2,\r
+  0x4ADFA541,\r
+  0x3DD895D7,\r
+  0xA4D1C46D,\r
+  0xD3D6F4FB,\r
+  0x4369E96A,\r
+  0x346ED9FC,\r
+  0xAD678846,\r
+  0xDA60B8D0,\r
+  0x44042D73,\r
+  0x33031DE5,\r
+  0xAA0A4C5F,\r
+  0xDD0D7CC9,\r
+  0x5005713C,\r
+  0x270241AA,\r
+  0xBE0B1010,\r
+  0xC90C2086,\r
+  0x5768B525,\r
+  0x206F85B3,\r
+  0xB966D409,\r
+  0xCE61E49F,\r
+  0x5EDEF90E,\r
+  0x29D9C998,\r
+  0xB0D09822,\r
+  0xC7D7A8B4,\r
+  0x59B33D17,\r
+  0x2EB40D81,\r
+  0xB7BD5C3B,\r
+  0xC0BA6CAD,\r
+  0xEDB88320,\r
+  0x9ABFB3B6,\r
+  0x03B6E20C,\r
+  0x74B1D29A,\r
+  0xEAD54739,\r
+  0x9DD277AF,\r
+  0x04DB2615,\r
+  0x73DC1683,\r
+  0xE3630B12,\r
+  0x94643B84,\r
+  0x0D6D6A3E,\r
+  0x7A6A5AA8,\r
+  0xE40ECF0B,\r
+  0x9309FF9D,\r
+  0x0A00AE27,\r
+  0x7D079EB1,\r
+  0xF00F9344,\r
+  0x8708A3D2,\r
+  0x1E01F268,\r
+  0x6906C2FE,\r
+  0xF762575D,\r
+  0x806567CB,\r
+  0x196C3671,\r
+  0x6E6B06E7,\r
+  0xFED41B76,\r
+  0x89D32BE0,\r
+  0x10DA7A5A,\r
+  0x67DD4ACC,\r
+  0xF9B9DF6F,\r
+  0x8EBEEFF9,\r
+  0x17B7BE43,\r
+  0x60B08ED5,\r
+  0xD6D6A3E8,\r
+  0xA1D1937E,\r
+  0x38D8C2C4,\r
+  0x4FDFF252,\r
+  0xD1BB67F1,\r
+  0xA6BC5767,\r
+  0x3FB506DD,\r
+  0x48B2364B,\r
+  0xD80D2BDA,\r
+  0xAF0A1B4C,\r
+  0x36034AF6,\r
+  0x41047A60,\r
+  0xDF60EFC3,\r
+  0xA867DF55,\r
+  0x316E8EEF,\r
+  0x4669BE79,\r
+  0xCB61B38C,\r
+  0xBC66831A,\r
+  0x256FD2A0,\r
+  0x5268E236,\r
+  0xCC0C7795,\r
+  0xBB0B4703,\r
+  0x220216B9,\r
+  0x5505262F,\r
+  0xC5BA3BBE,\r
+  0xB2BD0B28,\r
+  0x2BB45A92,\r
+  0x5CB36A04,\r
+  0xC2D7FFA7,\r
+  0xB5D0CF31,\r
+  0x2CD99E8B,\r
+  0x5BDEAE1D,\r
+  0x9B64C2B0,\r
+  0xEC63F226,\r
+  0x756AA39C,\r
+  0x026D930A,\r
+  0x9C0906A9,\r
+  0xEB0E363F,\r
+  0x72076785,\r
+  0x05005713,\r
+  0x95BF4A82,\r
+  0xE2B87A14,\r
+  0x7BB12BAE,\r
+  0x0CB61B38,\r
+  0x92D28E9B,\r
+  0xE5D5BE0D,\r
+  0x7CDCEFB7,\r
+  0x0BDBDF21,\r
+  0x86D3D2D4,\r
+  0xF1D4E242,\r
+  0x68DDB3F8,\r
+  0x1FDA836E,\r
+  0x81BE16CD,\r
+  0xF6B9265B,\r
+  0x6FB077E1,\r
+  0x18B74777,\r
+  0x88085AE6,\r
+  0xFF0F6A70,\r
+  0x66063BCA,\r
+  0x11010B5C,\r
+  0x8F659EFF,\r
+  0xF862AE69,\r
+  0x616BFFD3,\r
+  0x166CCF45,\r
+  0xA00AE278,\r
+  0xD70DD2EE,\r
+  0x4E048354,\r
+  0x3903B3C2,\r
+  0xA7672661,\r
+  0xD06016F7,\r
+  0x4969474D,\r
+  0x3E6E77DB,\r
+  0xAED16A4A,\r
+  0xD9D65ADC,\r
+  0x40DF0B66,\r
+  0x37D83BF0,\r
+  0xA9BCAE53,\r
+  0xDEBB9EC5,\r
+  0x47B2CF7F,\r
+  0x30B5FFE9,\r
+  0xBDBDF21C,\r
+  0xCABAC28A,\r
+  0x53B39330,\r
+  0x24B4A3A6,\r
+  0xBAD03605,\r
+  0xCDD70693,\r
+  0x54DE5729,\r
+  0x23D967BF,\r
+  0xB3667A2E,\r
+  0xC4614AB8,\r
+  0x5D681B02,\r
+  0x2A6F2B94,\r
+  0xB40BBE37,\r
+  0xC30C8EA1,\r
+  0x5A05DF1B,\r
+  0x2D02EF8D\r
+};\r
+\r
+EFI_STATUS\r
+CalculateCrc32 (\r
+  IN  UINT8                             *Data,\r
+  IN  UINTN                             DataSize,\r
+  IN OUT UINT32                         *CrcOut\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The CalculateCrc32 routine.\r
+\r
+Arguments:\r
+\r
+  Data        - The buffer contaning the data to be processed\r
+  DataSize    - The size of data to be processed\r
+  CrcOut      - A pointer to the caller allocated UINT32 that on\r
+                contains the CRC32 checksum of Data\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS               - Calculation is successful.\r
+  EFI_INVALID_PARAMETER     - Data / CrcOut = NULL, or DataSize = 0\r
+\r
+--*/\r
+{\r
+  UINT32  Crc;\r
+  UINTN   Index;\r
+  UINT8   *Ptr;\r
+\r
+  if ((DataSize == 0) || (Data == NULL) || (CrcOut == NULL)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Crc = 0xffffffff;\r
+  for (Index = 0, Ptr = Data; Index < DataSize; Index++, Ptr++) {\r
+    Crc = (Crc >> 8) ^ mCrcTable[(UINT8) Crc ^ *Ptr];\r
+  }\r
+\r
+  *CrcOut = Crc ^ 0xffffffff;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/Tools/CCode/Source/Common/Crc32.h b/Tools/CCode/Source/Common/Crc32.h
new file mode 100644 (file)
index 0000000..ec48cdd
--- /dev/null
@@ -0,0 +1,54 @@
+/*++\r
+\r
+Copyright (c) 2004, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  Crc32.h\r
+\r
+Abstract:\r
+\r
+  Header file for CalcuateCrc32 routine\r
+  \r
+--*/\r
+\r
+#ifndef _CRC32_H\r
+#define _CRC32_H\r
+\r
+#include <Common/UefiBaseTypes.h>\r
+\r
+EFI_STATUS\r
+CalculateCrc32 (\r
+  IN  UINT8                             *Data,\r
+  IN  UINTN                             DataSize,\r
+  IN OUT UINT32                         *CrcOut\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The CalculateCrc32 routine.\r
+\r
+Arguments:\r
+\r
+  Data        - The buffer contaning the data to be processed\r
+  DataSize    - The size of data to be processed\r
+  CrcOut      - A pointer to the caller allocated UINT32 that on\r
+                contains the CRC32 checksum of Data\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS               - Calculation is successful.\r
+  EFI_INVALID_PARAMETER     - Data / CrcOut = NULL, or DataSize = 0\r
+\r
+--*/\r
+;\r
+\r
+#endif\r
diff --git a/Tools/CCode/Source/Common/EfiCompress.c b/Tools/CCode/Source/Common/EfiCompress.c
new file mode 100644 (file)
index 0000000..5b91b1d
--- /dev/null
@@ -0,0 +1,1742 @@
+/*++\r
+\r
+Copyright (c) 2004, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  EfiCompress.c\r
+\r
+Abstract:\r
+\r
+  Compression routine. The compression algorithm is a mixture of\r
+  LZ77 and Huffman coding. LZ77 transforms the source data into a\r
+  sequence of Original Characters and Pointers to repeated strings.\r
+  This sequence is further divided into Blocks and Huffman codings\r
+  are applied to each Block.\r
+\r
+--*/\r
+\r
+#include "EfiCompress.h"\r
+\r
+//\r
+// Macro Definitions\r
+//\r
+typedef INT32 NODE;\r
+#define UINT8_BIT     8\r
+#define THRESHOLD     3\r
+#define INIT_CRC      0\r
+#define WNDBIT        19\r
+#define WNDSIZ        (1U << WNDBIT)\r
+#define MAXMATCH      256\r
+#define BLKSIZ        (1U << 14)  // 16 * 1024U\r
+#define PERC_FLAG     0x80000000U\r
+#define CODE_BIT      16\r
+#define NIL           0\r
+#define MAX_HASH_VAL  (3 * WNDSIZ + (WNDSIZ / 512 + 1) * UINT8_MAX)\r
+#define HASH(p, c)    ((p) + ((c) << (WNDBIT - 9)) + WNDSIZ * 2)\r
+#define CRCPOLY       0xA001\r
+#define UPDATE_CRC(c) mCrc = mCrcTable[(mCrc ^ (c)) & 0xFF] ^ (mCrc >> UINT8_BIT)\r
+\r
+//\r
+// C: the Char&Len Set; P: the Position Set; T: the exTra Set\r
+//\r
+#define NC    (UINT8_MAX + MAXMATCH + 2 - THRESHOLD)\r
+#define CBIT  9\r
+#define NP    (WNDBIT + 1)\r
+#define PBIT  5\r
+#define NT    (CODE_BIT + 3)\r
+#define TBIT  5\r
+#if NT > NP\r
+#define NPT NT\r
+#else\r
+#define NPT NP\r
+#endif\r
+//\r
+// Function Prototypes\r
+//\r
+STATIC VOID PutDword(IN UINT32 Data);\r
+\r
+STATIC\r
+EFI_STATUS\r
+AllocateMemory (\r
+  VOID\r
+  );\r
+\r
+STATIC\r
+VOID\r
+FreeMemory (\r
+  VOID\r
+  );\r
+\r
+STATIC\r
+VOID\r
+InitSlide (\r
+  VOID\r
+  );\r
+\r
+STATIC\r
+NODE\r
+Child (\r
+  IN NODE   NodeQ,\r
+  IN UINT8  CharC\r
+  );\r
+\r
+STATIC\r
+VOID\r
+MakeChild (\r
+  IN NODE  NodeQ,\r
+  IN UINT8 CharC,\r
+  IN NODE  NodeR\r
+  );\r
+\r
+STATIC\r
+VOID\r
+Split (\r
+  IN NODE Old\r
+  );\r
+\r
+STATIC\r
+VOID\r
+InsertNode (\r
+  VOID\r
+  );\r
+\r
+STATIC\r
+VOID\r
+DeleteNode (\r
+  VOID\r
+  );\r
+\r
+STATIC\r
+VOID\r
+GetNextMatch (\r
+  VOID\r
+  );\r
+\r
+STATIC\r
+EFI_STATUS\r
+Encode (\r
+  VOID\r
+  );\r
+\r
+STATIC\r
+VOID\r
+CountTFreq (\r
+  VOID\r
+  );\r
+\r
+STATIC\r
+VOID\r
+WritePTLen (\r
+  IN INT32 Number,\r
+  IN INT32 nbit,\r
+  IN INT32 Special\r
+  );\r
+\r
+STATIC\r
+VOID\r
+WriteCLen (\r
+  VOID\r
+  );\r
+\r
+STATIC\r
+VOID\r
+EncodeC (\r
+  IN INT32 Value\r
+  );\r
+\r
+STATIC\r
+VOID\r
+EncodeP (\r
+  IN UINT32 Value\r
+  );\r
+\r
+STATIC\r
+VOID\r
+SendBlock (\r
+  VOID\r
+  );\r
+\r
+STATIC\r
+VOID\r
+Output (\r
+  IN UINT32 c,\r
+  IN UINT32 p\r
+  );\r
+\r
+STATIC\r
+VOID\r
+HufEncodeStart (\r
+  VOID\r
+  );\r
+\r
+STATIC\r
+VOID\r
+HufEncodeEnd (\r
+  VOID\r
+  );\r
+\r
+STATIC\r
+VOID\r
+MakeCrcTable (\r
+  VOID\r
+  );\r
+\r
+STATIC\r
+VOID\r
+PutBits (\r
+  IN INT32  Number,\r
+  IN UINT32 Value\r
+  );\r
+\r
+STATIC\r
+INT32\r
+FreadCrc (\r
+  OUT UINT8 *Pointer,\r
+  IN  INT32 Number\r
+  );\r
+\r
+STATIC\r
+VOID\r
+InitPutBits (\r
+  VOID\r
+  );\r
+\r
+STATIC\r
+VOID\r
+CountLen (\r
+  IN INT32 Index\r
+  );\r
+\r
+STATIC\r
+VOID\r
+MakeLen (\r
+  IN INT32 Root\r
+  );\r
+\r
+STATIC\r
+VOID\r
+DownHeap (\r
+  IN INT32 Index\r
+  );\r
+\r
+STATIC\r
+VOID\r
+MakeCode (\r
+  IN  INT32       Number,\r
+  IN  UINT8 Len[  ],\r
+  OUT UINT16 Code[]\r
+  );\r
+\r
+STATIC\r
+INT32\r
+MakeTree (\r
+  IN  INT32            NParm,\r
+  IN  UINT16  FreqParm[],\r
+  OUT UINT8   LenParm[ ],\r
+  OUT UINT16  CodeParm[]\r
+  );\r
+\r
+//\r
+//  Global Variables\r
+//\r
+static UINT8  *mSrc, *mDst, *mSrcUpperLimit, *mDstUpperLimit;\r
+\r
+static UINT8  *mLevel, *mText, *mChildCount, *mBuf, mCLen[NC], mPTLen[NPT], *mLen;\r
+static INT16  mHeap[NC + 1];\r
+static INT32  mRemainder, mMatchLen, mBitCount, mHeapSize, mN;\r
+static UINT32 mBufSiz = 0, mOutputPos, mOutputMask, mSubBitBuf, mCrc;\r
+static UINT32 mCompSize, mOrigSize;\r
+\r
+static UINT16 *mFreq, *mSortPtr, mLenCnt[17], mLeft[2 * NC - 1], mRight[2 * NC - 1], mCrcTable[UINT8_MAX + 1],\r
+  mCFreq[2 * NC - 1], mCTable[4096], mCCode[NC], mPFreq[2 * NP - 1], mPTCode[NPT], mTFreq[2 * NT - 1];\r
+\r
+static NODE   mPos, mMatchPos, mAvail, *mPosition, *mParent, *mPrev, *mNext = NULL;\r
+\r
+//\r
+// functions\r
+//\r
+EFI_STATUS\r
+Compress (\r
+  IN      UINT8   *SrcBuffer,\r
+  IN      UINT32  SrcSize,\r
+  IN      UINT8   *DstBuffer,\r
+  IN OUT  UINT32  *DstSize\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The main compression routine.\r
+\r
+Arguments:\r
+\r
+  SrcBuffer   - The buffer storing the source data\r
+  SrcSize     - The size of source data\r
+  DstBuffer   - The buffer to store the compressed data\r
+  DstSize     - On input, the size of DstBuffer; On output,\r
+                the size of the actual compressed data.\r
+\r
+Returns:\r
+\r
+  EFI_BUFFER_TOO_SMALL  - The DstBuffer is too small. In this case,\r
+                DstSize contains the size needed.\r
+  EFI_SUCCESS           - Compression is successful.\r
+  EFI_OUT_OF_RESOURCES  - No resource to complete function.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // Initializations\r
+  //\r
+  mBufSiz         = 0;\r
+  mBuf            = NULL;\r
+  mText           = NULL;\r
+  mLevel          = NULL;\r
+  mChildCount     = NULL;\r
+  mPosition       = NULL;\r
+  mParent         = NULL;\r
+  mPrev           = NULL;\r
+  mNext           = NULL;\r
+\r
+  mSrc            = SrcBuffer;\r
+  mSrcUpperLimit  = mSrc + SrcSize;\r
+  mDst            = DstBuffer;\r
+  mDstUpperLimit  = mDst +*DstSize;\r
+\r
+  PutDword (0L);\r
+  PutDword (0L);\r
+\r
+  MakeCrcTable ();\r
+\r
+  mOrigSize             = mCompSize = 0;\r
+  mCrc                  = INIT_CRC;\r
+\r
+  //\r
+  // Compress it\r
+  //\r
+  Status = Encode ();\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  //\r
+  // Null terminate the compressed data\r
+  //\r
+  if (mDst < mDstUpperLimit) {\r
+    *mDst++ = 0;\r
+  }\r
+  //\r
+  // Fill in compressed size and original size\r
+  //\r
+  mDst = DstBuffer;\r
+  PutDword (mCompSize + 1);\r
+  PutDword (mOrigSize);\r
+\r
+  //\r
+  // Return\r
+  //\r
+  if (mCompSize + 1 + 8 > *DstSize) {\r
+    *DstSize = mCompSize + 1 + 8;\r
+    return EFI_BUFFER_TOO_SMALL;\r
+  } else {\r
+    *DstSize = mCompSize + 1 + 8;\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+}\r
+\r
+STATIC\r
+VOID\r
+PutDword (\r
+  IN UINT32 Data\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Put a dword to output stream\r
+  \r
+Arguments:\r
+\r
+  Data    - the dword to put\r
+  \r
+Returns: (VOID)\r
+  \r
+--*/\r
+{\r
+  if (mDst < mDstUpperLimit) {\r
+    *mDst++ = (UINT8) (((UINT8) (Data)) & 0xff);\r
+  }\r
+\r
+  if (mDst < mDstUpperLimit) {\r
+    *mDst++ = (UINT8) (((UINT8) (Data >> 0x08)) & 0xff);\r
+  }\r
+\r
+  if (mDst < mDstUpperLimit) {\r
+    *mDst++ = (UINT8) (((UINT8) (Data >> 0x10)) & 0xff);\r
+  }\r
+\r
+  if (mDst < mDstUpperLimit) {\r
+    *mDst++ = (UINT8) (((UINT8) (Data >> 0x18)) & 0xff);\r
+  }\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+AllocateMemory (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Allocate memory spaces for data structures used in compression process\r
+  \r
+Argements: \r
+  VOID\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - Memory is allocated successfully\r
+  EFI_OUT_OF_RESOURCES  - Allocation fails\r
+\r
+--*/\r
+{\r
+  UINT32  Index;\r
+\r
+  mText = malloc (WNDSIZ * 2 + MAXMATCH);\r
+  for (Index = 0; Index < WNDSIZ * 2 + MAXMATCH; Index++) {\r
+    mText[Index] = 0;\r
+  }\r
+\r
+  mLevel      = malloc ((WNDSIZ + UINT8_MAX + 1) * sizeof (*mLevel));\r
+  mChildCount = malloc ((WNDSIZ + UINT8_MAX + 1) * sizeof (*mChildCount));\r
+  mPosition   = malloc ((WNDSIZ + UINT8_MAX + 1) * sizeof (*mPosition));\r
+  mParent     = malloc (WNDSIZ * 2 * sizeof (*mParent));\r
+  mPrev       = malloc (WNDSIZ * 2 * sizeof (*mPrev));\r
+  mNext       = malloc ((MAX_HASH_VAL + 1) * sizeof (*mNext));\r
+\r
+  mBufSiz     = BLKSIZ;\r
+  mBuf        = malloc (mBufSiz);\r
+  while (mBuf == NULL) {\r
+    mBufSiz = (mBufSiz / 10U) * 9U;\r
+    if (mBufSiz < 4 * 1024U) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+\r
+    mBuf = malloc (mBufSiz);\r
+  }\r
+\r
+  mBuf[0] = 0;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+VOID\r
+FreeMemory (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Called when compression is completed to free memory previously allocated.\r
+  \r
+Arguments: (VOID)\r
+\r
+Returns: (VOID)\r
+\r
+--*/\r
+{\r
+  if (mText != NULL) {\r
+    free (mText);\r
+  }\r
+\r
+  if (mLevel != NULL) {\r
+    free (mLevel);\r
+  }\r
+\r
+  if (mChildCount != NULL) {\r
+    free (mChildCount);\r
+  }\r
+\r
+  if (mPosition != NULL) {\r
+    free (mPosition);\r
+  }\r
+\r
+  if (mParent != NULL) {\r
+    free (mParent);\r
+  }\r
+\r
+  if (mPrev != NULL) {\r
+    free (mPrev);\r
+  }\r
+\r
+  if (mNext != NULL) {\r
+    free (mNext);\r
+  }\r
+\r
+  if (mBuf != NULL) {\r
+    free (mBuf);\r
+  }\r
+\r
+  return ;\r
+}\r
+\r
+STATIC\r
+VOID\r
+InitSlide (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Initialize String Info Log data structures\r
+  \r
+Arguments: (VOID)\r
+\r
+Returns: (VOID)\r
+\r
+--*/\r
+{\r
+  NODE  Index;\r
+\r
+  for (Index = WNDSIZ; Index <= WNDSIZ + UINT8_MAX; Index++) {\r
+    mLevel[Index]     = 1;\r
+    mPosition[Index]  = NIL;  /* sentinel */\r
+  }\r
+\r
+  for (Index = WNDSIZ; Index < WNDSIZ * 2; Index++) {\r
+    mParent[Index] = NIL;\r
+  }\r
+\r
+  mAvail = 1;\r
+  for (Index = 1; Index < WNDSIZ - 1; Index++) {\r
+    mNext[Index] = (NODE) (Index + 1);\r
+  }\r
+\r
+  mNext[WNDSIZ - 1] = NIL;\r
+  for (Index = WNDSIZ * 2; Index <= MAX_HASH_VAL; Index++) {\r
+    mNext[Index] = NIL;\r
+  }\r
+}\r
+\r
+STATIC\r
+NODE\r
+Child (\r
+  IN NODE  NodeQ,\r
+  IN UINT8 CharC\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Find child node given the parent node and the edge character\r
+  \r
+Arguments:\r
+\r
+  NodeQ       - the parent node\r
+  CharC       - the edge character\r
+  \r
+Returns:\r
+\r
+  The child node (NIL if not found)  \r
+  \r
+--*/\r
+{\r
+  NODE  NodeR;\r
+\r
+  NodeR = mNext[HASH (NodeQ, CharC)];\r
+  //\r
+  // sentinel\r
+  //\r
+  mParent[NIL] = NodeQ;\r
+  while (mParent[NodeR] != NodeQ) {\r
+    NodeR = mNext[NodeR];\r
+  }\r
+\r
+  return NodeR;\r
+}\r
+\r
+STATIC\r
+VOID\r
+MakeChild (\r
+  IN NODE  Parent,\r
+  IN UINT8 CharC,\r
+  IN NODE  Child\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Create a new child for a given parent node.\r
+  \r
+Arguments:\r
+\r
+  Parent       - the parent node\r
+  CharC   - the edge character\r
+  Child       - the child node\r
+  \r
+Returns: (VOID)\r
+\r
+--*/\r
+{\r
+  NODE  Node1;\r
+  NODE  Node2;\r
+\r
+  Node1           = (NODE) HASH (Parent, CharC);\r
+  Node2           = mNext[Node1];\r
+  mNext[Node1]    = Child;\r
+  mNext[Child]    = Node2;\r
+  mPrev[Node2]    = Child;\r
+  mPrev[Child]    = Node1;\r
+  mParent[Child]  = Parent;\r
+  mChildCount[Parent]++;\r
+}\r
+\r
+STATIC\r
+VOID\r
+Split (\r
+  NODE Old\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Split a node.\r
+  \r
+Arguments:\r
+\r
+  Old     - the node to split\r
+  \r
+Returns: (VOID)\r
+\r
+--*/\r
+{\r
+  NODE  New;\r
+  NODE  TempNode;\r
+\r
+  New               = mAvail;\r
+  mAvail            = mNext[New];\r
+  mChildCount[New]  = 0;\r
+  TempNode          = mPrev[Old];\r
+  mPrev[New]        = TempNode;\r
+  mNext[TempNode]   = New;\r
+  TempNode          = mNext[Old];\r
+  mNext[New]        = TempNode;\r
+  mPrev[TempNode]   = New;\r
+  mParent[New]      = mParent[Old];\r
+  mLevel[New]       = (UINT8) mMatchLen;\r
+  mPosition[New]    = mPos;\r
+  MakeChild (New, mText[mMatchPos + mMatchLen], Old);\r
+  MakeChild (New, mText[mPos + mMatchLen], mPos);\r
+}\r
+\r
+STATIC\r
+VOID\r
+InsertNode (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Insert string info for current position into the String Info Log\r
+  \r
+Arguments: (VOID)\r
+\r
+Returns: (VOID)\r
+\r
+--*/\r
+{\r
+  NODE  NodeQ;\r
+  NODE  NodeR;\r
+  NODE  Index2;\r
+  NODE  NodeT;\r
+  UINT8 CharC;\r
+  UINT8 *t1;\r
+  UINT8 *t2;\r
+\r
+  if (mMatchLen >= 4) {\r
+    //\r
+    // We have just got a long match, the target tree\r
+    // can be located by MatchPos + 1. Travese the tree\r
+    // from bottom up to get to a proper starting point.\r
+    // The usage of PERC_FLAG ensures proper node deletion\r
+    // in DeleteNode() later.\r
+    //\r
+    mMatchLen--;\r
+    NodeR = (NODE) ((mMatchPos + 1) | WNDSIZ);\r
+    NodeQ = mParent[NodeR];\r
+    while (NodeQ == NIL) {\r
+      NodeR = mNext[NodeR];\r
+      NodeQ = mParent[NodeR];\r
+    }\r
+\r
+    while (mLevel[NodeQ] >= mMatchLen) {\r
+      NodeR = NodeQ;\r
+      NodeQ = mParent[NodeQ];\r
+    }\r
+\r
+    NodeT = NodeQ;\r
+    while (mPosition[NodeT] < 0) {\r
+      mPosition[NodeT]  = mPos;\r
+      NodeT             = mParent[NodeT];\r
+    }\r
+\r
+    if (NodeT < WNDSIZ) {\r
+      mPosition[NodeT] = (NODE) (mPos | (UINT32) PERC_FLAG);\r
+    }\r
+  } else {\r
+    //\r
+    // Locate the target tree\r
+    //\r
+    NodeQ = (NODE) (mText[mPos] + WNDSIZ);\r
+    CharC = mText[mPos + 1];\r
+    NodeR = Child (NodeQ, CharC);\r
+    if (NodeR == NIL) {\r
+      MakeChild (NodeQ, CharC, mPos);\r
+      mMatchLen = 1;\r
+      return ;\r
+    }\r
+\r
+    mMatchLen = 2;\r
+  }\r
+  //\r
+  // Traverse down the tree to find a match.\r
+  // Update Position value along the route.\r
+  // Node split or creation is involved.\r
+  //\r
+  for (;;) {\r
+    if (NodeR >= WNDSIZ) {\r
+      Index2    = MAXMATCH;\r
+      mMatchPos = NodeR;\r
+    } else {\r
+      Index2    = mLevel[NodeR];\r
+      mMatchPos = (NODE) (mPosition[NodeR] & (UINT32)~PERC_FLAG);\r
+    }\r
+\r
+    if (mMatchPos >= mPos) {\r
+      mMatchPos -= WNDSIZ;\r
+    }\r
+\r
+    t1  = &mText[mPos + mMatchLen];\r
+    t2  = &mText[mMatchPos + mMatchLen];\r
+    while (mMatchLen < Index2) {\r
+      if (*t1 != *t2) {\r
+        Split (NodeR);\r
+        return ;\r
+      }\r
+\r
+      mMatchLen++;\r
+      t1++;\r
+      t2++;\r
+    }\r
+\r
+    if (mMatchLen >= MAXMATCH) {\r
+      break;\r
+    }\r
+\r
+    mPosition[NodeR]  = mPos;\r
+    NodeQ             = NodeR;\r
+    NodeR             = Child (NodeQ, *t1);\r
+    if (NodeR == NIL) {\r
+      MakeChild (NodeQ, *t1, mPos);\r
+      return ;\r
+    }\r
+\r
+    mMatchLen++;\r
+  }\r
+\r
+  NodeT           = mPrev[NodeR];\r
+  mPrev[mPos]     = NodeT;\r
+  mNext[NodeT]    = mPos;\r
+  NodeT           = mNext[NodeR];\r
+  mNext[mPos]     = NodeT;\r
+  mPrev[NodeT]    = mPos;\r
+  mParent[mPos]   = NodeQ;\r
+  mParent[NodeR]  = NIL;\r
+\r
+  //\r
+  // Special usage of 'next'\r
+  //\r
+  mNext[NodeR] = mPos;\r
+\r
+}\r
+\r
+STATIC\r
+VOID\r
+DeleteNode (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Delete outdated string info. (The Usage of PERC_FLAG\r
+  ensures a clean deletion)\r
+  \r
+Arguments: (VOID)\r
+\r
+Returns: (VOID)\r
+\r
+--*/\r
+{\r
+  NODE  NodeQ;\r
+  NODE  NodeR;\r
+  NODE  NodeS;\r
+  NODE  NodeT;\r
+  NODE  NodeU;\r
+\r
+  if (mParent[mPos] == NIL) {\r
+    return ;\r
+  }\r
+\r
+  NodeR         = mPrev[mPos];\r
+  NodeS         = mNext[mPos];\r
+  mNext[NodeR]  = NodeS;\r
+  mPrev[NodeS]  = NodeR;\r
+  NodeR         = mParent[mPos];\r
+  mParent[mPos] = NIL;\r
+  if (NodeR >= WNDSIZ) {\r
+    return ;\r
+  }\r
+\r
+  mChildCount[NodeR]--;\r
+  if (mChildCount[NodeR] > 1) {\r
+    return ;\r
+  }\r
+\r
+  NodeT = (NODE) (mPosition[NodeR] & (UINT32)~PERC_FLAG);\r
+  if (NodeT >= mPos) {\r
+    NodeT -= WNDSIZ;\r
+  }\r
+\r
+  NodeS = NodeT;\r
+  NodeQ = mParent[NodeR];\r
+  NodeU = mPosition[NodeQ];\r
+  while (NodeU & (UINT32) PERC_FLAG) {\r
+    NodeU &= (UINT32)~PERC_FLAG;\r
+    if (NodeU >= mPos) {\r
+      NodeU -= WNDSIZ;\r
+    }\r
+\r
+    if (NodeU > NodeS) {\r
+      NodeS = NodeU;\r
+    }\r
+\r
+    mPosition[NodeQ]  = (NODE) (NodeS | WNDSIZ);\r
+    NodeQ             = mParent[NodeQ];\r
+    NodeU             = mPosition[NodeQ];\r
+  }\r
+\r
+  if (NodeQ < WNDSIZ) {\r
+    if (NodeU >= mPos) {\r
+      NodeU -= WNDSIZ;\r
+    }\r
+\r
+    if (NodeU > NodeS) {\r
+      NodeS = NodeU;\r
+    }\r
+\r
+    mPosition[NodeQ] = (NODE) (NodeS | WNDSIZ | (UINT32) PERC_FLAG);\r
+  }\r
+\r
+  NodeS           = Child (NodeR, mText[NodeT + mLevel[NodeR]]);\r
+  NodeT           = mPrev[NodeS];\r
+  NodeU           = mNext[NodeS];\r
+  mNext[NodeT]    = NodeU;\r
+  mPrev[NodeU]    = NodeT;\r
+  NodeT           = mPrev[NodeR];\r
+  mNext[NodeT]    = NodeS;\r
+  mPrev[NodeS]    = NodeT;\r
+  NodeT           = mNext[NodeR];\r
+  mPrev[NodeT]    = NodeS;\r
+  mNext[NodeS]    = NodeT;\r
+  mParent[NodeS]  = mParent[NodeR];\r
+  mParent[NodeR]  = NIL;\r
+  mNext[NodeR]    = mAvail;\r
+  mAvail          = NodeR;\r
+}\r
+\r
+STATIC\r
+VOID\r
+GetNextMatch (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Advance the current position (read in new data if needed).\r
+  Delete outdated string info. Find a match string for current position.\r
+\r
+Arguments: (VOID)\r
+\r
+Returns: (VOID)\r
+\r
+--*/\r
+{\r
+  INT32 Number;\r
+\r
+  mRemainder--;\r
+  mPos++;\r
+  if (mPos == WNDSIZ * 2) {\r
+    memmove (&mText[0], &mText[WNDSIZ], WNDSIZ + MAXMATCH);\r
+    Number = FreadCrc (&mText[WNDSIZ + MAXMATCH], WNDSIZ);\r
+    mRemainder += Number;\r
+    mPos = WNDSIZ;\r
+  }\r
+\r
+  DeleteNode ();\r
+  InsertNode ();\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+Encode (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The main controlling routine for compression process.\r
+\r
+Arguments: (VOID)\r
+\r
+Returns:\r
+  \r
+  EFI_SUCCESS           - The compression is successful\r
+  EFI_OUT_0F_RESOURCES  - Not enough memory for compression process\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+  INT32       LastMatchLen;\r
+  NODE        LastMatchPos;\r
+\r
+  Status = AllocateMemory ();\r
+  if (EFI_ERROR (Status)) {\r
+    FreeMemory ();\r
+    return Status;\r
+  }\r
+\r
+  InitSlide ();\r
+\r
+  HufEncodeStart ();\r
+\r
+  mRemainder  = FreadCrc (&mText[WNDSIZ], WNDSIZ + MAXMATCH);\r
+\r
+  mMatchLen   = 0;\r
+  mPos        = WNDSIZ;\r
+  InsertNode ();\r
+  if (mMatchLen > mRemainder) {\r
+    mMatchLen = mRemainder;\r
+  }\r
+\r
+  while (mRemainder > 0) {\r
+    LastMatchLen  = mMatchLen;\r
+    LastMatchPos  = mMatchPos;\r
+    GetNextMatch ();\r
+    if (mMatchLen > mRemainder) {\r
+      mMatchLen = mRemainder;\r
+    }\r
+\r
+    if (mMatchLen > LastMatchLen || LastMatchLen < THRESHOLD) {\r
+      //\r
+      // Not enough benefits are gained by outputting a pointer,\r
+      // so just output the original character\r
+      //\r
+      Output (mText[mPos - 1], 0);\r
+\r
+    } else {\r
+\r
+      if (LastMatchLen == THRESHOLD) {\r
+        if (((mPos - LastMatchPos - 2) & (WNDSIZ - 1)) > (1U << 11)) {\r
+          Output (mText[mPos - 1], 0);\r
+          continue;\r
+        }\r
+      }\r
+      //\r
+      // Outputting a pointer is beneficial enough, do it.\r
+      //\r
+      Output (\r
+        LastMatchLen + (UINT8_MAX + 1 - THRESHOLD),\r
+        (mPos - LastMatchPos - 2) & (WNDSIZ - 1)\r
+        );\r
+      LastMatchLen--;\r
+      while (LastMatchLen > 0) {\r
+        GetNextMatch ();\r
+        LastMatchLen--;\r
+      }\r
+\r
+      if (mMatchLen > mRemainder) {\r
+        mMatchLen = mRemainder;\r
+      }\r
+    }\r
+  }\r
+\r
+  HufEncodeEnd ();\r
+  FreeMemory ();\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+VOID\r
+CountTFreq (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Count the frequencies for the Extra Set\r
+  \r
+Arguments: (VOID)\r
+\r
+Returns: (VOID)\r
+\r
+--*/\r
+{\r
+  INT32 Index;\r
+  INT32 Index3;\r
+  INT32 Number;\r
+  INT32 Count;\r
+\r
+  for (Index = 0; Index < NT; Index++) {\r
+    mTFreq[Index] = 0;\r
+  }\r
+\r
+  Number = NC;\r
+  while (Number > 0 && mCLen[Number - 1] == 0) {\r
+    Number--;\r
+  }\r
+\r
+  Index = 0;\r
+  while (Index < Number) {\r
+    Index3 = mCLen[Index++];\r
+    if (Index3 == 0) {\r
+      Count = 1;\r
+      while (Index < Number && mCLen[Index] == 0) {\r
+        Index++;\r
+        Count++;\r
+      }\r
+\r
+      if (Count <= 2) {\r
+        mTFreq[0] = (UINT16) (mTFreq[0] + Count);\r
+      } else if (Count <= 18) {\r
+        mTFreq[1]++;\r
+      } else if (Count == 19) {\r
+        mTFreq[0]++;\r
+        mTFreq[1]++;\r
+      } else {\r
+        mTFreq[2]++;\r
+      }\r
+    } else {\r
+      mTFreq[Index3 + 2]++;\r
+    }\r
+  }\r
+}\r
+\r
+STATIC\r
+VOID\r
+WritePTLen (\r
+  IN INT32 Number,\r
+  IN INT32 nbit,\r
+  IN INT32 Special\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Outputs the code length array for the Extra Set or the Position Set.\r
+  \r
+Arguments:\r
+\r
+  Number       - the number of symbols\r
+  nbit    - the number of bits needed to represent 'n'\r
+  Special - the special symbol that needs to be take care of\r
+  \r
+Returns: (VOID)\r
+\r
+--*/\r
+{\r
+  INT32 Index;\r
+  INT32 Index3;\r
+\r
+  while (Number > 0 && mPTLen[Number - 1] == 0) {\r
+    Number--;\r
+  }\r
+\r
+  PutBits (nbit, Number);\r
+  Index = 0;\r
+  while (Index < Number) {\r
+    Index3 = mPTLen[Index++];\r
+    if (Index3 <= 6) {\r
+      PutBits (3, Index3);\r
+    } else {\r
+      PutBits (Index3 - 3, (1U << (Index3 - 3)) - 2);\r
+    }\r
+\r
+    if (Index == Special) {\r
+      while (Index < 6 && mPTLen[Index] == 0) {\r
+        Index++;\r
+      }\r
+\r
+      PutBits (2, (Index - 3) & 3);\r
+    }\r
+  }\r
+}\r
+\r
+STATIC\r
+VOID\r
+WriteCLen (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Outputs the code length array for Char&Length Set\r
+  \r
+Arguments: (VOID)\r
+\r
+Returns: (VOID)\r
+\r
+--*/\r
+{\r
+  INT32 Index;\r
+  INT32 Index3;\r
+  INT32 Number;\r
+  INT32 Count;\r
+\r
+  Number = NC;\r
+  while (Number > 0 && mCLen[Number - 1] == 0) {\r
+    Number--;\r
+  }\r
+\r
+  PutBits (CBIT, Number);\r
+  Index = 0;\r
+  while (Index < Number) {\r
+    Index3 = mCLen[Index++];\r
+    if (Index3 == 0) {\r
+      Count = 1;\r
+      while (Index < Number && mCLen[Index] == 0) {\r
+        Index++;\r
+        Count++;\r
+      }\r
+\r
+      if (Count <= 2) {\r
+        for (Index3 = 0; Index3 < Count; Index3++) {\r
+          PutBits (mPTLen[0], mPTCode[0]);\r
+        }\r
+      } else if (Count <= 18) {\r
+        PutBits (mPTLen[1], mPTCode[1]);\r
+        PutBits (4, Count - 3);\r
+      } else if (Count == 19) {\r
+        PutBits (mPTLen[0], mPTCode[0]);\r
+        PutBits (mPTLen[1], mPTCode[1]);\r
+        PutBits (4, 15);\r
+      } else {\r
+        PutBits (mPTLen[2], mPTCode[2]);\r
+        PutBits (CBIT, Count - 20);\r
+      }\r
+    } else {\r
+      PutBits (mPTLen[Index3 + 2], mPTCode[Index3 + 2]);\r
+    }\r
+  }\r
+}\r
+\r
+STATIC\r
+VOID\r
+EncodeC (\r
+  IN INT32 Value\r
+  )\r
+{\r
+  PutBits (mCLen[Value], mCCode[Value]);\r
+}\r
+\r
+STATIC\r
+VOID\r
+EncodeP (\r
+  IN UINT32 Value\r
+  )\r
+{\r
+  UINT32  Index;\r
+  UINT32  NodeQ;\r
+\r
+  Index = 0;\r
+  NodeQ = Value;\r
+  while (NodeQ) {\r
+    NodeQ >>= 1;\r
+    Index++;\r
+  }\r
+\r
+  PutBits (mPTLen[Index], mPTCode[Index]);\r
+  if (Index > 1) {\r
+    PutBits (Index - 1, Value & (0xFFFFFFFFU >> (32 - Index + 1)));\r
+  }\r
+}\r
+\r
+STATIC\r
+VOID\r
+SendBlock (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Huffman code the block and output it.\r
+  \r
+Arguments: \r
+  (VOID)\r
+\r
+Returns: \r
+  (VOID)\r
+\r
+--*/\r
+{\r
+  UINT32  Index;\r
+  UINT32  Index2;\r
+  UINT32  Index3;\r
+  UINT32  Flags;\r
+  UINT32  Root;\r
+  UINT32  Pos;\r
+  UINT32  Size;\r
+  Flags = 0;\r
+\r
+  Root  = MakeTree (NC, mCFreq, mCLen, mCCode);\r
+  Size  = mCFreq[Root];\r
+  PutBits (16, Size);\r
+  if (Root >= NC) {\r
+    CountTFreq ();\r
+    Root = MakeTree (NT, mTFreq, mPTLen, mPTCode);\r
+    if (Root >= NT) {\r
+      WritePTLen (NT, TBIT, 3);\r
+    } else {\r
+      PutBits (TBIT, 0);\r
+      PutBits (TBIT, Root);\r
+    }\r
+\r
+    WriteCLen ();\r
+  } else {\r
+    PutBits (TBIT, 0);\r
+    PutBits (TBIT, 0);\r
+    PutBits (CBIT, 0);\r
+    PutBits (CBIT, Root);\r
+  }\r
+\r
+  Root = MakeTree (NP, mPFreq, mPTLen, mPTCode);\r
+  if (Root >= NP) {\r
+    WritePTLen (NP, PBIT, -1);\r
+  } else {\r
+    PutBits (PBIT, 0);\r
+    PutBits (PBIT, Root);\r
+  }\r
+\r
+  Pos = 0;\r
+  for (Index = 0; Index < Size; Index++) {\r
+    if (Index % UINT8_BIT == 0) {\r
+      Flags = mBuf[Pos++];\r
+    } else {\r
+      Flags <<= 1;\r
+    }\r
+\r
+    if (Flags & (1U << (UINT8_BIT - 1))) {\r
+      EncodeC (mBuf[Pos++] + (1U << UINT8_BIT));\r
+      Index3 = mBuf[Pos++];\r
+      for (Index2 = 0; Index2 < 3; Index2++) {\r
+        Index3 <<= UINT8_BIT;\r
+        Index3 += mBuf[Pos++];\r
+      }\r
+\r
+      EncodeP (Index3);\r
+    } else {\r
+      EncodeC (mBuf[Pos++]);\r
+    }\r
+  }\r
+\r
+  for (Index = 0; Index < NC; Index++) {\r
+    mCFreq[Index] = 0;\r
+  }\r
+\r
+  for (Index = 0; Index < NP; Index++) {\r
+    mPFreq[Index] = 0;\r
+  }\r
+}\r
+\r
+STATIC\r
+VOID\r
+Output (\r
+  IN UINT32 CharC,\r
+  IN UINT32 Pos\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Outputs an Original Character or a Pointer\r
+\r
+Arguments:\r
+\r
+  CharC     - The original character or the 'String Length' element of a Pointer\r
+  Pos     - The 'Position' field of a Pointer\r
+\r
+Returns: (VOID)\r
+\r
+--*/\r
+{\r
+  static UINT32 CPos;\r
+\r
+  if ((mOutputMask >>= 1) == 0) {\r
+    mOutputMask = 1U << (UINT8_BIT - 1);\r
+    //\r
+    // Check the buffer overflow per outputing UINT8_BIT symbols\r
+    // which is an Original Character or a Pointer. The biggest\r
+    // symbol is a Pointer which occupies 5 bytes.\r
+    //\r
+    if (mOutputPos >= mBufSiz - 5 * UINT8_BIT) {\r
+      SendBlock ();\r
+      mOutputPos = 0;\r
+    }\r
+\r
+    CPos        = mOutputPos++;\r
+    mBuf[CPos]  = 0;\r
+  }\r
+\r
+  mBuf[mOutputPos++] = (UINT8) CharC;\r
+  mCFreq[CharC]++;\r
+  if (CharC >= (1U << UINT8_BIT)) {\r
+    mBuf[CPos] |= mOutputMask;\r
+    mBuf[mOutputPos++]  = (UINT8) (Pos >> 24);\r
+    mBuf[mOutputPos++]  = (UINT8) (Pos >> 16);\r
+    mBuf[mOutputPos++]  = (UINT8) (Pos >> (UINT8_BIT));\r
+    mBuf[mOutputPos++]  = (UINT8) Pos;\r
+    CharC               = 0;\r
+    while (Pos) {\r
+      Pos >>= 1;\r
+      CharC++;\r
+    }\r
+\r
+    mPFreq[CharC]++;\r
+  }\r
+}\r
+\r
+STATIC\r
+VOID\r
+HufEncodeStart (\r
+  VOID\r
+  )\r
+{\r
+  INT32 Index;\r
+\r
+  for (Index = 0; Index < NC; Index++) {\r
+    mCFreq[Index] = 0;\r
+  }\r
+\r
+  for (Index = 0; Index < NP; Index++) {\r
+    mPFreq[Index] = 0;\r
+  }\r
+\r
+  mOutputPos = mOutputMask = 0;\r
+  InitPutBits ();\r
+  return ;\r
+}\r
+\r
+STATIC\r
+VOID\r
+HufEncodeEnd (\r
+  VOID\r
+  )\r
+{\r
+  SendBlock ();\r
+\r
+  //\r
+  // Flush remaining bits\r
+  //\r
+  PutBits (UINT8_BIT - 1, 0);\r
+\r
+  return ;\r
+}\r
+\r
+STATIC\r
+VOID\r
+MakeCrcTable (\r
+  VOID\r
+  )\r
+{\r
+  UINT32  Index;\r
+  UINT32  Index2;\r
+  UINT32  Temp;\r
+\r
+  for (Index = 0; Index <= UINT8_MAX; Index++) {\r
+    Temp = Index;\r
+    for (Index2 = 0; Index2 < UINT8_BIT; Index2++) {\r
+      if (Temp & 1) {\r
+        Temp = (Temp >> 1) ^ CRCPOLY;\r
+      } else {\r
+        Temp >>= 1;\r
+      }\r
+    }\r
+\r
+    mCrcTable[Index] = (UINT16) Temp;\r
+  }\r
+}\r
+\r
+STATIC\r
+VOID\r
+PutBits (\r
+  IN INT32  Number,\r
+  IN UINT32 Value\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Outputs rightmost n bits of x\r
+\r
+Arguments:\r
+\r
+  Number   - the rightmost n bits of the data is used\r
+  x   - the data \r
+\r
+Returns: (VOID)\r
+\r
+--*/\r
+{\r
+  UINT8 Temp;\r
+\r
+  while (Number >= mBitCount) {\r
+    //\r
+    // Number -= mBitCount should never equal to 32\r
+    //\r
+    Temp = (UINT8) (mSubBitBuf | (Value >> (Number -= mBitCount)));\r
+    if (mDst < mDstUpperLimit) {\r
+      *mDst++ = Temp;\r
+    }\r
+\r
+    mCompSize++;\r
+    mSubBitBuf  = 0;\r
+    mBitCount   = UINT8_BIT;\r
+  }\r
+\r
+  mSubBitBuf |= Value << (mBitCount -= Number);\r
+}\r
+\r
+STATIC\r
+INT32\r
+FreadCrc (\r
+  OUT UINT8 *Pointer,\r
+  IN  INT32 Number\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Read in source data\r
+  \r
+Arguments:\r
+\r
+  Pointer   - the buffer to hold the data\r
+  Number   - number of bytes to read\r
+\r
+Returns:\r
+\r
+  number of bytes actually read\r
+  \r
+--*/\r
+{\r
+  INT32 Index;\r
+\r
+  for (Index = 0; mSrc < mSrcUpperLimit && Index < Number; Index++) {\r
+    *Pointer++ = *mSrc++;\r
+  }\r
+\r
+  Number = Index;\r
+\r
+  Pointer -= Number;\r
+  mOrigSize += Number;\r
+  Index--;\r
+  while (Index >= 0) {\r
+    UPDATE_CRC (*Pointer++);\r
+    Index--;\r
+  }\r
+\r
+  return Number;\r
+}\r
+\r
+STATIC\r
+VOID\r
+InitPutBits (\r
+  VOID\r
+  )\r
+{\r
+  mBitCount   = UINT8_BIT;\r
+  mSubBitBuf  = 0;\r
+}\r
+\r
+STATIC\r
+VOID\r
+CountLen (\r
+  IN INT32 Index\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Count the number of each code length for a Huffman tree.\r
+  \r
+Arguments:\r
+\r
+  Index   - the top node\r
+  \r
+Returns: (VOID)\r
+\r
+--*/\r
+{\r
+  static INT32  Depth = 0;\r
+\r
+  if (Index < mN) {\r
+    mLenCnt[(Depth < 16) ? Depth : 16]++;\r
+  } else {\r
+    Depth++;\r
+    CountLen (mLeft[Index]);\r
+    CountLen (mRight[Index]);\r
+    Depth--;\r
+  }\r
+}\r
+\r
+STATIC\r
+VOID\r
+MakeLen (\r
+  IN INT32 Root\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Create code length array for a Huffman tree\r
+  \r
+Arguments:\r
+\r
+  Root   - the root of the tree\r
+  \r
+Returns:\r
+\r
+  VOID\r
+\r
+--*/\r
+{\r
+  INT32   Index;\r
+  INT32   Index3;\r
+  UINT32  Cum;\r
+\r
+  for (Index = 0; Index <= 16; Index++) {\r
+    mLenCnt[Index] = 0;\r
+  }\r
+\r
+  CountLen (Root);\r
+\r
+  //\r
+  // Adjust the length count array so that\r
+  // no code will be generated longer than its designated length\r
+  //\r
+  Cum = 0;\r
+  for (Index = 16; Index > 0; Index--) {\r
+    Cum += mLenCnt[Index] << (16 - Index);\r
+  }\r
+\r
+  while (Cum != (1U << 16)) {\r
+    mLenCnt[16]--;\r
+    for (Index = 15; Index > 0; Index--) {\r
+      if (mLenCnt[Index] != 0) {\r
+        mLenCnt[Index]--;\r
+        mLenCnt[Index + 1] += 2;\r
+        break;\r
+      }\r
+    }\r
+\r
+    Cum--;\r
+  }\r
+\r
+  for (Index = 16; Index > 0; Index--) {\r
+    Index3 = mLenCnt[Index];\r
+    Index3--;\r
+    while (Index3 >= 0) {\r
+      mLen[*mSortPtr++] = (UINT8) Index;\r
+      Index3--;\r
+    }\r
+  }\r
+}\r
+\r
+STATIC\r
+VOID\r
+DownHeap (\r
+  IN INT32 Index\r
+  )\r
+{\r
+  INT32 Index2;\r
+  INT32 Index3;\r
+\r
+  //\r
+  // priority queue: send Index-th entry down heap\r
+  //\r
+  Index3  = mHeap[Index];\r
+  Index2  = 2 * Index;\r
+  while (Index2 <= mHeapSize) {\r
+    if (Index2 < mHeapSize && mFreq[mHeap[Index2]] > mFreq[mHeap[Index2 + 1]]) {\r
+      Index2++;\r
+    }\r
+\r
+    if (mFreq[Index3] <= mFreq[mHeap[Index2]]) {\r
+      break;\r
+    }\r
+\r
+    mHeap[Index]  = mHeap[Index2];\r
+    Index         = Index2;\r
+    Index2        = 2 * Index;\r
+  }\r
+\r
+  mHeap[Index] = (INT16) Index3;\r
+}\r
+\r
+STATIC\r
+VOID\r
+MakeCode (\r
+  IN  INT32       Number,\r
+  IN  UINT8 Len[  ],\r
+  OUT UINT16 Code[]\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Assign code to each symbol based on the code length array\r
+  \r
+Arguments:\r
+\r
+  Number     - number of symbols\r
+  Len   - the code length array\r
+  Code  - stores codes for each symbol\r
+\r
+Returns: (VOID)\r
+\r
+--*/\r
+{\r
+  INT32   Index;\r
+  UINT16  Start[18];\r
+\r
+  Start[1] = 0;\r
+  for (Index = 1; Index <= 16; Index++) {\r
+    Start[Index + 1] = (UINT16) ((Start[Index] + mLenCnt[Index]) << 1);\r
+  }\r
+\r
+  for (Index = 0; Index < Number; Index++) {\r
+    Code[Index] = Start[Len[Index]]++;\r
+  }\r
+}\r
+\r
+STATIC\r
+INT32\r
+MakeTree (\r
+  IN  INT32            NParm,\r
+  IN  UINT16  FreqParm[],\r
+  OUT UINT8   LenParm[ ],\r
+  OUT UINT16  CodeParm[]\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Generates Huffman codes given a frequency distribution of symbols\r
+  \r
+Arguments:\r
+\r
+  NParm    - number of symbols\r
+  FreqParm - frequency of each symbol\r
+  LenParm  - code length for each symbol\r
+  CodeParm - code for each symbol\r
+  \r
+Returns:\r
+\r
+  Root of the Huffman tree.\r
+  \r
+--*/\r
+{\r
+  INT32 Index;\r
+  INT32 Index2;\r
+  INT32 Index3;\r
+  INT32 Avail;\r
+\r
+  //\r
+  // make tree, calculate len[], return root\r
+  //\r
+  mN        = NParm;\r
+  mFreq     = FreqParm;\r
+  mLen      = LenParm;\r
+  Avail     = mN;\r
+  mHeapSize = 0;\r
+  mHeap[1]  = 0;\r
+  for (Index = 0; Index < mN; Index++) {\r
+    mLen[Index] = 0;\r
+    if (mFreq[Index]) {\r
+      mHeapSize++;\r
+      mHeap[mHeapSize] = (INT16) Index;\r
+    }\r
+  }\r
+\r
+  if (mHeapSize < 2) {\r
+    CodeParm[mHeap[1]] = 0;\r
+    return mHeap[1];\r
+  }\r
+\r
+  for (Index = mHeapSize / 2; Index >= 1; Index--) {\r
+    //\r
+    // make priority queue\r
+    //\r
+    DownHeap (Index);\r
+  }\r
+\r
+  mSortPtr = CodeParm;\r
+  do {\r
+    Index = mHeap[1];\r
+    if (Index < mN) {\r
+      *mSortPtr++ = (UINT16) Index;\r
+    }\r
+\r
+    mHeap[1] = mHeap[mHeapSize--];\r
+    DownHeap (1);\r
+    Index2 = mHeap[1];\r
+    if (Index2 < mN) {\r
+      *mSortPtr++ = (UINT16) Index2;\r
+    }\r
+\r
+    Index3        = Avail++;\r
+    mFreq[Index3] = (UINT16) (mFreq[Index] + mFreq[Index2]);\r
+    mHeap[1]      = (INT16) Index3;\r
+    DownHeap (1);\r
+    mLeft[Index3]   = (UINT16) Index;\r
+    mRight[Index3]  = (UINT16) Index2;\r
+  } while (mHeapSize > 1);\r
+\r
+  mSortPtr = CodeParm;\r
+  MakeLen (Index3);\r
+  MakeCode (NParm, LenParm, CodeParm);\r
+\r
+  //\r
+  // return root\r
+  //\r
+  return Index3;\r
+}\r
diff --git a/Tools/CCode/Source/Common/EfiCompress.h b/Tools/CCode/Source/Common/EfiCompress.h
new file mode 100644 (file)
index 0000000..6ad80e4
--- /dev/null
@@ -0,0 +1,69 @@
+/*++\r
+\r
+Copyright (c) 2004, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  EfiCompress.h\r
+\r
+Abstract:\r
+\r
+  Header file for compression routine\r
+  \r
+--*/\r
+\r
+#ifndef _EFICOMPRESS_H\r
+#define _EFICOMPRESS_H\r
+\r
+#include <string.h>\r
+#include <stdlib.h>\r
+\r
+#include <Common/UefiBaseTypes.h>\r
+\r
+EFI_STATUS\r
+Compress (\r
+  IN      UINT8   *SrcBuffer,\r
+  IN      UINT32  SrcSize,\r
+  IN      UINT8   *DstBuffer,\r
+  IN OUT  UINT32  *DstSize\r
+  )\r
+;\r
+\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The compression routine.\r
+\r
+Arguments:\r
+\r
+  SrcBuffer   - The buffer storing the source data\r
+  SrcSize     - The size of source data\r
+  DstBuffer   - The buffer to store the compressed data\r
+  DstSize     - On input, the size of DstBuffer; On output,\r
+                the size of the actual compressed data.\r
+\r
+Returns:\r
+\r
+  EFI_BUFFER_TOO_SMALL  - The DstBuffer is too small. In this case,\r
+                DstSize contains the size needed.\r
+  EFI_SUCCESS           - Compression is successful.\r
+\r
+--*/\r
+typedef\r
+EFI_STATUS\r
+(*COMPRESS_FUNCTION) (\r
+  IN      UINT8   *SrcBuffer,\r
+  IN      UINT32  SrcSize,\r
+  IN      UINT8   *DstBuffer,\r
+  IN OUT  UINT32  *DstSize\r
+  );\r
+\r
+#endif\r
diff --git a/Tools/CCode/Source/Common/EfiCustomizedCompress.h b/Tools/CCode/Source/Common/EfiCustomizedCompress.h
new file mode 100644 (file)
index 0000000..af26b6f
--- /dev/null
@@ -0,0 +1,141 @@
+/*++\r
+\r
+Copyright (c) 2004, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+  \r
+  EfiCustomizedCompress.h\r
+\r
+Abstract:\r
+\r
+  Header file for Customized compression routine\r
+  \r
+--*/\r
+\r
+#ifndef _EFICUSTOMIZEDCOMPRESS_H\r
+#define _EFICUSTOMIZEDCOMPRESS_H\r
+\r
+#include <Common/UefiBaseTypes.h>\r
+\r
+EFI_STATUS\r
+SetCustomizedCompressionType (\r
+  IN  CHAR8   *Type\r
+  )\r
+;\r
+\r
+/*++\r
+\r
+Routine Description:\r
+\r
+The implementation of Customized SetCompressionType().\r
+\r
+Arguments:\r
+  Type        - The type if compression.\r
+    \r
+Returns:\r
+    \r
+  EFI_SUCCESS           - The type has been set.\r
+  EFI_UNSUPPORTED       - This type is unsupported.\r
+\r
+    \r
+--*/\r
+EFI_STATUS\r
+CustomizedGetInfo (\r
+  IN      VOID    *Source,\r
+  IN      UINT32  SrcSize,\r
+  OUT     UINT32  *DstSize,\r
+  OUT     UINT32  *ScratchSize\r
+  )\r
+;\r
+\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The implementation of Customized GetInfo().\r
+\r
+Arguments:\r
+\r
+  Source      - The source buffer containing the compressed data.\r
+  SrcSize     - The size of source buffer\r
+  DstSize     - The size of destination buffer.\r
+  ScratchSize - The size of scratch buffer.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - The size of destination buffer and the size of scratch buffer are successull retrieved.\r
+  EFI_INVALID_PARAMETER - The source data is corrupted\r
+\r
+--*/\r
+EFI_STATUS\r
+CustomizedDecompress (\r
+  IN      VOID    *Source,\r
+  IN      UINT32  SrcSize,\r
+  IN OUT  VOID    *Destination,\r
+  IN      UINT32  DstSize,\r
+  IN OUT  VOID    *Scratch,\r
+  IN      UINT32  ScratchSize\r
+  )\r
+;\r
+\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The implementation of Customized Decompress().\r
+\r
+Arguments:\r
+\r
+  This        - The protocol instance pointer\r
+  Source      - The source buffer containing the compressed data.\r
+  SrcSize     - The size of source buffer\r
+  Destination - The destination buffer to store the decompressed data\r
+  DstSize     - The size of destination buffer.\r
+  Scratch     - The buffer used internally by the decompress routine. This  buffer is needed to store intermediate data.\r
+  ScratchSize - The size of scratch buffer.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - Decompression is successfull\r
+  EFI_INVALID_PARAMETER - The source data is corrupted\r
+\r
+--*/\r
+EFI_STATUS\r
+CustomizedCompress (\r
+  IN      UINT8   *SrcBuffer,\r
+  IN      UINT32  SrcSize,\r
+  IN      UINT8   *DstBuffer,\r
+  IN OUT  UINT32  *DstSize\r
+  )\r
+;\r
+\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The Customized compression routine.\r
+\r
+Arguments:\r
+\r
+  SrcBuffer   - The buffer storing the source data\r
+  SrcSize     - The size of source data\r
+  DstBuffer   - The buffer to store the compressed data\r
+  DstSize     - On input, the size of DstBuffer; On output,\r
+                the size of the actual compressed data.\r
+\r
+Returns:\r
+\r
+  EFI_BUFFER_TOO_SMALL  - The DstBuffer is too small. In this case,\r
+                          DstSize contains the size needed.\r
+  EFI_SUCCESS           - Compression is successful.\r
+\r
+--*/\r
+\r
+#endif\r
diff --git a/Tools/CCode/Source/Common/EfiDecompress.c b/Tools/CCode/Source/Common/EfiDecompress.c
new file mode 100644 (file)
index 0000000..288c425
--- /dev/null
@@ -0,0 +1,790 @@
+/*++\r
+\r
+Copyright (c) 2004, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+  \r
+  EfiDecompress.c\r
+\r
+Abstract:\r
+\r
+  Decompressor. Algorithm Ported from OPSD code (Decomp.asm)\r
+  \r
+--*/\r
+\r
+#include "EfiDecompress.h"\r
+\r
+//\r
+// Decompression algorithm begins here\r
+//\r
+#define BITBUFSIZ 32\r
+#define MAXMATCH  256\r
+#define THRESHOLD 3\r
+#define CODE_BIT  16\r
+#define BAD_TABLE - 1\r
+\r
+//\r
+// C: Char&Len Set; P: Position Set; T: exTra Set\r
+//\r
+#define NC    (0xff + MAXMATCH + 2 - THRESHOLD)\r
+#define CBIT  9\r
+#define PBIT  5\r
+#define TBIT  5\r
+#define MAXNP ((1U << PBIT) - 1)\r
+#define NT    (CODE_BIT + 3)\r
+#if NT > MAXNP\r
+#define NPT NT\r
+#else\r
+#define NPT MAXNP\r
+#endif\r
+\r
+typedef struct {\r
+  UINT8   *mSrcBase;  // Starting address of compressed data\r
+  UINT8   *mDstBase;  // Starting address of decompressed data\r
+  UINT32  mOutBuf;\r
+  UINT32  mInBuf;\r
+\r
+  UINT16  mBitCount;\r
+  UINT32  mBitBuf;\r
+  UINT32  mSubBitBuf;\r
+  UINT16  mBlockSize;\r
+  UINT32  mCompSize;\r
+  UINT32  mOrigSize;\r
+\r
+  UINT16  mBadTableFlag;\r
+\r
+  UINT16  mLeft[2 * NC - 1];\r
+  UINT16  mRight[2 * NC - 1];\r
+  UINT8   mCLen[NC];\r
+  UINT8   mPTLen[NPT];\r
+  UINT16  mCTable[4096];\r
+  UINT16  mPTTable[256];\r
+} SCRATCH_DATA;\r
+\r
+STATIC\r
+VOID\r
+FillBuf (\r
+  IN  SCRATCH_DATA  *Sd,\r
+  IN  UINT16        NumOfBits\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Shift mBitBuf NumOfBits left. Read in NumOfBits of bits from source.\r
+\r
+Arguments:\r
+\r
+  Sd        - The global scratch data\r
+  NumOfBit  - The number of bits to shift and read.\r
+\r
+Returns: (VOID)\r
+\r
+--*/\r
+{\r
+  Sd->mBitBuf = (UINT32) (Sd->mBitBuf << NumOfBits);\r
+\r
+  while (NumOfBits > Sd->mBitCount) {\r
+\r
+    Sd->mBitBuf |= (UINT32) (Sd->mSubBitBuf << (NumOfBits = (UINT16) (NumOfBits - Sd->mBitCount)));\r
+\r
+    if (Sd->mCompSize > 0) {\r
+      //\r
+      // Get 1 byte into SubBitBuf\r
+      //\r
+      Sd->mCompSize--;\r
+      Sd->mSubBitBuf  = 0;\r
+      Sd->mSubBitBuf  = Sd->mSrcBase[Sd->mInBuf++];\r
+      Sd->mBitCount   = 8;\r
+\r
+    } else {\r
+      //\r
+      // No more bits from the source, just pad zero bit.\r
+      //\r
+      Sd->mSubBitBuf  = 0;\r
+      Sd->mBitCount   = 8;\r
+\r
+    }\r
+  }\r
+\r
+  Sd->mBitCount = (UINT16) (Sd->mBitCount - NumOfBits);\r
+  Sd->mBitBuf |= Sd->mSubBitBuf >> Sd->mBitCount;\r
+}\r
+\r
+STATIC\r
+UINT32\r
+GetBits (\r
+  IN  SCRATCH_DATA  *Sd,\r
+  IN  UINT16        NumOfBits\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Get NumOfBits of bits out from mBitBuf. Fill mBitBuf with subsequent \r
+  NumOfBits of bits from source. Returns NumOfBits of bits that are \r
+  popped out.\r
+\r
+Arguments:\r
+\r
+  Sd            - The global scratch data.\r
+  NumOfBits     - The number of bits to pop and read.\r
+\r
+Returns:\r
+\r
+  The bits that are popped out.\r
+\r
+--*/\r
+{\r
+  UINT32  OutBits;\r
+\r
+  OutBits = (UINT32) (Sd->mBitBuf >> (BITBUFSIZ - NumOfBits));\r
+\r
+  FillBuf (Sd, NumOfBits);\r
+\r
+  return OutBits;\r
+}\r
+\r
+STATIC\r
+UINT16\r
+MakeTable (\r
+  IN  SCRATCH_DATA  *Sd,\r
+  IN  UINT16        NumOfChar,\r
+  IN  UINT8         *BitLen,\r
+  IN  UINT16        TableBits,\r
+  OUT UINT16        *Table\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Creates Huffman Code mapping table according to code length array.\r
+\r
+Arguments:\r
+\r
+  Sd        - The global scratch data\r
+  NumOfChar - Number of symbols in the symbol set\r
+  BitLen    - Code length array\r
+  TableBits - The width of the mapping table\r
+  Table     - The table\r
+  \r
+Returns:\r
+  \r
+  0         - OK.\r
+  BAD_TABLE - The table is corrupted.\r
+\r
+--*/\r
+{\r
+  UINT16  Count[17];\r
+  UINT16  Weight[17];\r
+  UINT16  Start[18];\r
+  UINT16  *Pointer;\r
+  UINT16  Index3;\r
+  UINT16  Index;\r
+  UINT16  Len;\r
+  UINT16  Char;\r
+  UINT16  JuBits;\r
+  UINT16  Avail;\r
+  UINT16  NextCode;\r
+  UINT16  Mask;\r
+\r
+  for (Index = 1; Index <= 16; Index++) {\r
+    Count[Index] = 0;\r
+  }\r
+\r
+  for (Index = 0; Index < NumOfChar; Index++) {\r
+    Count[BitLen[Index]]++;\r
+  }\r
+\r
+  Start[1] = 0;\r
+\r
+  for (Index = 1; Index <= 16; Index++) {\r
+    Start[Index + 1] = (UINT16) (Start[Index] + (Count[Index] << (16 - Index)));\r
+  }\r
+\r
+  if (Start[17] != 0) {\r
+    /*(1U << 16)*/\r
+    return (UINT16) BAD_TABLE;\r
+  }\r
+\r
+  JuBits = (UINT16) (16 - TableBits);\r
+\r
+  for (Index = 1; Index <= TableBits; Index++) {\r
+    Start[Index] >>= JuBits;\r
+    Weight[Index] = (UINT16) (1U << (TableBits - Index));\r
+  }\r
+\r
+  while (Index <= 16) {\r
+    Weight[Index++] = (UINT16) (1U << (16 - Index));\r
+  }\r
+\r
+  Index = (UINT16) (Start[TableBits + 1] >> JuBits);\r
+\r
+  if (Index != 0) {\r
+    Index3 = (UINT16) (1U << TableBits);\r
+    while (Index != Index3) {\r
+      Table[Index++] = 0;\r
+    }\r
+  }\r
+\r
+  Avail = NumOfChar;\r
+  Mask  = (UINT16) (1U << (15 - TableBits));\r
+\r
+  for (Char = 0; Char < NumOfChar; Char++) {\r
+\r
+    Len = BitLen[Char];\r
+    if (Len == 0) {\r
+      continue;\r
+    }\r
+\r
+    NextCode = (UINT16) (Start[Len] + Weight[Len]);\r
+\r
+    if (Len <= TableBits) {\r
+\r
+      for (Index = Start[Len]; Index < NextCode; Index++) {\r
+        Table[Index] = Char;\r
+      }\r
+\r
+    } else {\r
+\r
+      Index3  = Start[Len];\r
+      Pointer = &Table[Index3 >> JuBits];\r
+      Index   = (UINT16) (Len - TableBits);\r
+\r
+      while (Index != 0) {\r
+        if (*Pointer == 0) {\r
+          Sd->mRight[Avail]                     = Sd->mLeft[Avail] = 0;\r
+          *Pointer = Avail++;\r
+        }\r
+\r
+        if (Index3 & Mask) {\r
+          Pointer = &Sd->mRight[*Pointer];\r
+        } else {\r
+          Pointer = &Sd->mLeft[*Pointer];\r
+        }\r
+\r
+        Index3 <<= 1;\r
+        Index--;\r
+      }\r
+\r
+      *Pointer = Char;\r
+\r
+    }\r
+\r
+    Start[Len] = NextCode;\r
+  }\r
+  //\r
+  // Succeeds\r
+  //\r
+  return 0;\r
+}\r
+\r
+STATIC\r
+UINT32\r
+DecodeP (\r
+  IN  SCRATCH_DATA  *Sd\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Decodes a position value.\r
+\r
+Arguments:\r
+\r
+  Sd      - the global scratch data\r
+\r
+Returns:\r
+\r
+  The position value decoded.\r
+\r
+--*/\r
+{\r
+  UINT16  Val;\r
+  UINT32  Mask;\r
+  UINT32  Pos;\r
+\r
+  Val = Sd->mPTTable[Sd->mBitBuf >> (BITBUFSIZ - 8)];\r
+\r
+  if (Val >= MAXNP) {\r
+    Mask = 1U << (BITBUFSIZ - 1 - 8);\r
+\r
+    do {\r
+\r
+      if (Sd->mBitBuf & Mask) {\r
+        Val = Sd->mRight[Val];\r
+      } else {\r
+        Val = Sd->mLeft[Val];\r
+      }\r
+\r
+      Mask >>= 1;\r
+    } while (Val >= MAXNP);\r
+  }\r
+  //\r
+  // Advance what we have read\r
+  //\r
+  FillBuf (Sd, Sd->mPTLen[Val]);\r
+\r
+  Pos = Val;\r
+  if (Val > 1) {\r
+    Pos = (UINT32) ((1U << (Val - 1)) + GetBits (Sd, (UINT16) (Val - 1)));\r
+  }\r
+\r
+  return Pos;\r
+}\r
+\r
+STATIC\r
+UINT16\r
+ReadPTLen (\r
+  IN  SCRATCH_DATA  *Sd,\r
+  IN  UINT16        nn,\r
+  IN  UINT16        nbit,\r
+  IN  UINT16        Special\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Reads code lengths for the Extra Set or the Position Set\r
+\r
+Arguments:\r
+\r
+  Sd        - The global scratch data\r
+  nn        - Number of symbols\r
+  nbit      - Number of bits needed to represent nn\r
+  Special   - The special symbol that needs to be taken care of \r
+\r
+Returns:\r
+\r
+  0         - OK.\r
+  BAD_TABLE - Table is corrupted.\r
+\r
+--*/\r
+{\r
+  UINT16  Number;\r
+  UINT16  CharC;\r
+  UINT16  Index;\r
+  UINT32  Mask;\r
+\r
+  Number = (UINT16) GetBits (Sd, nbit);\r
+\r
+  if (Number == 0) {\r
+    CharC = (UINT16) GetBits (Sd, nbit);\r
+\r
+    for (Index = 0; Index < 256; Index++) {\r
+      Sd->mPTTable[Index] = CharC;\r
+    }\r
+\r
+    for (Index = 0; Index < nn; Index++) {\r
+      Sd->mPTLen[Index] = 0;\r
+    }\r
+\r
+    return 0;\r
+  }\r
+\r
+  Index = 0;\r
+\r
+  while (Index < Number) {\r
+\r
+    CharC = (UINT16) (Sd->mBitBuf >> (BITBUFSIZ - 3));\r
+\r
+    if (CharC == 7) {\r
+      Mask = 1U << (BITBUFSIZ - 1 - 3);\r
+      while (Mask & Sd->mBitBuf) {\r
+        Mask >>= 1;\r
+        CharC += 1;\r
+      }\r
+    }\r
+\r
+    FillBuf (Sd, (UINT16) ((CharC < 7) ? 3 : CharC - 3));\r
+\r
+    Sd->mPTLen[Index++] = (UINT8) CharC;\r
+\r
+    if (Index == Special) {\r
+      CharC = (UINT16) GetBits (Sd, 2);\r
+      CharC--;\r
+      while ((INT16) (CharC) >= 0) {\r
+        Sd->mPTLen[Index++] = 0;\r
+        CharC--;\r
+      }\r
+    }\r
+  }\r
+\r
+  while (Index < nn) {\r
+    Sd->mPTLen[Index++] = 0;\r
+  }\r
+\r
+  return MakeTable (Sd, nn, Sd->mPTLen, 8, Sd->mPTTable);\r
+}\r
+\r
+STATIC\r
+VOID\r
+ReadCLen (\r
+  SCRATCH_DATA  *Sd\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Reads code lengths for Char&Len Set.\r
+\r
+Arguments:\r
+\r
+  Sd    - the global scratch data\r
+\r
+Returns: (VOID)\r
+\r
+--*/\r
+{\r
+  UINT16  Number;\r
+  UINT16  CharC;\r
+  UINT16  Index;\r
+  UINT32  Mask;\r
+\r
+  Number = (UINT16) GetBits (Sd, CBIT);\r
+\r
+  if (Number == 0) {\r
+    CharC = (UINT16) GetBits (Sd, CBIT);\r
+\r
+    for (Index = 0; Index < NC; Index++) {\r
+      Sd->mCLen[Index] = 0;\r
+    }\r
+\r
+    for (Index = 0; Index < 4096; Index++) {\r
+      Sd->mCTable[Index] = CharC;\r
+    }\r
+\r
+    return ;\r
+  }\r
+\r
+  Index = 0;\r
+  while (Index < Number) {\r
+\r
+    CharC = Sd->mPTTable[Sd->mBitBuf >> (BITBUFSIZ - 8)];\r
+    if (CharC >= NT) {\r
+      Mask = 1U << (BITBUFSIZ - 1 - 8);\r
+\r
+      do {\r
+\r
+        if (Mask & Sd->mBitBuf) {\r
+          CharC = Sd->mRight[CharC];\r
+        } else {\r
+          CharC = Sd->mLeft[CharC];\r
+        }\r
+\r
+        Mask >>= 1;\r
+\r
+      } while (CharC >= NT);\r
+    }\r
+    //\r
+    // Advance what we have read\r
+    //\r
+    FillBuf (Sd, Sd->mPTLen[CharC]);\r
+\r
+    if (CharC <= 2) {\r
+\r
+      if (CharC == 0) {\r
+        CharC = 1;\r
+      } else if (CharC == 1) {\r
+        CharC = (UINT16) (GetBits (Sd, 4) + 3);\r
+      } else if (CharC == 2) {\r
+        CharC = (UINT16) (GetBits (Sd, CBIT) + 20);\r
+      }\r
+\r
+      CharC--;\r
+      while ((INT16) (CharC) >= 0) {\r
+        Sd->mCLen[Index++] = 0;\r
+        CharC--;\r
+      }\r
+\r
+    } else {\r
+\r
+      Sd->mCLen[Index++] = (UINT8) (CharC - 2);\r
+\r
+    }\r
+  }\r
+\r
+  while (Index < NC) {\r
+    Sd->mCLen[Index++] = 0;\r
+  }\r
+\r
+  MakeTable (Sd, NC, Sd->mCLen, 12, Sd->mCTable);\r
+\r
+  return ;\r
+}\r
+\r
+STATIC\r
+UINT16\r
+DecodeC (\r
+  SCRATCH_DATA  *Sd\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Decode a character/length value.\r
+\r
+Arguments:\r
+\r
+  Sd    - The global scratch data.\r
+\r
+Returns:\r
+\r
+  The value decoded.\r
+\r
+--*/\r
+{\r
+  UINT16  Index2;\r
+  UINT32  Mask;\r
+\r
+  if (Sd->mBlockSize == 0) {\r
+    //\r
+    // Starting a new block\r
+    //\r
+    Sd->mBlockSize    = (UINT16) GetBits (Sd, 16);\r
+    Sd->mBadTableFlag = ReadPTLen (Sd, NT, TBIT, 3);\r
+    if (Sd->mBadTableFlag != 0) {\r
+      return 0;\r
+    }\r
+\r
+    ReadCLen (Sd);\r
+\r
+    Sd->mBadTableFlag = ReadPTLen (Sd, MAXNP, PBIT, (UINT16) (-1));\r
+    if (Sd->mBadTableFlag != 0) {\r
+      return 0;\r
+    }\r
+  }\r
+\r
+  Sd->mBlockSize--;\r
+  Index2 = Sd->mCTable[Sd->mBitBuf >> (BITBUFSIZ - 12)];\r
+\r
+  if (Index2 >= NC) {\r
+    Mask = 1U << (BITBUFSIZ - 1 - 12);\r
+\r
+    do {\r
+      if (Sd->mBitBuf & Mask) {\r
+        Index2 = Sd->mRight[Index2];\r
+      } else {\r
+        Index2 = Sd->mLeft[Index2];\r
+      }\r
+\r
+      Mask >>= 1;\r
+    } while (Index2 >= NC);\r
+  }\r
+  //\r
+  // Advance what we have read\r
+  //\r
+  FillBuf (Sd, Sd->mCLen[Index2]);\r
+\r
+  return Index2;\r
+}\r
+\r
+STATIC\r
+VOID\r
+Decode (\r
+  SCRATCH_DATA  *Sd\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Decode the source data and put the resulting data into the destination buffer.\r
+\r
+Arguments:\r
+\r
+  Sd            - The global scratch data\r
+\r
+Returns: (VOID)\r
+\r
+ --*/\r
+{\r
+  UINT16  BytesRemain;\r
+  UINT32  DataIdx;\r
+  UINT16  CharC;\r
+\r
+  BytesRemain = (UINT16) (-1);\r
+\r
+  DataIdx     = 0;\r
+\r
+  for (;;) {\r
+    CharC = DecodeC (Sd);\r
+    if (Sd->mBadTableFlag != 0) {\r
+      return ;\r
+    }\r
+\r
+    if (CharC < 256) {\r
+      //\r
+      // Process an Original character\r
+      //\r
+      Sd->mDstBase[Sd->mOutBuf++] = (UINT8) CharC;\r
+      if (Sd->mOutBuf >= Sd->mOrigSize) {\r
+        return ;\r
+      }\r
+\r
+    } else {\r
+      //\r
+      // Process a Pointer\r
+      //\r
+      CharC       = (UINT16) (CharC - (UINT8_MAX + 1 - THRESHOLD));\r
+\r
+      BytesRemain = CharC;\r
+\r
+      DataIdx     = Sd->mOutBuf - DecodeP (Sd) - 1;\r
+\r
+      BytesRemain--;\r
+      while ((INT16) (BytesRemain) >= 0) {\r
+        Sd->mDstBase[Sd->mOutBuf++] = Sd->mDstBase[DataIdx++];\r
+        if (Sd->mOutBuf >= Sd->mOrigSize) {\r
+          return ;\r
+        }\r
+\r
+        BytesRemain--;\r
+      }\r
+    }\r
+  }\r
+\r
+  return ;\r
+}\r
+\r
+EFI_STATUS\r
+GetInfo (\r
+  IN      VOID    *Source,\r
+  IN      UINT32  SrcSize,\r
+  OUT     UINT32  *DstSize,\r
+  OUT     UINT32  *ScratchSize\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The implementation of EFI_DECOMPRESS_PROTOCOL.GetInfo().\r
+\r
+Arguments:\r
+\r
+  Source      - The source buffer containing the compressed data.\r
+  SrcSize     - The size of source buffer\r
+  DstSize     - The size of destination buffer.\r
+  ScratchSize - The size of scratch buffer.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - The size of destination buffer and the size of scratch buffer are successull retrieved.\r
+  EFI_INVALID_PARAMETER - The source data is corrupted\r
+\r
+--*/\r
+{\r
+  UINT8 *Src;\r
+\r
+  *ScratchSize  = sizeof (SCRATCH_DATA);\r
+\r
+  Src           = Source;\r
+  if (SrcSize < 8) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  *DstSize = Src[4] + (Src[5] << 8) + (Src[6] << 16) + (Src[7] << 24);\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+Decompress (\r
+  IN      VOID    *Source,\r
+  IN      UINT32  SrcSize,\r
+  IN OUT  VOID    *Destination,\r
+  IN      UINT32  DstSize,\r
+  IN OUT  VOID    *Scratch,\r
+  IN      UINT32  ScratchSize\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The implementation of EFI_DECOMPRESS_PROTOCOL.Decompress().\r
+\r
+Arguments:\r
+\r
+  This        - The protocol instance pointer\r
+  Source      - The source buffer containing the compressed data.\r
+  SrcSize     - The size of source buffer\r
+  Destination - The destination buffer to store the decompressed data\r
+  DstSize     - The size of destination buffer.\r
+  Scratch     - The buffer used internally by the decompress routine. This  buffer is needed to store intermediate data.\r
+  ScratchSize - The size of scratch buffer.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - Decompression is successfull\r
+  EFI_INVALID_PARAMETER - The source data is corrupted\r
+\r
+--*/\r
+{\r
+  UINT32        Index;\r
+  UINT32        CompSize;\r
+  UINT32        OrigSize;\r
+  EFI_STATUS    Status;\r
+  SCRATCH_DATA  *Sd;\r
+  UINT8         *Src;\r
+  UINT8         *Dst;\r
+\r
+  Status  = EFI_SUCCESS;\r
+  Src     = Source;\r
+  Dst     = Destination;\r
+\r
+  if (ScratchSize < sizeof (SCRATCH_DATA)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Sd = (SCRATCH_DATA *) Scratch;\r
+\r
+  if (SrcSize < 8) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  CompSize  = Src[0] + (Src[1] << 8) + (Src[2] << 16) + (Src[3] << 24);\r
+  OrigSize  = Src[4] + (Src[5] << 8) + (Src[6] << 16) + (Src[7] << 24);\r
+\r
+  if (SrcSize < CompSize + 8) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (DstSize != OrigSize) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Src = Src + 8;\r
+\r
+  for (Index = 0; Index < sizeof (SCRATCH_DATA); Index++) {\r
+    ((UINT8 *) Sd)[Index] = 0;\r
+  }\r
+\r
+  Sd->mSrcBase  = Src;\r
+  Sd->mDstBase  = Dst;\r
+  Sd->mCompSize = CompSize;\r
+  Sd->mOrigSize = OrigSize;\r
+\r
+  //\r
+  // Fill the first BITBUFSIZ bits\r
+  //\r
+  FillBuf (Sd, BITBUFSIZ);\r
+\r
+  //\r
+  // Decompress it\r
+  //\r
+  Decode (Sd);\r
+\r
+  if (Sd->mBadTableFlag != 0) {\r
+    //\r
+    // Something wrong with the source\r
+    //\r
+    Status = EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  return Status;\r
+}\r
diff --git a/Tools/CCode/Source/Common/EfiDecompress.h b/Tools/CCode/Source/Common/EfiDecompress.h
new file mode 100644 (file)
index 0000000..3f82ac6
--- /dev/null
@@ -0,0 +1,106 @@
+/*++\r
+\r
+Copyright (c) 2004, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+  \r
+  EfiDecompress.h\r
+\r
+Abstract:\r
+\r
+  Header file for compression routine\r
+  \r
+--*/\r
+\r
+#ifndef _EFI_DECOMPRESS_H\r
+#define _EFI_DECOMPRESS_H\r
+\r
+#include <Common/UefiBaseTypes.h>\r
+\r
+EFI_STATUS\r
+GetInfo (\r
+  IN      VOID    *Source,\r
+  IN      UINT32  SrcSize,\r
+  OUT     UINT32  *DstSize,\r
+  OUT     UINT32  *ScratchSize\r
+  );\r
+\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The implementation of EFI_DECOMPRESS_PROTOCOL.GetInfo().\r
+\r
+Arguments:\r
+\r
+  Source      - The source buffer containing the compressed data.\r
+  SrcSize     - The size of source buffer\r
+  DstSize     - The size of destination buffer.\r
+  ScratchSize - The size of scratch buffer.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - The size of destination buffer and the size of scratch buffer are successull retrieved.\r
+  EFI_INVALID_PARAMETER - The source data is corrupted\r
+\r
+--*/\r
+EFI_STATUS\r
+Decompress (\r
+  IN      VOID    *Source,\r
+  IN      UINT32  SrcSize,\r
+  IN OUT  VOID    *Destination,\r
+  IN      UINT32  DstSize,\r
+  IN OUT  VOID    *Scratch,\r
+  IN      UINT32  ScratchSize\r
+  )\r
+;\r
+\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The implementation of EFI_DECOMPRESS_PROTOCOL.Decompress().\r
+\r
+Arguments:\r
+\r
+  This        - The protocol instance pointer\r
+  Source      - The source buffer containing the compressed data.\r
+  SrcSize     - The size of source buffer\r
+  Destination - The destination buffer to store the decompressed data\r
+  DstSize     - The size of destination buffer.\r
+  Scratch     - The buffer used internally by the decompress routine. This  buffer is needed to store intermediate data.\r
+  ScratchSize - The size of scratch buffer.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - Decompression is successfull\r
+  EFI_INVALID_PARAMETER - The source data is corrupted\r
+\r
+--*/\r
+typedef\r
+EFI_STATUS\r
+(*GETINFO_FUNCTION) (\r
+  IN      VOID    *Source,\r
+  IN      UINT32  SrcSize,\r
+  OUT     UINT32  *DstSize,\r
+  OUT     UINT32  *ScratchSize\r
+  );\r
+\r
+typedef\r
+EFI_STATUS\r
+(*DECOMPRESS_FUNCTION) (\r
+  IN      VOID    *Source,\r
+  IN      UINT32  SrcSize,\r
+  IN OUT  VOID    *Destination,\r
+  IN      UINT32  DstSize,\r
+  IN OUT  VOID    *Scratch,\r
+  IN      UINT32  ScratchSize\r
+  );\r
+#endif\r
diff --git a/Tools/CCode/Source/Common/EfiUtilityMsgs.c b/Tools/CCode/Source/Common/EfiUtilityMsgs.c
new file mode 100644 (file)
index 0000000..566d214
--- /dev/null
@@ -0,0 +1,755 @@
+/*++\r
+\r
+Copyright (c) 2004, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:  \r
+\r
+  EfiUtilityMsgs.c\r
+  \r
+Abstract:\r
+\r
+  EFI tools utility functions to display warning, error, and informational\r
+  messages.\r
+  \r
+--*/\r
+\r
+#include <stdio.h>\r
+#include <string.h>\r
+#include <ctype.h>\r
+#include <stdarg.h>\r
+\r
+#include "EfiUtilityMsgs.h"\r
+\r
+#define MAX_LINE_LEN  200\r
+\r
+//\r
+// Declare module globals for keeping track of the the utility's\r
+// name and other settings.\r
+//\r
+static STATUS mStatus                 = STATUS_SUCCESS;\r
+static CHAR8  mUtilityName[50]        = { 0 };\r
+static UINT32 mDebugMsgMask           = 0;\r
+static CHAR8  *mSourceFileName        = NULL;\r
+static UINT32 mSourceFileLineNum      = 0;\r
+static UINT32 mErrorCount             = 0;\r
+static UINT32 mWarningCount           = 0;\r
+static UINT32 mMaxErrors              = 0;\r
+static UINT32 mMaxWarnings            = 0;\r
+static UINT32 mMaxWarningsPlusErrors  = 0;\r
+static INT8   mPrintLimitsSet         = 0;\r
+\r
+static\r
+void\r
+PrintMessage (\r
+  CHAR8   *Type,\r
+  CHAR8   *FileName,\r
+  UINT32  LineNumber,\r
+  UINT32  MessageCode,\r
+  CHAR8   *Text,\r
+  CHAR8   *MsgFmt,\r
+  va_list List\r
+  );\r
+\r
+static\r
+void\r
+PrintLimitExceeded (\r
+  VOID\r
+  );\r
+\r
+void\r
+Error (\r
+  CHAR8   *FileName,\r
+  UINT32  LineNumber,\r
+  UINT32  MessageCode,\r
+  CHAR8   *Text,\r
+  CHAR8   *MsgFmt,\r
+  ...\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Prints an error message.\r
+  \r
+Arguments:\r
+  All arguments are optional, though the printed message may be useless if\r
+  at least something valid is not specified.\r
+  \r
+  FileName - name of the file or application. If not specified, then the\r
+             utilty name (as set by the utility calling SetUtilityName()\r
+             earlier) is used. Otherwise "Unknown utility" is used.\r
+  \r
+  LineNumber - the line number of error, typically used by parsers. If the\r
+               utility is not a parser, then 0 should be specified. Otherwise\r
+               the FileName and LineNumber info can be used to cause\r
+               MS Visual Studio to jump to the error.\r
+               \r
+  MessageCode - an application-specific error code that can be referenced in\r
+              other documentation. \r
+\r
+  Text        - the text in question, typically used by parsers.\r
+  \r
+  MsgFmt - the format string for the error message. Can contain formatting\r
+           controls for use with the varargs.\r
+           \r
+Returns:\r
+  None.\r
+  \r
+Notes:\r
+  We print the following (similar to the Warn() and Debug() \r
+  W\r
+  Typical error/warning message format:\r
+\r
+  bin\VfrCompile.cpp(330) : error C2660: 'AddVfrDataStructField' : function does not take 2 parameters\r
+\r
+  BUGBUG -- these three utility functions are almost identical, and\r
+  should be modified to share code.\r
+\r
+  Visual Studio does not find error messages with:\r
+  \r
+     " error :"\r
+     " error 1:"\r
+     " error c1:"\r
+     " error 1000:"\r
+     " error c100:"\r
+\r
+  It does find:\r
+     " error c1000:"     \r
+--*/\r
+{\r
+  va_list List;\r
+  //\r
+  // If limits have been set, then check that we have not exceeded them\r
+  //\r
+  if (mPrintLimitsSet) {\r
+    //\r
+    // See if we've exceeded our total count\r
+    //\r
+    if (mMaxWarningsPlusErrors != 0) {\r
+      if (mErrorCount + mWarningCount > mMaxWarningsPlusErrors) {\r
+        PrintLimitExceeded ();\r
+        return ;\r
+      }\r
+    }\r
+    //\r
+    // See if we've exceeded our error count\r
+    //\r
+    if (mMaxErrors != 0) {\r
+      if (mErrorCount > mMaxErrors) {\r
+        PrintLimitExceeded ();\r
+        return ;\r
+      }\r
+    }\r
+  }\r
+\r
+  mErrorCount++;\r
+  va_start (List, MsgFmt);\r
+  PrintMessage ("error", FileName, LineNumber, MessageCode, Text, MsgFmt, List);\r
+  va_end (List);\r
+  //\r
+  // Set status accordingly\r
+  //\r
+  if (mStatus < STATUS_ERROR) {\r
+    mStatus = STATUS_ERROR;\r
+  }\r
+}\r
+\r
+void\r
+ParserError (\r
+  UINT32  MessageCode,\r
+  CHAR8   *Text,\r
+  CHAR8   *MsgFmt,\r
+  ...\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Print a parser error, using the source file name and line number\r
+  set by a previous call to SetParserPosition().\r
+\r
+Arguments:\r
+  MessageCode   - application-specific error code\r
+  Text          - text to print in the error message\r
+  MsgFmt        - format string to print at the end of the error message\r
+\r
+Returns:\r
+  NA\r
+\r
+--*/\r
+{\r
+  va_list List;\r
+  //\r
+  // If limits have been set, then check them\r
+  //\r
+  if (mPrintLimitsSet) {\r
+    //\r
+    // See if we've exceeded our total count\r
+    //\r
+    if (mMaxWarningsPlusErrors != 0) {\r
+      if (mErrorCount + mWarningCount > mMaxWarningsPlusErrors) {\r
+        PrintLimitExceeded ();\r
+        return ;\r
+      }\r
+    }\r
+    //\r
+    // See if we've exceeded our error count\r
+    //\r
+    if (mMaxErrors != 0) {\r
+      if (mErrorCount > mMaxErrors) {\r
+        PrintLimitExceeded ();\r
+        return ;\r
+      }\r
+    }\r
+  }\r
+\r
+  mErrorCount++;\r
+  va_start (List, MsgFmt);\r
+  PrintMessage ("error", mSourceFileName, mSourceFileLineNum, MessageCode, Text, MsgFmt, List);\r
+  va_end (List);\r
+  //\r
+  // Set status accordingly\r
+  //\r
+  if (mStatus < STATUS_ERROR) {\r
+    mStatus = STATUS_ERROR;\r
+  }\r
+}\r
+\r
+void\r
+ParserWarning (\r
+  UINT32  ErrorCode,\r
+  CHAR8   *OffendingText,\r
+  CHAR8   *MsgFmt,\r
+  ...\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Print a parser warning, using the source file name and line number\r
+  set by a previous call to SetParserPosition().\r
+\r
+Arguments:\r
+  ErrorCode     - application-specific error code\r
+  OffendingText - text to print in the warning message\r
+  MsgFmt        - format string to print at the end of the warning message\r
+\r
+Returns:\r
+  NA\r
+\r
+--*/\r
+{\r
+  va_list List;\r
+  //\r
+  // If limits have been set, then check them\r
+  //\r
+  if (mPrintLimitsSet) {\r
+    //\r
+    // See if we've exceeded our total count\r
+    //\r
+    if (mMaxWarningsPlusErrors != 0) {\r
+      if (mErrorCount + mWarningCount > mMaxWarningsPlusErrors) {\r
+        PrintLimitExceeded ();\r
+        return ;\r
+      }\r
+    }\r
+    //\r
+    // See if we've exceeded our warning count\r
+    //\r
+    if (mMaxWarnings != 0) {\r
+      if (mWarningCount > mMaxWarnings) {\r
+        PrintLimitExceeded ();\r
+        return ;\r
+      }\r
+    }\r
+  }\r
+\r
+  mWarningCount++;\r
+  va_start (List, MsgFmt);\r
+  PrintMessage ("warning", mSourceFileName, mSourceFileLineNum, ErrorCode, OffendingText, MsgFmt, List);\r
+  va_end (List);\r
+  //\r
+  // Set status accordingly\r
+  //\r
+  if (mStatus < STATUS_WARNING) {\r
+    mStatus = STATUS_WARNING;\r
+  }\r
+}\r
+\r
+void\r
+Warning (\r
+  CHAR8   *FileName,\r
+  UINT32  LineNumber,\r
+  UINT32  MessageCode,\r
+  CHAR8   *Text,\r
+  CHAR8   *MsgFmt,\r
+  ...\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Print a warning message.\r
+\r
+Arguments:\r
+  FileName    - name of the file where the warning was detected, or the name\r
+                of the application that detected the warning\r
+  \r
+  LineNumber  - the line number where the warning was detected (parsers).\r
+                0 should be specified if the utility is not a parser.\r
+               \r
+  MessageCode - an application-specific warning code that can be referenced in\r
+                other documentation. \r
+\r
+  Text        - the text in question (parsers)\r
+  \r
+  MsgFmt      - the format string for the warning message. Can contain formatting\r
+                controls for use with varargs.\r
+           \r
+Returns:\r
+  None.\r
+\r
+--*/\r
+{\r
+  va_list List;\r
+  //\r
+  // If limits have been set, then check them\r
+  //\r
+  if (mPrintLimitsSet) {\r
+    //\r
+    // See if we've exceeded our total count\r
+    //\r
+    if (mMaxWarningsPlusErrors != 0) {\r
+      if (mErrorCount + mWarningCount > mMaxWarningsPlusErrors) {\r
+        PrintLimitExceeded ();\r
+        return ;\r
+      }\r
+    }\r
+    //\r
+    // See if we've exceeded our warning count\r
+    //\r
+    if (mMaxWarnings != 0) {\r
+      if (mWarningCount > mMaxWarnings) {\r
+        PrintLimitExceeded ();\r
+        return ;\r
+      }\r
+    }\r
+  }\r
+\r
+  mWarningCount++;\r
+  va_start (List, MsgFmt);\r
+  PrintMessage ("warning", FileName, LineNumber, MessageCode, Text, MsgFmt, List);\r
+  va_end (List);\r
+  //\r
+  // Set status accordingly\r
+  //\r
+  if (mStatus < STATUS_WARNING) {\r
+    mStatus = STATUS_WARNING;\r
+  }\r
+}\r
+\r
+void\r
+DebugMsg (\r
+  CHAR8   *FileName,\r
+  UINT32  LineNumber,\r
+  UINT32  MsgMask,\r
+  CHAR8   *Text,\r
+  CHAR8   *MsgFmt,\r
+  ...\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Print a warning message.\r
+\r
+Arguments:\r
+  FileName    - typically the name of the utility printing the debug message, but\r
+                can be the name of a file being parsed.\r
+  \r
+  LineNumber  - the line number in FileName (parsers) \r
+               \r
+  MsgMask     - an application-specific bitmask that, in combination with mDebugMsgMask,\r
+                determines if the debug message gets printed.\r
+\r
+  Text        - the text in question (parsers)\r
+  \r
+  MsgFmt      - the format string for the debug message. Can contain formatting\r
+                controls for use with varargs.\r
+           \r
+Returns:\r
+  None.\r
+\r
+--*/\r
+{\r
+  va_list List;\r
+  //\r
+  // If the debug mask is not applicable, then do nothing.\r
+  //\r
+  if ((MsgMask != 0) && ((mDebugMsgMask & MsgMask) == 0)) {\r
+    return ;\r
+  }\r
+\r
+  va_start (List, MsgFmt);\r
+  PrintMessage ("debug", FileName, LineNumber, 0, Text, MsgFmt, List);\r
+  va_end (List);\r
+}\r
+\r
+static\r
+void\r
+PrintMessage (\r
+  CHAR8   *Type,\r
+  CHAR8   *FileName,\r
+  UINT32  LineNumber,\r
+  UINT32  MessageCode,\r
+  CHAR8   *Text,\r
+  CHAR8   *MsgFmt,\r
+  va_list List\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Worker routine for all the utility printing services. Prints the message in\r
+  a format that Visual Studio will find when scanning build outputs for\r
+  errors or warnings.\r
+\r
+Arguments:\r
+  Type        - "warning" or "error" string to insert into the message to be\r
+                printed. The first character of this string (converted to uppercase)\r
+                is used to preceed the MessageCode value in the output string.\r
+\r
+  FileName    - name of the file where the warning was detected, or the name\r
+                of the application that detected the warning\r
+  \r
+  LineNumber  - the line number where the warning was detected (parsers).\r
+                0 should be specified if the utility is not a parser.\r
+               \r
+  MessageCode - an application-specific warning code that can be referenced in\r
+                other documentation. \r
+\r
+  Text        - part of the message to print\r
+  \r
+  MsgFmt      - the format string for the message. Can contain formatting\r
+                controls for use with varargs.\r
+  List        - the variable list.\r
+           \r
+Returns:\r
+  None.\r
+\r
+Notes:\r
+  If FileName == NULL then this utility will use the string passed into SetUtilityName(). \r
+  \r
+  LineNumber is only used if the caller is a parser, in which case FileName refers to the\r
+  file being parsed.\r
+\r
+  Text and MsgFmt are both optional, though it would be of little use calling this function with\r
+  them both NULL.\r
+\r
+  Output will typically be of the form:\r
+    <FileName>(<LineNumber>) : <Type> <Type[0]><MessageCode>: <Text> : <MsgFmt>\r
+\r
+    Parser (LineNumber != 0)\r
+      VfrCompile.cpp(330) : error E2660: AddVfrDataStructField : function does not take 2 parameters\r
+    Generic utility (LineNumber == 0) \r
+      UtilityName : error E1234 : Text string : MsgFmt string and args\r
+\r
+--*/\r
+{\r
+  CHAR8 Line[MAX_LINE_LEN];\r
+  CHAR8 Line2[MAX_LINE_LEN];\r
+  CHAR8 *Cptr;\r
+  //\r
+  // If given a filename, then add it (and the line number) to the string.\r
+  // If there's no filename, then use the program name if provided.\r
+  //\r
+  if (FileName != NULL) {\r
+    Cptr = FileName;\r
+  } else if (mUtilityName[0] != 0) {\r
+    Cptr = mUtilityName;\r
+  } else {\r
+    Cptr = "Unknown utility";\r
+  }\r
+\r
+  strcpy (Line, Cptr);\r
+  if (LineNumber != 0) {\r
+    sprintf (Line2, "(%d)", LineNumber);\r
+    strcat (Line, Line2);\r
+  }\r
+  //\r
+  // Have to print an error code or Visual Studio won't find the\r
+  // message for you. It has to be decimal digits too.\r
+  //\r
+  sprintf (Line2, " : %s %c%04d", Type, toupper (Type[0]), MessageCode);\r
+  strcat (Line, Line2);\r
+  fprintf (stdout, "%s", Line);\r
+  //\r
+  // If offending text was provided, then print it\r
+  //\r
+  if (Text != NULL) {\r
+    fprintf (stdout, ": %s ", Text);\r
+  }\r
+  //\r
+  // Print formatted message if provided\r
+  //\r
+  if (MsgFmt != NULL) {\r
+    vsprintf (Line2, MsgFmt, List);\r
+    fprintf (stdout, ": %s", Line2);\r
+  }\r
+\r
+  fprintf (stdout, "\n");\r
+}\r
+\r
+void\r
+ParserSetPosition (\r
+  CHAR8   *SourceFileName,\r
+  UINT32  LineNum\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Set the position in a file being parsed. This can be used to \r
+  print error messages deeper down in a parser.\r
+\r
+Arguments:\r
+  SourceFileName - name of the source file being parsed\r
+  LineNum        - line number of the source file being parsed\r
+\r
+Returns:\r
+  NA\r
+\r
+--*/\r
+{\r
+  mSourceFileName     = SourceFileName;\r
+  mSourceFileLineNum  = LineNum;\r
+}\r
+\r
+void\r
+SetUtilityName (\r
+  CHAR8   *UtilityName\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  All printed error/warning/debug messages follow the same format, and\r
+  typically will print a filename or utility name followed by the error\r
+  text. However if a filename is not passed to the print routines, then\r
+  they'll print the utility name if you call this function early in your\r
+  app to set the utility name.\r
+  \r
+Arguments:\r
+  UtilityName  -  name of the utility, which will be printed with all\r
+                  error/warning/debug messags.\r
+\r
+Returns:\r
+  NA\r
+  \r
+--*/\r
+{\r
+  //\r
+  // Save the name of the utility in our local variable. Make sure its\r
+  // length does not exceed our buffer.\r
+  //\r
+  if (UtilityName != NULL) {\r
+    if (strlen (UtilityName) >= sizeof (mUtilityName)) {\r
+      Error (UtilityName, 0, 0, "application error", "utility name length exceeds internal buffer size");\r
+      strncpy (mUtilityName, UtilityName, sizeof (mUtilityName) - 1);\r
+      mUtilityName[sizeof (mUtilityName) - 1] = 0;\r
+      return ;\r
+    } else {\r
+      strcpy (mUtilityName, UtilityName);\r
+    }\r
+  } else {\r
+    Error (NULL, 0, 0, "application error", "SetUtilityName() called with NULL utility name");\r
+  }\r
+}\r
+\r
+STATUS\r
+GetUtilityStatus (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  When you call Error() or Warning(), this module keeps track of it and\r
+  sets a local mStatus to STATUS_ERROR or STATUS_WARNING. When the utility\r
+  exits, it can call this function to get the status and use it as a return\r
+  value.\r
+  \r
+Arguments:\r
+  None.\r
+\r
+Returns:\r
+  Worst-case status reported, as defined by which print function was called.\r
+  \r
+--*/\r
+{\r
+  return mStatus;\r
+}\r
+\r
+void\r
+SetDebugMsgMask (\r
+  UINT32  DebugMask\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Set the debug printing mask. This is used by the DebugMsg() function\r
+  to determine when/if a debug message should be printed.\r
+\r
+Arguments:\r
+  DebugMask  - bitmask, specific to the calling application\r
+\r
+Returns:\r
+  NA\r
+\r
+--*/\r
+{\r
+  mDebugMsgMask = DebugMask;\r
+}\r
+\r
+void\r
+SetPrintLimits (\r
+  UINT32  MaxErrors,\r
+  UINT32  MaxWarnings,\r
+  UINT32  MaxWarningsPlusErrors\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Set the limits of how many errors, warnings, and errors+warnings\r
+  we will print.\r
+\r
+Arguments:\r
+  MaxErrors       - maximum number of error messages to print\r
+  MaxWarnings     - maximum number of warning messages to print\r
+  MaxWarningsPlusErrors \r
+                  - maximum number of errors+warnings to print\r
+\r
+Returns:\r
+  NA\r
+\r
+--*/\r
+{\r
+  mMaxErrors              = MaxErrors;\r
+  mMaxWarnings            = MaxWarnings;\r
+  mMaxWarningsPlusErrors  = MaxWarningsPlusErrors;\r
+  mPrintLimitsSet         = 1;\r
+}\r
+\r
+static\r
+void\r
+PrintLimitExceeded (\r
+  VOID\r
+  )\r
+{\r
+  static INT8 mPrintLimitExceeded = 0;\r
+  //\r
+  // If we've already printed the message, do nothing. Otherwise\r
+  // temporarily increase our print limits so we can pass one\r
+  // more message through.\r
+  //\r
+  if (mPrintLimitExceeded == 0) {\r
+    mPrintLimitExceeded++;\r
+    mMaxErrors++;\r
+    mMaxWarnings++;\r
+    mMaxWarningsPlusErrors++;\r
+    Error (NULL, 0, 0, "error/warning print limit exceeded", NULL);\r
+    mMaxErrors--;\r
+    mMaxWarnings--;\r
+    mMaxWarningsPlusErrors--;\r
+  }\r
+}\r
+\r
+#if 0\r
+void\r
+TestUtilityMessages (\r
+  VOID\r
+  )\r
+{\r
+  char *ArgStr = "ArgString";\r
+  int  ArgInt;\r
+\r
+  ArgInt  = 0x12345678;\r
+  //\r
+  // Test without setting utility name\r
+  //\r
+  fprintf (stdout, "* Testing without setting utility name\n");\r
+  fprintf (stdout, "** Test debug message not printed\n");\r
+  DebugMsg (NULL, 0, 0x00000001, NULL, NULL);\r
+  fprintf (stdout, "** Test warning with two strings and two args\n");\r
+  Warning (NULL, 0, 1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r
+  fprintf (stdout, "** Test error with two strings and two args\n");\r
+  Warning (NULL, 0, 1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r
+  fprintf (stdout, "** Test parser warning with nothing\n");\r
+  ParserWarning (0, NULL, NULL);\r
+  fprintf (stdout, "** Test parser error with nothing\n");\r
+  ParserError (0, NULL, NULL);\r
+  //\r
+  // Test with utility name set now\r
+  //\r
+  fprintf (stdout, "** Testingin with utility name set\n");\r
+  SetUtilityName ("MyUtilityName");\r
+  //\r
+  // Test debug prints\r
+  //\r
+  SetDebugMsgMask (2);\r
+  fprintf (stdout, "** Test debug message with one string\n");\r
+  DebugMsg (NULL, 0, 0x00000002, "Text1", NULL);\r
+  fprintf (stdout, "** Test debug message with one string\n");\r
+  DebugMsg (NULL, 0, 0x00000002, NULL, "Text2");\r
+  fprintf (stdout, "** Test debug message with two strings\n");\r
+  DebugMsg (NULL, 0, 0x00000002, "Text1", "Text2");\r
+  fprintf (stdout, "** Test debug message with two strings and two args\n");\r
+  DebugMsg (NULL, 0, 0x00000002, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r
+  //\r
+  // Test warning prints\r
+  //\r
+  fprintf (stdout, "** Test warning with no strings\n");\r
+  Warning (NULL, 0, 1234, NULL, NULL);\r
+  fprintf (stdout, "** Test warning with one string\n");\r
+  Warning (NULL, 0, 1234, "Text1", NULL);\r
+  fprintf (stdout, "** Test warning with one string\n");\r
+  Warning (NULL, 0, 1234, NULL, "Text2");\r
+  fprintf (stdout, "** Test warning with two strings and two args\n");\r
+  Warning (NULL, 0, 1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r
+  //\r
+  // Test error prints\r
+  //\r
+  fprintf (stdout, "** Test error with no strings\n");\r
+  Error (NULL, 0, 1234, NULL, NULL);\r
+  fprintf (stdout, "** Test error with one string\n");\r
+  Error (NULL, 0, 1234, "Text1", NULL);\r
+  fprintf (stdout, "** Test error with one string\n");\r
+  Error (NULL, 0, 1234, NULL, "Text2");\r
+  fprintf (stdout, "** Test error with two strings and two args\n");\r
+  Error (NULL, 0, 1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r
+  //\r
+  // Test parser prints\r
+  //\r
+  fprintf (stdout, "** Test parser errors\n");\r
+  ParserSetPosition (__FILE__, __LINE__ + 1);\r
+  ParserError (1234, NULL, NULL);\r
+  ParserSetPosition (__FILE__, __LINE__ + 1);\r
+  ParserError (1234, "Text1", NULL);\r
+  ParserSetPosition (__FILE__, __LINE__ + 1);\r
+  ParserError (1234, NULL, "Text2");\r
+  ParserSetPosition (__FILE__, __LINE__ + 1);\r
+  ParserError (1234, "Text1", "Text2");\r
+  ParserSetPosition (__FILE__, __LINE__ + 1);\r
+  ParserError (1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r
+\r
+  fprintf (stdout, "** Test parser warnings\n");\r
+  ParserSetPosition (__FILE__, __LINE__ + 1);\r
+  ParserWarning (4321, NULL, NULL);\r
+  ParserSetPosition (__FILE__, __LINE__ + 1);\r
+  ParserWarning (4321, "Text1", NULL);\r
+  ParserSetPosition (__FILE__, __LINE__ + 1);\r
+  ParserWarning (4321, NULL, "Text2");\r
+  ParserSetPosition (__FILE__, __LINE__ + 1);\r
+  ParserWarning (4321, "Text1", "Text2");\r
+  ParserSetPosition (__FILE__, __LINE__ + 1);\r
+  ParserWarning (4321, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);\r
+}\r
+#endif\r
diff --git a/Tools/CCode/Source/Common/EfiUtilityMsgs.h b/Tools/CCode/Source/Common/EfiUtilityMsgs.h
new file mode 100644 (file)
index 0000000..a76b822
--- /dev/null
@@ -0,0 +1,137 @@
+/*++\r
+\r
+Copyright (c) 2004, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  EfiUtilityMsgs.h\r
+\r
+Abstract:\r
+\r
+  Defines and prototypes for common EFI utility error and debug messages.\r
+  \r
+--*/\r
+\r
+#ifndef _EFI_UTILITY_MSGS_H_\r
+#define _EFI_UTILITY_MSGS_H_\r
+\r
+#include <Common/UefiBaseTypes.h>\r
+\r
+//\r
+// Status codes returned by EFI utility programs and functions\r
+//\r
+#define STATUS_SUCCESS  0\r
+#define STATUS_WARNING  1\r
+#define STATUS_ERROR    2\r
+#define VOID void \r
+\r
+typedef int STATUS;\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+//\r
+// When we call Error() or Warning(), the module keeps track of the worst\r
+// case reported. GetUtilityStatus() will get the worst-case results, which\r
+// can be used as the return value from the app.\r
+//\r
+STATUS\r
+GetUtilityStatus (\r
+  void\r
+  );\r
+\r
+//\r
+// If someone prints an error message and didn't specify a source file name,\r
+// then we print the utility name instead. However they must tell us the\r
+// utility name early on via this function.\r
+//\r
+void\r
+SetUtilityName (\r
+  CHAR8 *ProgramName\r
+  )\r
+;\r
+\r
+void\r
+Error (\r
+  CHAR8   *FileName,\r
+  UINT32  LineNumber,\r
+  UINT32  ErrorCode,\r
+  CHAR8   *OffendingText,\r
+  CHAR8   *MsgFmt,\r
+  ...\r
+  )\r
+;\r
+\r
+void\r
+Warning (\r
+  CHAR8   *FileName,\r
+  UINT32  LineNumber,\r
+  UINT32  ErrorCode,\r
+  CHAR8   *OffendingText,\r
+  CHAR8   *MsgFmt,\r
+  ...\r
+  )\r
+;\r
+\r
+void\r
+DebugMsg (\r
+  CHAR8   *FileName,\r
+  UINT32  LineNumber,\r
+  UINT32  MsgLevel,\r
+  CHAR8   *OffendingText,\r
+  CHAR8   *MsgFmt,\r
+  ...\r
+  )\r
+;\r
+\r
+void\r
+SetDebugMsgMask (\r
+  UINT32    MsgMask\r
+  )\r
+;\r
+\r
+void\r
+ParserSetPosition (\r
+  CHAR8   *SourceFileName,\r
+  UINT32  LineNum\r
+  )\r
+;\r
+\r
+void\r
+ParserError (\r
+  UINT32  ErrorCode,\r
+  CHAR8   *OffendingText,\r
+  CHAR8   *MsgFmt,\r
+  ...\r
+  )\r
+;\r
+\r
+void\r
+ParserWarning (\r
+  UINT32  ErrorCode,\r
+  CHAR8   *OffendingText,\r
+  CHAR8   *MsgFmt,\r
+  ...\r
+  )\r
+;\r
+\r
+void\r
+SetPrintLimits (\r
+  UINT32  NumErrors,\r
+  UINT32  NumWarnings,\r
+  UINT32  NumWarningsPlusErrors\r
+  )\r
+;\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif // #ifndef _EFI_UTILITY_MSGS_H_\r
diff --git a/Tools/CCode/Source/Common/FvLib.c b/Tools/CCode/Source/Common/FvLib.c
new file mode 100644 (file)
index 0000000..e8d6279
--- /dev/null
@@ -0,0 +1,780 @@
+/*++\r
+\r
+Copyright (c) 2004, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  FvLib.c\r
+\r
+Abstract:\r
+\r
+  These functions assist in parsing and manipulating a Firmware Volume.\r
+\r
+--*/\r
+\r
+//\r
+// Include files\r
+//\r
+#include "FvLib.h"\r
+#include "CommonLib.h"\r
+#include "EfiUtilityMsgs.h"\r
+\r
+//\r
+// Module global variables\r
+//\r
+EFI_FIRMWARE_VOLUME_HEADER  *mFvHeader  = NULL;\r
+UINT32                      mFvLength   = 0;\r
+\r
+//\r
+// External function implementations\r
+//\r
+EFI_STATUS\r
+InitializeFvLib (\r
+  IN VOID                         *Fv,\r
+  IN UINT32                       FvLength\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This initializes the FV lib with a pointer to the FV and length.  It does not\r
+  verify the FV in any way.\r
+\r
+Arguments:\r
+\r
+  Fv            Buffer containing the FV.\r
+  FvLength      Length of the FV\r
+    \r
+Returns:\r
\r
+  EFI_SUCCESS             Function Completed successfully.\r
+  EFI_INVALID_PARAMETER   A required parameter was NULL.\r
+\r
+--*/\r
+{\r
+  //\r
+  // Verify input arguments\r
+  //\r
+  if (Fv == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  mFvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) Fv;\r
+  mFvLength = FvLength;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+GetFvHeader (\r
+  OUT EFI_FIRMWARE_VOLUME_HEADER  **FvHeader,\r
+  OUT UINT32                      *FvLength\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This function returns a pointer to the current FV and the size.\r
+\r
+Arguments:\r
+\r
+  FvHeader      Pointer to the FV buffer.\r
+  FvLength      Length of the FV\r
+    \r
+Returns:\r
\r
+  EFI_SUCCESS             Function Completed successfully.\r
+  EFI_INVALID_PARAMETER   A required parameter was NULL.\r
+  EFI_ABORTED             The library needs to be initialized.\r
+\r
+--*/\r
+{\r
+  //\r
+  // Verify library has been initialized.\r
+  //\r
+  if (mFvHeader == NULL || mFvLength == 0) {\r
+    return EFI_ABORTED;\r
+  }\r
+  //\r
+  // Verify input arguments\r
+  //\r
+  if (FvHeader == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  *FvHeader = mFvHeader;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+GetNextFile (\r
+  IN EFI_FFS_FILE_HEADER          *CurrentFile,\r
+  OUT EFI_FFS_FILE_HEADER         **NextFile\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This function returns the next file.  If the current file is NULL, it returns\r
+  the first file in the FV.  If the function returns EFI_SUCCESS and the file \r
+  pointer is NULL, then there are no more files in the FV.\r
+\r
+Arguments:\r
+\r
+  CurrentFile   Pointer to the current file, must be within the current FV.\r
+  NextFile      Pointer to the next file in the FV.\r
+    \r
+Returns:\r
\r
+  EFI_SUCCESS             Function completed successfully.\r
+  EFI_INVALID_PARAMETER   A required parameter was NULL or is out of range.\r
+  EFI_ABORTED             The library needs to be initialized.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // Verify library has been initialized.\r
+  //\r
+  if (mFvHeader == NULL || mFvLength == 0) {\r
+    return EFI_ABORTED;\r
+  }\r
+  //\r
+  // Verify input arguments\r
+  //\r
+  if (NextFile == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  //\r
+  // Verify FV header\r
+  //\r
+  Status = VerifyFv (mFvHeader);\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_ABORTED;\r
+  }\r
+  //\r
+  // Get first file\r
+  //\r
+  if (CurrentFile == NULL) {\r
+    CurrentFile = (EFI_FFS_FILE_HEADER *) ((UINTN) mFvHeader + mFvHeader->HeaderLength);\r
+\r
+    //\r
+    // Verify file is valid\r
+    //\r
+    Status = VerifyFfsFile (CurrentFile);\r
+    if (EFI_ERROR (Status)) {\r
+      //\r
+      // no files in this FV\r
+      //\r
+      *NextFile = NULL;\r
+      return EFI_SUCCESS;\r
+    } else {\r
+      //\r
+      // Verify file is in this FV.\r
+      //\r
+      if ((UINTN) CurrentFile >= (UINTN) mFvHeader + mFvLength - sizeof (EFI_FFS_FILE_HEADER)) {\r
+        *NextFile = NULL;\r
+        return EFI_SUCCESS;\r
+      }\r
+\r
+      *NextFile = CurrentFile;\r
+      return EFI_SUCCESS;\r
+    }\r
+  }\r
+  //\r
+  // Verify current file is in range\r
+  //\r
+  if (((UINTN) CurrentFile < (UINTN) mFvHeader + sizeof (EFI_FIRMWARE_VOLUME_HEADER)) ||\r
+      ((UINTN) CurrentFile >= (UINTN) mFvHeader + mFvLength - sizeof (EFI_FIRMWARE_VOLUME_HEADER))\r
+      ) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  //\r
+  // Get next file, compensate for 8 byte alignment if necessary.\r
+  //\r
+  *NextFile = (EFI_FFS_FILE_HEADER *) (((UINTN) CurrentFile + GetLength (CurrentFile->Size) + 0x07) & (-1 << 3));\r
+\r
+  //\r
+  // Verify file is in this FV.\r
+  //\r
+  if ((UINTN) *NextFile >= (UINTN) mFvHeader + mFvLength - sizeof (EFI_FFS_FILE_HEADER)) {\r
+    *NextFile = NULL;\r
+    return EFI_SUCCESS;\r
+  }\r
+  //\r
+  // Verify file is valid\r
+  //\r
+  Status = VerifyFfsFile (*NextFile);\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // no more files in this FV\r
+    //\r
+    *NextFile = NULL;\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+GetFileByName (\r
+  IN EFI_GUID                     *FileName,\r
+  OUT EFI_FFS_FILE_HEADER         **File\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Find a file by name.  The function will return NULL if the file is not found.\r
+\r
+Arguments:\r
+\r
+  FileName    The GUID file name of the file to search for.\r
+  File        Return pointer.  In the case of an error, contents are undefined.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS             The function completed successfully.\r
+  EFI_ABORTED             An error was encountered.\r
+  EFI_INVALID_PARAMETER   One of the parameters was NULL.\r
+\r
+--*/\r
+{\r
+  EFI_FFS_FILE_HEADER *CurrentFile;\r
+  EFI_STATUS          Status;\r
+\r
+  //\r
+  // Verify library has been initialized.\r
+  //\r
+  if (mFvHeader == NULL || mFvLength == 0) {\r
+    return EFI_ABORTED;\r
+  }\r
+  //\r
+  // Verify input parameters\r
+  //\r
+  if (FileName == NULL || File == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  //\r
+  // Verify FV header\r
+  //\r
+  Status = VerifyFv (mFvHeader);\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_ABORTED;\r
+  }\r
+  //\r
+  // Get the first file\r
+  //\r
+  Status = GetNextFile (NULL, &CurrentFile);\r
+  if (EFI_ERROR (Status)) {\r
+    Error (NULL, 0, 0, "error parsing the FV", NULL);\r
+    return EFI_ABORTED;\r
+  }\r
+  //\r
+  // Loop as long as we have a valid file\r
+  //\r
+  while (CurrentFile) {\r
+    if (!CompareGuid (&CurrentFile->Name, FileName)) {\r
+      *File = CurrentFile;\r
+      return EFI_SUCCESS;\r
+    }\r
+\r
+    Status = GetNextFile (CurrentFile, &CurrentFile);\r
+    if (EFI_ERROR (Status)) {\r
+      Error (NULL, 0, 0, "error parsing the FV", NULL);\r
+      return EFI_ABORTED;\r
+    }\r
+  }\r
+  //\r
+  // File not found in this FV.\r
+  //\r
+  *File = NULL;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+GetFileByType (\r
+  IN EFI_FV_FILETYPE              FileType,\r
+  IN UINTN                        Instance,\r
+  OUT EFI_FFS_FILE_HEADER         **File\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Find a file by type and instance.  An instance of 1 is the first instance.\r
+  The function will return NULL if a matching file cannot be found.\r
+  File type EFI_FV_FILETYPE_ALL means any file type is valid.\r
+\r
+Arguments:\r
+\r
+  FileType    Type of file to search for.\r
+  Instance    Instace of the file type to return.\r
+  File        Return pointer.  In the case of an error, contents are undefined.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS             The function completed successfully.\r
+  EFI_ABORTED             An error was encountered.\r
+  EFI_INVALID_PARAMETER   One of the parameters was NULL.\r
+\r
+--*/\r
+{\r
+  EFI_FFS_FILE_HEADER *CurrentFile;\r
+  EFI_STATUS          Status;\r
+  UINTN               FileCount;\r
+\r
+  //\r
+  // Verify library has been initialized.\r
+  //\r
+  if (mFvHeader == NULL || mFvLength == 0) {\r
+    return EFI_ABORTED;\r
+  }\r
+  //\r
+  // Verify input parameters\r
+  //\r
+  if (File == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  //\r
+  // Verify FV header\r
+  //\r
+  Status = VerifyFv (mFvHeader);\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_ABORTED;\r
+  }\r
+  //\r
+  // Initialize the number of matching files found.\r
+  //\r
+  FileCount = 0;\r
+\r
+  //\r
+  // Get the first file\r
+  //\r
+  Status = GetNextFile (NULL, &CurrentFile);\r
+  if (EFI_ERROR (Status)) {\r
+    Error (NULL, 0, 0, "error parsing FV", NULL);\r
+    return EFI_ABORTED;\r
+  }\r
+  //\r
+  // Loop as long as we have a valid file\r
+  //\r
+  while (CurrentFile) {\r
+    if (FileType == EFI_FV_FILETYPE_ALL || CurrentFile->Type == FileType) {\r
+      FileCount++;\r
+    }\r
+\r
+    if (FileCount == Instance) {\r
+      *File = CurrentFile;\r
+      return EFI_SUCCESS;\r
+    }\r
+\r
+    Status = GetNextFile (CurrentFile, &CurrentFile);\r
+    if (EFI_ERROR (Status)) {\r
+      Error (NULL, 0, 0, "error parsing the FV", NULL);\r
+      return EFI_ABORTED;\r
+    }\r
+  }\r
+\r
+  *File = NULL;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+GetSectionByType (\r
+  IN EFI_FFS_FILE_HEADER          *File,\r
+  IN EFI_SECTION_TYPE             SectionType,\r
+  IN UINTN                        Instance,\r
+  OUT EFI_FILE_SECTION_POINTER    *Section\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Find a section in a file by type and instance.  An instance of 1 is the first \r
+  instance.  The function will return NULL if a matching section cannot be found.\r
+  The function will not handle encapsulating sections.\r
+\r
+Arguments:\r
+\r
+  File        The file to search.\r
+  SectionType Type of file to search for.\r
+  Instance    Instace of the section to return.\r
+  Section     Return pointer.  In the case of an error, contents are undefined.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS             The function completed successfully.\r
+  EFI_ABORTED             An error was encountered.\r
+  EFI_INVALID_PARAMETER   One of the parameters was NULL.\r
+  EFI_NOT_FOUND           No found.\r
+--*/\r
+{\r
+  EFI_FILE_SECTION_POINTER  CurrentSection;\r
+  EFI_STATUS                Status;\r
+  UINTN                     SectionCount;\r
+\r
+  //\r
+  // Verify input parameters\r
+  //\r
+  if (File == NULL || Instance == 0) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  //\r
+  // Verify FFS header\r
+  //\r
+  Status = VerifyFfsFile (File);\r
+  if (EFI_ERROR (Status)) {\r
+    Error (NULL, 0, 0, "invalid FFS file", NULL);\r
+    return EFI_ABORTED;\r
+  }\r
+  //\r
+  // Initialize the number of matching sections found.\r
+  //\r
+  SectionCount = 0;\r
+\r
+  //\r
+  // Get the first section\r
+  //\r
+  CurrentSection.CommonHeader = (EFI_COMMON_SECTION_HEADER *) ((UINTN) File + sizeof (EFI_FFS_FILE_HEADER));\r
+\r
+  //\r
+  // Loop as long as we have a valid file\r
+  //\r
+  while ((UINTN) CurrentSection.CommonHeader < (UINTN) File + GetLength (File->Size)) {\r
+    if (CurrentSection.CommonHeader->Type == SectionType) {\r
+      SectionCount++;\r
+    }\r
+\r
+    if (SectionCount == Instance) {\r
+      *Section = CurrentSection;\r
+      return EFI_SUCCESS;\r
+    }\r
+    //\r
+    // Find next section (including compensating for alignment issues.\r
+    //\r
+    CurrentSection.CommonHeader = (EFI_COMMON_SECTION_HEADER *) ((((UINTN) CurrentSection.CommonHeader) + GetLength (CurrentSection.CommonHeader->Size) + 0x03) & (-1 << 2));\r
+  }\r
+  //\r
+  // Section not found\r
+  //\r
+  (*Section).Code16Section = NULL;\r
+  return EFI_NOT_FOUND;\r
+}\r
+//\r
+// will not parse compressed sections\r
+//\r
+EFI_STATUS\r
+VerifyFv (\r
+  IN EFI_FIRMWARE_VOLUME_HEADER   *FvHeader\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Verify the current pointer points to a valid FV header.\r
+\r
+Arguments:\r
+\r
+  FvHeader     Pointer to an alleged FV file.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS             The FV header is valid.\r
+  EFI_VOLUME_CORRUPTED    The FV header is not valid.\r
+  EFI_INVALID_PARAMETER   A required parameter was NULL.\r
+  EFI_ABORTED             Operation aborted.\r
+\r
+--*/\r
+{\r
+  UINT16  Checksum;\r
+\r
+  //\r
+  // Verify input parameters\r
+  //\r
+  if (FvHeader == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (FvHeader->Signature != EFI_FVH_SIGNATURE) {\r
+    Error (NULL, 0, 0, "invalid FV header signature", NULL);\r
+    return EFI_VOLUME_CORRUPTED;\r
+  }\r
+  //\r
+  // Verify header checksum\r
+  //\r
+  Checksum = CalculateSum16 ((UINT16 *) FvHeader, FvHeader->HeaderLength / sizeof (UINT16));\r
+\r
+  if (Checksum != 0) {\r
+    Error (NULL, 0, 0, "invalid FV header checksum", NULL);\r
+    return EFI_ABORTED;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+VerifyFfsFile (\r
+  IN EFI_FFS_FILE_HEADER  *FfsHeader\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Verify the current pointer points to a FFS file header.\r
+\r
+Arguments:\r
+\r
+  FfsHeader     Pointer to an alleged FFS file.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           The Ffs header is valid.\r
+  EFI_NOT_FOUND         This "file" is the beginning of free space.\r
+  EFI_VOLUME_CORRUPTED  The Ffs header is not valid.\r
+  EFI_ABORTED           The erase polarity is not known.\r
+\r
+--*/\r
+{\r
+  BOOLEAN             ErasePolarity;\r
+  EFI_STATUS          Status;\r
+  EFI_FFS_FILE_HEADER BlankHeader;\r
+  UINT8               Checksum;\r
+  UINT32              FileLength;\r
+  UINT32              OccupiedFileLength;\r
+  EFI_FFS_FILE_TAIL   *Tail;\r
+  UINT8               SavedChecksum;\r
+  UINT8               SavedState;\r
+  UINT8               FileGuidString[80];\r
+  UINT32              TailSize;\r
+  //\r
+  // Verify library has been initialized.\r
+  //\r
+  if (mFvHeader == NULL || mFvLength == 0) {\r
+    return EFI_ABORTED;\r
+  }\r
+  //\r
+  // Verify FV header\r
+  //\r
+  Status = VerifyFv (mFvHeader);\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_ABORTED;\r
+  }\r
+  //\r
+  // Get the erase polarity.\r
+  //\r
+  Status = GetErasePolarity (&ErasePolarity);\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_ABORTED;\r
+  }\r
+  //\r
+  // Check if we have free space\r
+  //\r
+  if (ErasePolarity) {\r
+    memset (&BlankHeader, -1, sizeof (EFI_FFS_FILE_HEADER));\r
+  } else {\r
+    memset (&BlankHeader, 0, sizeof (EFI_FFS_FILE_HEADER));\r
+  }\r
+\r
+  if (memcmp (&BlankHeader, FfsHeader, sizeof (EFI_FFS_FILE_HEADER)) == 0) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+  //\r
+  // Convert the GUID to a string so we can at least report which file\r
+  // if we find an error.\r
+  //\r
+  PrintGuidToBuffer (&FfsHeader->Name, FileGuidString, sizeof (FileGuidString), TRUE);\r
+  if (FfsHeader->Attributes & FFS_ATTRIB_TAIL_PRESENT) {\r
+    TailSize = sizeof (EFI_FFS_FILE_TAIL);\r
+  } else {\r
+    TailSize = 0;\r
+  }\r
+  //\r
+  // Verify file header checksum\r
+  //\r
+  SavedState = FfsHeader->State;\r
+  FfsHeader->State = 0;\r
+  SavedChecksum = FfsHeader->IntegrityCheck.Checksum.File;\r
+  FfsHeader->IntegrityCheck.Checksum.File = 0;\r
+  Checksum = CalculateSum8 ((UINT8 *) FfsHeader, sizeof (EFI_FFS_FILE_HEADER));\r
+  FfsHeader->State = SavedState;\r
+  FfsHeader->IntegrityCheck.Checksum.File = SavedChecksum;\r
+  if (Checksum != 0) {\r
+    Error (NULL, 0, 0, FileGuidString, "invalid FFS file header checksum");\r
+    return EFI_ABORTED;\r
+  }\r
+  //\r
+  // Verify file checksum\r
+  //\r
+  if (FfsHeader->Attributes & FFS_ATTRIB_CHECKSUM) {\r
+    //\r
+    // Verify file data checksum\r
+    //\r
+    FileLength          = GetLength (FfsHeader->Size);\r
+    OccupiedFileLength  = (FileLength + 0x07) & (-1 << 3);\r
+    Checksum            = CalculateSum8 ((UINT8 *) FfsHeader, FileLength - TailSize);\r
+    Checksum            = (UINT8) (Checksum - FfsHeader->State);\r
+    if (Checksum != 0) {\r
+      Error (NULL, 0, 0, FileGuidString, "invalid FFS file checksum");\r
+      return EFI_ABORTED;\r
+    }\r
+  } else {\r
+    //\r
+    // File does not have a checksum\r
+    // Verify contents are 0x5A as spec'd\r
+    //\r
+    if (FfsHeader->IntegrityCheck.Checksum.File != FFS_FIXED_CHECKSUM) {\r
+      Error (NULL, 0, 0, FileGuidString, "invalid fixed FFS file header checksum");\r
+      return EFI_ABORTED;\r
+    }\r
+  }\r
+  //\r
+  // Check if the tail is present and verify it if it is.\r
+  //\r
+  if (FfsHeader->Attributes & FFS_ATTRIB_TAIL_PRESENT) {\r
+    //\r
+    // Verify tail is complement of integrity check field in the header.\r
+    //\r
+    Tail = (EFI_FFS_FILE_TAIL *) ((UINTN) FfsHeader + GetLength (FfsHeader->Size) - sizeof (EFI_FFS_FILE_TAIL));\r
+    if (FfsHeader->IntegrityCheck.TailReference != (EFI_FFS_FILE_TAIL)~(*Tail)) {\r
+      Error (NULL, 0, 0, FileGuidString, "invalid FFS file tail");\r
+      return EFI_ABORTED;\r
+    }\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+UINT32\r
+GetLength (\r
+  UINT8     *ThreeByteLength\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Converts a three byte length value into a UINT32.\r
+\r
+Arguments:\r
+\r
+  ThreeByteLength   Pointer to the first of the 3 byte length.\r
+\r
+Returns:\r
+\r
+  UINT32      Size of the section\r
+\r
+--*/\r
+{\r
+  UINT32  Length;\r
+\r
+  if (ThreeByteLength == NULL) {\r
+    return 0;\r
+  }\r
+\r
+  Length  = *((UINT32 *) ThreeByteLength);\r
+  Length  = Length & 0x00FFFFFF;\r
+\r
+  return Length;\r
+}\r
+\r
+EFI_STATUS\r
+GetErasePolarity (\r
+  OUT BOOLEAN   *ErasePolarity\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This function returns with the FV erase polarity.  If the erase polarity\r
+  for a bit is 1, the function return TRUE.\r
+\r
+Arguments:\r
+\r
+  ErasePolarity   A pointer to the erase polarity.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS              The function completed successfully.\r
+  EFI_INVALID_PARAMETER    One of the input parameters was invalid.\r
+  EFI_ABORTED              Operation aborted.\r
+  \r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // Verify library has been initialized.\r
+  //\r
+  if (mFvHeader == NULL || mFvLength == 0) {\r
+    return EFI_ABORTED;\r
+  }\r
+  //\r
+  // Verify FV header\r
+  //\r
+  Status = VerifyFv (mFvHeader);\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_ABORTED;\r
+  }\r
+  //\r
+  // Verify input parameters.\r
+  //\r
+  if (ErasePolarity == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (mFvHeader->Attributes & EFI_FVB_ERASE_POLARITY) {\r
+    *ErasePolarity = TRUE;\r
+  } else {\r
+    *ErasePolarity = FALSE;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+UINT8\r
+GetFileState (\r
+  IN BOOLEAN              ErasePolarity,\r
+  IN EFI_FFS_FILE_HEADER  *FfsHeader\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This function returns a the highest state bit in the FFS that is set.\r
+  It in no way validate the FFS file.\r
+\r
+Arguments:\r
+  \r
+  ErasePolarity The erase polarity for the file state bits.\r
+  FfsHeader     Pointer to a FFS file.\r
+\r
+Returns:\r
+\r
+  UINT8   The hightest set state of the file.\r
+\r
+--*/\r
+{\r
+  UINT8 FileState;\r
+  UINT8 HighestBit;\r
+\r
+  FileState = FfsHeader->State;\r
+\r
+  if (ErasePolarity) {\r
+    FileState = (UINT8)~FileState;\r
+  }\r
+\r
+  HighestBit = 0x80;\r
+  while (HighestBit != 0 && (HighestBit & FileState) == 0) {\r
+    HighestBit >>= 1;\r
+  }\r
+\r
+  return HighestBit;\r
+}\r
diff --git a/Tools/CCode/Source/Common/FvLib.h b/Tools/CCode/Source/Common/FvLib.h
new file mode 100644 (file)
index 0000000..1ad1e81
--- /dev/null
@@ -0,0 +1,181 @@
+/*++\r
+\r
+Copyright (c) 2004, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  FvLib.h\r
+\r
+Abstract:\r
+\r
+  These functions assist in parsing and manipulating a Firmware Volume.\r
+\r
+--*/\r
+\r
+#ifndef _EFI_FV_LIB_H\r
+#define _EFI_FV_LIB_H\r
+\r
+//\r
+// Include files\r
+//\r
+#include <string.h>\r
+\r
+#include <Common/UefiBaseTypes.h>\r
+#include <Common/EfiImage.h>\r
+#include <Common/FirmwareVolumeImageFormat.h>\r
+#include <Common/FirmwareFileSystem.h>\r
+#include <Common/FirmwareVolumeHeader.h>\r
+#include <Common/MultiPhase.h>\r
+\r
+EFI_STATUS\r
+InitializeFvLib (\r
+  IN VOID                         *Fv,\r
+  IN UINT32                       FvLength\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+GetFvHeader (\r
+  OUT EFI_FIRMWARE_VOLUME_HEADER  **FvHeader,\r
+  OUT UINT32                      *FvLength\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+GetNextFile (\r
+  IN EFI_FFS_FILE_HEADER          *CurrentFile,\r
+  OUT EFI_FFS_FILE_HEADER         **NextFile\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+GetFileByName (\r
+  IN EFI_GUID                     *FileName,\r
+  OUT EFI_FFS_FILE_HEADER         **File\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+GetFileByType (\r
+  IN EFI_FV_FILETYPE              FileType,\r
+  IN UINTN                        Instance,\r
+  OUT EFI_FFS_FILE_HEADER         **File\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+GetSectionByType (\r
+  IN EFI_FFS_FILE_HEADER          *File,\r
+  IN EFI_SECTION_TYPE             SectionType,\r
+  IN UINTN                        Instance,\r
+  OUT EFI_FILE_SECTION_POINTER    *Section\r
+  )\r
+;\r
+//\r
+// will not parse compressed sections\r
+//\r
+EFI_STATUS\r
+VerifyFv (\r
+  IN EFI_FIRMWARE_VOLUME_HEADER   *FvHeader\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+VerifyFfsFile (\r
+  IN EFI_FFS_FILE_HEADER          *FfsHeader\r
+  )\r
+;\r
+\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Verify the current pointer points to a FFS file header.\r
+\r
+Arguments:\r
+\r
+  FfsHeader     Pointer to an alleged FFS file.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           The Ffs header is valid.\r
+  EFI_NOT_FOUND         This "file" is the beginning of free space.\r
+  EFI_VOLUME_CORRUPTED  The Ffs header is not valid.\r
+\r
+--*/\r
+UINT32\r
+GetLength (\r
+  UINT8                           *ThreeByteLength\r
+  )\r
+;\r
+\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Converts a three byte length value into a UINT32.\r
+\r
+Arguments:\r
+\r
+  ThreeByteLength   Pointer to the first of the 3 byte length.\r
+\r
+Returns:\r
+\r
+  UINT32      Size of the section\r
+\r
+--*/\r
+EFI_STATUS\r
+GetErasePolarity (\r
+  OUT BOOLEAN   *ErasePolarity\r
+  )\r
+;\r
+\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This function returns with the FV erase polarity.  If the erase polarity\r
+  for a bit is 1, the function return TRUE.\r
+\r
+Arguments:\r
+\r
+  ErasePolarity   A pointer to the erase polarity.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS              The function completed successfully.\r
+  EFI_INVALID_PARAMETER    One of the input parameters was invalid.\r
+\r
+--*/\r
+UINT8\r
+GetFileState (\r
+  IN BOOLEAN              ErasePolarity,\r
+  IN EFI_FFS_FILE_HEADER  *FfsHeader\r
+  )\r
+;\r
+\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This function returns a the highest state bit in the FFS that is set.\r
+  It in no way validate the FFS file.\r
+\r
+Arguments:\r
+  \r
+  ErasePolarity The erase polarity for the file state bits.\r
+  FfsHeader     Pointer to a FFS file.\r
+\r
+Returns:\r
+\r
+  UINT8   The hightest set state of the file.\r
+\r
+--*/\r
+#endif\r
diff --git a/Tools/CCode/Source/Common/MyAlloc.c b/Tools/CCode/Source/Common/MyAlloc.c
new file mode 100644 (file)
index 0000000..39fddf7
--- /dev/null
@@ -0,0 +1,516 @@
+/*++\r
+\r
+Copyright (c) 2004, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  MyAlloc.c\r
+\r
+Abstract:\r
+\r
+  File for memory allocation tracking functions.\r
+\r
+--*/\r
+\r
+#include "MyAlloc.h"\r
+\r
+#if USE_MYALLOC\r
+//\r
+// Get back to original alloc/free calls.\r
+//\r
+#undef malloc\r
+#undef calloc\r
+#undef realloc\r
+#undef free\r
+//\r
+// Start of allocation list.\r
+//\r