4 This class is to generate Autogen.h and Autogen.c according to module surface area
5 or library surface area.
7 Copyright (c) 2006, Intel Corporation
8 All rights reserved. This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 package org
.tianocore
.build
.autogen
;
21 import java
.io
.FileInputStream
;
22 import java
.io
.FileOutputStream
;
23 import java
.io
.FileReader
;
24 import java
.io
.FileWriter
;
25 import java
.util
.ArrayList
;
26 import java
.util
.HashSet
;
27 import java
.util
.Iterator
;
28 import java
.util
.LinkedHashSet
;
29 import java
.util
.LinkedList
;
30 import java
.util
.List
;
34 import org
.apache
.tools
.ant
.BuildException
;
35 import org
.apache
.xmlbeans
.XmlObject
;
36 import org
.tianocore
.GuidsDocument
;
37 import org
.tianocore
.LibraryClassDocument
.LibraryClass
;
38 import org
.tianocore
.PPIsDocument
;
39 import org
.tianocore
.ProtocolsDocument
;
40 import org
.tianocore
.build
.exception
.*;
41 import org
.tianocore
.build
.global
.GlobalData
;
42 import org
.tianocore
.build
.global
.Spd
;
43 import org
.tianocore
.build
.global
.SurfaceAreaQuery
;
44 import org
.tianocore
.build
.id
.ModuleIdentification
;
45 import org
.tianocore
.build
.id
.PackageIdentification
;
46 import org
.tianocore
.build
.pcd
.action
.PCDAutoGenAction
;
48 import org
.tianocore
.common
.logger
.EdkLog
;
51 * This class is to generate Autogen.h and Autogen.c according to module surface
52 * area or library surface area.
54 public class AutoGen
{
56 /// The output path of Autogen.h and Autogen.c
58 private String outputPath
;
61 /// The name of FV directory
66 /// The base name of module or library.
68 private ModuleIdentification moduleId
;
71 /// The build architecture
76 /// PcdAutogen instance which is used to manage how to generate the PCD
79 private PCDAutoGenAction myPcdAutogen
;
82 /// the one of type : NOT_PCD_DRIVER, PEI_PCD_DRIVER, DXE_PCD_DRIVER
84 private CommonDefinition
.PCD_DRIVER_TYPE pcdDriverType
;
87 /// Judge whether this module's library instance use PcdLib library class
89 private boolean isModuleLibraryInstanceUsePcd
;
92 /// The protocl list which records in module or library surface area and
93 /// it's dependence on library instance surface area.
95 private Set
<String
> mProtocolList
= new HashSet
<String
>();
98 /// The Ppi list which recorded in module or library surface area and its
99 /// dependency on library instance surface area.
101 private Set
<String
> mPpiList
= new HashSet
<String
>();
104 /// The Guid list which recoreded in module or library surface area and it's
105 /// dependence on library instance surface area.
107 private Set
<String
> mGuidList
= new HashSet
<String
>();
110 // The dependence package list which recoreded in module or library surface
111 // area and it's dependence on library instance surface are.
113 private List
<PackageIdentification
> mDepPkgList
= new LinkedList
<PackageIdentification
>();
116 // For non library module, add its library instance's construct and destructor to
119 private List
<String
> libConstructList
= new ArrayList
<String
>();
120 private List
<String
> libDestructList
= new ArrayList
<String
>();
123 // List to store SetVirtalAddressMapCallBack, ExitBootServiceCallBack
125 private List
<String
> setVirtalAddList
= new ArrayList
<String
>();
126 private List
<String
> exitBootServiceList
= new ArrayList
<String
>();
132 * This function mainly initialize some member variable.
135 * Output path of AutoGen file.
139 * Target architecture.
141 public AutoGen(String fvDir
, String outputPath
, ModuleIdentification moduleId
, String arch
) {
142 this.outputPath
= outputPath
;
143 this.moduleId
= moduleId
;
152 * This function save the content in stringBuffer to file.
157 * The content of AutoGen file in buffer.
158 * @return "true" successful, "false" failed.
160 private boolean saveFile(String fileName
, StringBuffer fileBuffer
) {
162 File autoGenH
= new File(fileName
);
165 // if the file exists, compare their content
167 if (autoGenH
.exists()) {
168 FileReader fIn
= new FileReader(autoGenH
);
169 char[] oldFileBuffer
= new char[(int) autoGenH
.length()];
170 fIn
.read(oldFileBuffer
, 0, (int) autoGenH
.length());
174 // if we got the same file, don't re-generate it to prevent
175 // sources depending on it from re-building
177 if (fileBuffer
.toString().compareTo(new String(oldFileBuffer
)) == 0) {
181 FileWriter fOut
= new FileWriter(autoGenH
);
182 fOut
.write(fileBuffer
.toString());
184 } catch (Exception e
) {
191 * genAutogen function
193 * This function call libGenAutoGen or moduleGenAutogen function, which
194 * dependence on generate library autogen or module autogen.
196 * @throws BuildException
197 * Failed to creat AutoGen.c & AutoGen.h.
199 public void genAutogen() throws BuildException
{
202 // If outputPath do not exist, create it.
204 File path
= new File(outputPath
);
208 // Check current is library or not, then call the corresponding
211 if (this.moduleId
.isLibrary()) {
217 } catch (Exception e
) {
218 throw new BuildException(
219 "Failed to create AutoGen.c & AutoGen.h!\n"
225 * moduleGenAutogen function
227 * This function generates AutoGen.c & AutoGen.h for module.
229 * @throws BuildException
230 * Faile to create module AutoGen.c & AutoGen.h.
232 void moduleGenAutogen() throws BuildException
{
235 collectLibInstanceInfo();
238 } catch (Exception e
) {
239 throw new BuildException(
240 "Faile to create module AutoGen.c & AutoGen.h!\n"
246 * libGenAutogen function
248 * This function generates AutoGen.c & AutoGen.h for library.
250 * @throws BuildException
251 * Faile to create library AutoGen.c & AutoGen.h
253 void libGenAutogen() throws BuildException
{
257 } catch (Exception e
) {
258 throw new BuildException(
259 "Failed to create library AutoGen.c & AutoGen.h!\n"
267 * This function generates AutoGen.h for module.
269 * @throws BuildException
270 * Failed to generate AutoGen.h.
272 void moduleGenAutogenH() throws AutoGenException
{
274 Set
<String
> libClassIncludeH
;
276 // List<String> headerFileList;
277 List
<String
> headerFileList
;
279 StringBuffer fileBuffer
= new StringBuffer(8192);
282 // Write Autogen.h header notation
284 fileBuffer
.append(CommonDefinition
.autogenHNotation
);
287 // Add #ifndef ${BaseName}_AUTOGENH
288 // #def ${BseeName}_AUTOGENH
290 fileBuffer
.append("#ifndef " + "_AUTOGENH_" + this.moduleId
.getGuid().replaceAll("-", "_") +"\r\n");
291 fileBuffer
.append("#define " + "_AUTOGENH_" + this.moduleId
.getGuid().replaceAll("-", "_") +"\r\n\r\n");
294 // Write the specification version and release version at the begine
295 // of autogen.h file.
296 // Note: the specification version and release version should
297 // be got from module surface area instead of hard code by it's
300 moduleType
= SurfaceAreaQuery
.getModuleType();
303 // Add "extern int __make_me_compile_correctly;" at begin of
306 fileBuffer
.append(CommonDefinition
.autoGenHbegin
);
309 // Put EFI_SPECIFICATION_VERSION, and EDK_RELEASE_VERSION.
311 String
[] specList
= SurfaceAreaQuery
.getExternSpecificaiton();
312 for (int i
= 0; i
< specList
.length
; i
++) {
313 fileBuffer
.append(CommonDefinition
.marcDefineStr
+ specList
[i
]
317 // Write consumed package's mdouleInfo related .h file to autogen.h
319 // PackageIdentification[] consumedPkgIdList = SurfaceAreaQuery
320 // .getDependencePkg(this.arch);
321 PackageIdentification
[] consumedPkgIdList
= SurfaceAreaQuery
322 .getDependencePkg(this.arch
);
323 if (consumedPkgIdList
!= null) {
324 headerFileList
= depPkgToAutogenH(consumedPkgIdList
, moduleType
);
325 item
= headerFileList
.iterator();
326 while (item
.hasNext()) {
327 fileBuffer
.append(item
.next().toString());
332 // Write library class's related *.h file to autogen.h.
334 String
[] libClassList
= SurfaceAreaQuery
335 .getLibraryClasses(CommonDefinition
.AlwaysConsumed
,this.arch
);
336 boolean isModuleConsumePcdLib
= false;
337 List
<String
> libClassArray
= new ArrayList
<String
>();
338 for (int index
= 0; index
< libClassList
.length
; index
++) {
339 libClassArray
.add(libClassList
[index
]);
341 // Search all library class of a module for PcdLib
343 if (libClassList
[index
].equalsIgnoreCase(CommonDefinition
.pcdLibName
)) {
344 isModuleConsumePcdLib
= true;
349 // If module do not use PCD but module's library use PCD.
351 if (!isModuleConsumePcdLib
&& this.isModuleLibraryInstanceUsePcd
) {
352 libClassArray
.add(CommonDefinition
.pcdLibName
);
355 libClassList
= new String
[libClassArray
.size()];
356 libClassArray
.toArray(libClassList
);
358 if (libClassList
!= null) {
359 libClassIncludeH
= LibraryClassToAutogenH(libClassList
);
360 item
= libClassIncludeH
.iterator();
361 while (item
.hasNext()) {
362 fileBuffer
.append(item
.next().toString());
366 libClassList
= SurfaceAreaQuery
367 .getLibraryClasses(CommonDefinition
.AlwaysProduced
, this.arch
);
368 if (libClassList
!= null) {
369 libClassIncludeH
= LibraryClassToAutogenH(libClassList
);
370 item
= libClassIncludeH
.iterator();
371 while (item
.hasNext()) {
372 fileBuffer
.append(item
.next().toString());
375 fileBuffer
.append("\r\n");
378 // If is TianoR8FlashMap, copy {Fv_DIR}/FlashMap.h to
379 // {DEST_DIR_DRBUG}/FlashMap.h
381 if (SurfaceAreaQuery
.isHaveTianoR8FlashMap()) {
382 fileBuffer
.append(CommonDefinition
.include
);
383 fileBuffer
.append(" <");
384 fileBuffer
.append(CommonDefinition
.tianoR8FlashMapH
+ ">\r\n");
385 copyFlashMapHToDebugDir();
388 // Write PCD autogen information to AutoGen.h.
390 if (this.myPcdAutogen
!= null) {
391 fileBuffer
.append("\r\n");
392 fileBuffer
.append(this.myPcdAutogen
.getHAutoGenString());
396 // Append the #endif at AutoGen.h
398 fileBuffer
.append("#endif\r\n");
401 // Save string buffer content in AutoGen.h.
403 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.h", fileBuffer
)) {
404 throw new BuildException("Failed to generate AutoGen.h !!!");
411 * This function generates AutoGen.c for module.
413 * @throws BuildException
414 * Failed to generate AutoGen.c.
416 void moduleGenAutogenC() throws AutoGenException
{
418 StringBuffer fileBuffer
= new StringBuffer(8192);
420 // Write Autogen.c header notation
422 fileBuffer
.append(CommonDefinition
.autogenCNotation
);
425 // Write #include <AutoGen.h> at beginning of AutoGen.c
427 fileBuffer
.append(CommonDefinition
.includeAutogenH
);
430 // Get the native MSA file infomation. Since before call autogen,
431 // the MSA native <Externs> information were overrided. So before
432 // process <Externs> it should be set the DOC as the Native MSA info.
434 Map
<String
, XmlObject
> doc
= GlobalData
.getNativeMsa(this.moduleId
);
435 SurfaceAreaQuery
.push(doc
);
438 // DriverBinding/ComponentName/DriverConfiguration/DriverDialog
442 ExternsDriverBindingToAutoGenC(fileBuffer
);
445 // Write DriverExitBootServicesEvent/DriverSetVirtualAddressMapEvent
448 ExternCallBackToAutoGenC(fileBuffer
);
451 // Write EntryPoint to autgoGen.c
453 String
[] entryPointList
= SurfaceAreaQuery
.getModuleEntryPointArray();
454 EntryPointToAutoGen(CommonDefinition
.remDupString(entryPointList
), fileBuffer
);
456 pcdDriverType
= SurfaceAreaQuery
.getPcdDriverType();
459 // Restore the DOC which include the FPD module info.
461 SurfaceAreaQuery
.pop();
464 // Write Guid to autogen.c
466 String guid
= CommonDefinition
.formatGuidName(SurfaceAreaQuery
470 .append("GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiCallerIdGuid = {");
472 throw new AutoGenException("Guid value must set!\n");
476 // Formate Guid as ANSI c form.Example:
477 // {0xd2b2b828, 0x826, 0x48a7,{0xb3, 0xdf, 0x98, 0x3c, 0x0, 0x60, 0x24,
481 fileBuffer
.append(guid
);
482 fileBuffer
.append("};\r\n");
485 // Generate library instance consumed protocol, guid, ppi, pcd list.
486 // Save those to this.protocolList, this.ppiList, this.pcdList,
487 // this.guidList. Write Consumed library constructor and desconstuct to
490 LibInstanceToAutogenC(fileBuffer
);
493 // Get module dependent Package identification.
495 PackageIdentification
[] packages
= SurfaceAreaQuery
.getDependencePkg(this.arch
);
496 for (int i
= 0; i
< packages
.length
; i
++) {
497 if (!this.mDepPkgList
.contains(packages
[i
])) {
498 this.mDepPkgList
.add(packages
[i
]);
504 // Write consumed ppi, guid, protocol to autogen.c
506 ProtocolGuidToAutogenC(fileBuffer
);
507 PpiGuidToAutogenC(fileBuffer
);
508 GuidGuidToAutogenC(fileBuffer
);
513 this.myPcdAutogen
= new PCDAutoGenAction(moduleId
,
519 this.myPcdAutogen
.execute();
520 } catch (Exception exp
) {
521 throw new PcdAutogenException (exp
.getMessage());
524 if (this.myPcdAutogen
!= null) {
525 fileBuffer
.append("\r\n");
526 fileBuffer
.append(this.myPcdAutogen
.getCAutoGenString());
529 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.c", fileBuffer
)) {
530 throw new BuildException("Failed to generate AutoGen.c !!!");
538 * This function generates AutoGen.h for library.
540 * @throws BuildException
541 * Failed to generate AutoGen.c.
543 void libGenAutogenH() throws AutoGenException
{
545 Set
<String
> libClassIncludeH
;
547 List
<String
> headerFileList
;
549 StringBuffer fileBuffer
= new StringBuffer(10240);
552 // Write Autogen.h header notation
554 fileBuffer
.append(CommonDefinition
.autogenHNotation
);
557 // Add #ifndef ${BaseName}_AUTOGENH
558 // #def ${BseeName}_AUTOGENH
560 fileBuffer
.append("#ifndef " + "_AUTOGENH_" + this.moduleId
.getGuid().replaceAll("-", "_") + "\r\n");
561 fileBuffer
.append("#define " + "_AUTOGENH_" + this.moduleId
.getGuid().replaceAll("-", "_") + "\r\n\r\n");
564 // Write EFI_SPECIFICATION_VERSION and EDK_RELEASE_VERSION
565 // to autogen.h file.
566 // Note: the specification version and release version should
567 // be get from module surface area instead of hard code.
569 fileBuffer
.append(CommonDefinition
.autoGenHbegin
);
570 String
[] specList
= SurfaceAreaQuery
.getExternSpecificaiton();
571 for (int i
= 0; i
< specList
.length
; i
++) {
572 fileBuffer
.append(CommonDefinition
.marcDefineStr
+ specList
[i
]
575 // fileBuffer.append(CommonDefinition.autoGenHLine1);
576 // fileBuffer.append(CommonDefinition.autoGenHLine2);
579 // Write consumed package's mdouleInfo related *.h file to autogen.h.
581 moduleType
= SurfaceAreaQuery
.getModuleType();
582 PackageIdentification
[] cosumedPkglist
= SurfaceAreaQuery
583 .getDependencePkg(this.arch
);
584 headerFileList
= depPkgToAutogenH(cosumedPkglist
, moduleType
);
585 item
= headerFileList
.iterator();
586 while (item
.hasNext()) {
587 fileBuffer
.append(item
.next().toString());
590 // Write library class's related *.h file to autogen.h
592 String
[] libClassList
= SurfaceAreaQuery
593 .getLibraryClasses(CommonDefinition
.AlwaysConsumed
, this.arch
);
594 if (libClassList
!= null) {
595 libClassIncludeH
= LibraryClassToAutogenH(libClassList
);
596 item
= libClassIncludeH
.iterator();
597 while (item
.hasNext()) {
598 fileBuffer
.append(item
.next().toString());
602 libClassList
= SurfaceAreaQuery
603 .getLibraryClasses(CommonDefinition
.AlwaysProduced
, this.arch
);
604 if (libClassList
!= null) {
605 libClassIncludeH
= LibraryClassToAutogenH(libClassList
);
606 item
= libClassIncludeH
.iterator();
607 while (item
.hasNext()) {
608 fileBuffer
.append(item
.next().toString());
611 fileBuffer
.append("\r\n");
614 // If is TianoR8FlashMap, copy {Fv_DIR}/FlashMap.h to
615 // {DEST_DIR_DRBUG}/FlashMap.h
617 if (SurfaceAreaQuery
.isHaveTianoR8FlashMap()) {
618 fileBuffer
.append(CommonDefinition
.include
);
619 fileBuffer
.append(" <");
620 fileBuffer
.append(CommonDefinition
.tianoR8FlashMapH
+ ">\r\n");
621 copyFlashMapHToDebugDir();
625 // Write PCD information to library AutoGen.h.
627 if (this.myPcdAutogen
!= null) {
628 fileBuffer
.append("\r\n");
629 fileBuffer
.append(this.myPcdAutogen
.getHAutoGenString());
633 // Append the #endif at AutoGen.h
635 fileBuffer
.append("#endif\r\n");
638 // Save content of string buffer to AutoGen.h file.
640 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.h", fileBuffer
)) {
641 throw new BuildException("Failed to generate AutoGen.h !!!");
648 * This function generates AutoGen.h for library.
650 * @throws BuildException
651 * Failed to generate AutoGen.c.
653 void libGenAutogenC() throws BuildException
, PcdAutogenException
{
654 StringBuffer fileBuffer
= new StringBuffer(10240);
657 // Write Autogen.c header notation
659 fileBuffer
.append(CommonDefinition
.autogenCNotation
);
661 fileBuffer
.append(CommonDefinition
.autoGenCLine1
);
662 fileBuffer
.append("\r\n");
667 this.myPcdAutogen
= new PCDAutoGenAction(moduleId
,
670 SurfaceAreaQuery
.getModulePcdEntryNameArray(),
673 this.myPcdAutogen
.execute();
674 } catch (Exception e
) {
675 throw new PcdAutogenException(e
.getMessage());
678 if (this.myPcdAutogen
!= null) {
679 fileBuffer
.append("\r\n");
680 fileBuffer
.append(this.myPcdAutogen
.getCAutoGenString());
683 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.c", fileBuffer
)) {
684 throw new BuildException("Failed to generate AutoGen.c !!!");
689 * LibraryClassToAutogenH
691 * This function returns *.h files declared by library classes which are
692 * consumed or produced by current build module or library.
694 * @param libClassList
695 * List of library class which consumed or produce by current
696 * build module or library.
697 * @return includeStrList List of *.h file.
699 Set
<String
> LibraryClassToAutogenH(String
[] libClassList
)
700 throws AutoGenException
{
701 Set
<String
> includStrList
= new LinkedHashSet
<String
>();
702 String includerName
[];
706 // Get include file from GlobalData's SPDTable according to
707 // library class name.
709 for (int i
= 0; i
< libClassList
.length
; i
++) {
710 includerName
= GlobalData
.getLibraryClassHeaderFiles(
711 SurfaceAreaQuery
.getDependencePkg(this.arch
),
713 if (includerName
== null) {
714 throw new AutoGenException("Can not find library class ["
715 + libClassList
[i
] + "] declaration in any SPD package. ");
717 for (int j
= 0; j
< includerName
.length
; j
++) {
718 String includeNameStr
= includerName
[j
];
719 if (includeNameStr
!= null) {
720 str
= CommonDefinition
.include
+ " " + "<";
721 str
= str
+ includeNameStr
+ ">\r\n";
722 includStrList
.add(str
);
723 includeNameStr
= null;
727 return includStrList
;
733 * This function add include file in AutoGen.h file.
735 * @param packageNameList
736 * List of module depended package.
741 List
<String
> depPkgToAutogenH(PackageIdentification
[] packageNameList
,
742 String moduleType
) throws AutoGenException
{
744 List
<String
> includeStrList
= new LinkedList
<String
>();
746 String includeStr
= "";
749 // Get include file from moduleInfo file
751 for (int i
= 0; i
< packageNameList
.length
; i
++) {
752 pkgHeader
= GlobalData
.getPackageHeaderFiles(packageNameList
[i
],
754 if (pkgHeader
== null) {
755 throw new AutoGenException("Can not find package ["
757 + "] declaration in any SPD package. ");
758 } else if (!pkgHeader
.equalsIgnoreCase("")) {
759 includeStr
= CommonDefinition
.include
+ " <" + pkgHeader
761 includeStrList
.add(includeStr
);
765 return includeStrList
;
769 * EntryPointToAutoGen
771 * This function convert <ModuleEntryPoint> & <ModuleUnloadImage>
772 * information in mas to AutoGen.c
774 * @param entryPointList
775 * List of entry point.
777 * String buffer fo AutoGen.c.
780 void EntryPointToAutoGen(String
[] entryPointList
, StringBuffer fileBuffer
)
781 throws BuildException
{
783 String typeStr
= SurfaceAreaQuery
.getModuleType();
786 // The parameters and return value of entryPoint is difference
787 // for difference module type.
789 switch (CommonDefinition
.getModuleType(typeStr
)) {
791 case CommonDefinition
.ModuleTypePeiCore
:
792 if (entryPointList
== null ||entryPointList
.length
!= 1 ) {
793 throw new BuildException(
794 "Module type = 'PEI_CORE', can have only one module entry point!");
796 fileBuffer
.append("EFI_STATUS\r\n");
797 fileBuffer
.append("EFIAPI\r\n");
798 fileBuffer
.append(entryPointList
[0]);
799 fileBuffer
.append(" (\r\n");
801 .append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n");
803 .append(" IN VOID *OldCoreData\r\n");
804 fileBuffer
.append(" );\r\n\r\n");
806 fileBuffer
.append("EFI_STATUS\r\n");
807 fileBuffer
.append("EFIAPI\r\n");
808 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
810 .append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n");
812 .append(" IN VOID *OldCoreData\r\n");
813 fileBuffer
.append(" )\r\n\r\n");
814 fileBuffer
.append("{\r\n");
815 fileBuffer
.append(" return ");
816 fileBuffer
.append(entryPointList
[0]);
817 fileBuffer
.append(" (PeiStartupDescriptor, OldCoreData);\r\n");
818 fileBuffer
.append("}\r\n\r\n");
822 case CommonDefinition
.ModuleTypeDxeCore
:
823 fileBuffer
.append("const UINT32 _gUefiDriverRevision = 0;\r\n");
824 if (entryPointList
== null || entryPointList
.length
!= 1) {
825 throw new BuildException(
826 "Module type = 'DXE_CORE', can have only one module entry point!");
829 fileBuffer
.append("VOID\r\n");
830 fileBuffer
.append("EFIAPI\r\n");
831 fileBuffer
.append(entryPointList
[0]);
832 fileBuffer
.append(" (\n");
833 fileBuffer
.append(" IN VOID *HobStart\r\n");
834 fileBuffer
.append(" );\r\n\r\n");
836 fileBuffer
.append("VOID\r\n");
837 fileBuffer
.append("EFIAPI\r\n");
838 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
839 fileBuffer
.append(" IN VOID *HobStart\r\n");
840 fileBuffer
.append(" )\r\n\r\n");
841 fileBuffer
.append("{\r\n");
842 fileBuffer
.append(" ");
843 fileBuffer
.append(entryPointList
[0]);
844 fileBuffer
.append(" (HobStart);\r\n");
845 fileBuffer
.append("}\r\n\r\n");
849 case CommonDefinition
.ModuleTypePeim
:
850 int entryPointCount
= 0;
852 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = 0;\r\n");
853 if (entryPointList
== null || entryPointList
.length
== 0) {
854 fileBuffer
.append("EFI_STATUS\r\n");
855 fileBuffer
.append("EFIAPI\r\n");
856 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
857 fileBuffer
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
858 fileBuffer
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
859 fileBuffer
.append(" )\r\n\r\n");
860 fileBuffer
.append("{\r\n");
861 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
862 fileBuffer
.append("}\r\n\r\n");
865 for (int i
= 0; i
< entryPointList
.length
; i
++) {
866 fileBuffer
.append("EFI_STATUS\r\n");
867 fileBuffer
.append("EFIAPI\r\n");
868 fileBuffer
.append(entryPointList
[i
]);
869 fileBuffer
.append(" (\r\n");
871 .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
873 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
874 fileBuffer
.append(" );\r\n");
879 fileBuffer
.append("EFI_STATUS\r\n");
880 fileBuffer
.append("EFIAPI\r\n");
881 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
882 fileBuffer
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
883 fileBuffer
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
884 fileBuffer
.append(" )\r\n\r\n");
885 fileBuffer
.append("{\r\n");
886 if (entryPointCount
== 1) {
887 fileBuffer
.append(" return ");
888 fileBuffer
.append(entryPointList
[0]);
889 fileBuffer
.append(" (FfsHeader, PeiServices);\r\n");
891 fileBuffer
.append(" EFI_STATUS Status;\r\n");
892 fileBuffer
.append(" EFI_STATUS CombinedStatus;\r\n\r\n");
893 fileBuffer
.append(" CombinedStatus = EFI_LOAD_ERROR;\r\n\r\n");
894 for (int i
= 0; i
< entryPointList
.length
; i
++) {
895 if (!entryPointList
[i
].equals("")) {
896 fileBuffer
.append(" Status = ");
897 fileBuffer
.append(entryPointList
[i
]);
898 fileBuffer
.append(" (FfsHeader, PeiServices);\r\n");
900 .append(" if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {\r\n");
901 fileBuffer
.append(" CombinedStatus = Status;\r\n");
902 fileBuffer
.append(" }\r\n\r\n");
907 fileBuffer
.append(" return CombinedStatus;\r\n");
909 fileBuffer
.append("}\r\n\r\n");
912 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
915 // If entryPoint is null, create an empty ProcessModuleEntryPointList
918 if (entryPointList
== null || entryPointList
.length
== 0) {
920 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
921 fileBuffer
.append(Integer
.toString(entryPointCount
));
922 fileBuffer
.append(";\r\n");
923 fileBuffer
.append("EFI_STATUS\r\n");
924 fileBuffer
.append("EFIAPI\r\n");
925 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
926 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
927 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
928 fileBuffer
.append(" )\r\n\r\n");
929 fileBuffer
.append("{\r\n");
930 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
931 fileBuffer
.append("}\r\n\r\n");
934 for (int i
= 0; i
< entryPointList
.length
; i
++) {
935 fileBuffer
.append("EFI_STATUS\r\n");
936 fileBuffer
.append("EFIAPI\r\n");
937 fileBuffer
.append(entryPointList
[i
]);
938 fileBuffer
.append(" (\r\n");
939 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
940 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
941 fileBuffer
.append(" );\r\n");
945 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
946 fileBuffer
.append(Integer
.toString(entryPointCount
));
947 fileBuffer
.append(";\r\n");
949 .append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");
951 .append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n\r\n");
953 fileBuffer
.append("EFI_STATUS\r\n");
954 fileBuffer
.append("EFIAPI\r\n");
955 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
956 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
957 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
958 fileBuffer
.append(" )\r\n\r\n");
959 fileBuffer
.append("{\r\n");
962 for (int i
= 0; i
< entryPointList
.length
; i
++) {
964 .append(" if (SetJump (&mJumpContext) == 0) {\r\n");
965 fileBuffer
.append(" ExitDriver (");
966 fileBuffer
.append(entryPointList
[i
]);
967 fileBuffer
.append(" (ImageHandle, SystemTable));\r\n");
968 fileBuffer
.append(" ASSERT (FALSE);\r\n");
969 fileBuffer
.append(" }\r\n");
972 fileBuffer
.append(" return mDriverEntryPointStatus;\r\n");
973 fileBuffer
.append("}\r\n\r\n");
975 fileBuffer
.append("VOID\r\n");
976 fileBuffer
.append("EFIAPI\r\n");
977 fileBuffer
.append("ExitDriver (\r\n");
978 fileBuffer
.append(" IN EFI_STATUS Status\n");
979 fileBuffer
.append(" )\r\n\r\n");
980 fileBuffer
.append("{\r\n");
982 .append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");
983 fileBuffer
.append(" mDriverEntryPointStatus = Status;\r\n");
984 fileBuffer
.append(" }\r\n");
985 fileBuffer
.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");
986 fileBuffer
.append(" ASSERT (FALSE);\r\n");
987 fileBuffer
.append("}\r\n\r\n");
993 // Add "ModuleUnloadImage" for DxeSmmDriver module type;
995 entryPointList
= SurfaceAreaQuery
.getModuleUnloadImageArray();
996 entryPointList
= CommonDefinition
.remDupString(entryPointList
);
999 if (entryPointList
!= null) {
1000 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1001 fileBuffer
.append("EFI_STATUS\r\n");
1002 fileBuffer
.append("EFIAPI\r\n");
1003 fileBuffer
.append(entryPointList
[i
]);
1004 fileBuffer
.append(" (\r\n");
1006 .append(" IN EFI_HANDLE ImageHandle\r\n");
1007 fileBuffer
.append(" );\r\n");
1013 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");
1014 fileBuffer
.append(Integer
.toString(entryPointCount
));
1015 fileBuffer
.append(";\r\n\r\n");
1017 fileBuffer
.append("EFI_STATUS\r\n");
1018 fileBuffer
.append("EFIAPI\r\n");
1019 fileBuffer
.append("ProcessModuleUnloadList (\r\n");
1020 fileBuffer
.append(" IN EFI_HANDLE ImageHandle\r\n");
1021 fileBuffer
.append(" )\r\n");
1022 fileBuffer
.append("{\r\n");
1024 if (entryPointCount
== 0) {
1025 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
1026 } else if (entryPointCount
== 1) {
1027 fileBuffer
.append(" return ");
1028 fileBuffer
.append(entryPointList
[0]);
1029 fileBuffer
.append("(ImageHandle);\r\n");
1031 fileBuffer
.append(" EFI_STATUS Status;\r\n\r\n");
1032 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n\r\n");
1033 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1035 fileBuffer
.append(" Status = ");
1036 fileBuffer
.append(entryPointList
[i
]);
1037 fileBuffer
.append("(ImageHandle);\r\n");
1039 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
1040 fileBuffer
.append(" ");
1041 fileBuffer
.append(entryPointList
[i
]);
1042 fileBuffer
.append("(ImageHandle);\r\n");
1043 fileBuffer
.append(" } else {\r\n");
1044 fileBuffer
.append(" Status = ");
1045 fileBuffer
.append(entryPointList
[i
]);
1046 fileBuffer
.append("(ImageHandle);\r\n");
1047 fileBuffer
.append(" }\r\n");
1050 fileBuffer
.append(" return Status;\r\n");
1052 fileBuffer
.append("}\r\n\r\n");
1055 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1056 case CommonDefinition
.ModuleTypeDxeDriver
:
1057 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1058 case CommonDefinition
.ModuleTypeUefiDriver
:
1059 case CommonDefinition
.ModuleTypeUefiApplication
:
1060 entryPointCount
= 0;
1061 fileBuffer
.append("const UINT32 _gUefiDriverRevision = 0;\r\n");
1063 // If entry point is null, create a empty ProcessModuleEntryPointList function.
1065 if (entryPointList
== null || entryPointList
.length
== 0) {
1067 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = 0;\r\n");
1068 fileBuffer
.append("EFI_STATUS\r\n");
1069 fileBuffer
.append("EFIAPI\r\n");
1070 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
1071 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1072 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1073 fileBuffer
.append(" )\r\n\r\n");
1074 fileBuffer
.append("{\r\n");
1075 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
1076 fileBuffer
.append("}\r\n");
1079 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1081 fileBuffer
.append("EFI_STATUS\r\n");
1082 fileBuffer
.append("EFIAPI\r\n");
1083 fileBuffer
.append(entryPointList
[i
]);
1084 fileBuffer
.append(" (\r\n");
1085 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1086 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1087 fileBuffer
.append(" );\r\n");
1092 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
1093 fileBuffer
.append(Integer
.toString(entryPointCount
));
1094 fileBuffer
.append(";\r\n");
1095 if (entryPointCount
> 1) {
1097 .append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");
1099 .append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n");
1101 fileBuffer
.append("\n");
1103 fileBuffer
.append("EFI_STATUS\r\n");
1104 fileBuffer
.append("EFIAPI\r\n");
1105 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
1106 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1107 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1108 fileBuffer
.append(" )\r\n\r\n");
1109 fileBuffer
.append("{\r\n");
1111 if (entryPointCount
== 1) {
1112 fileBuffer
.append(" return (");
1113 fileBuffer
.append(entryPointList
[0]);
1114 fileBuffer
.append(" (ImageHandle, SystemTable));\r\n");
1116 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1117 if (!entryPointList
[i
].equals("")) {
1119 .append(" if (SetJump (&mJumpContext) == 0) {\r\n");
1120 fileBuffer
.append(" ExitDriver (");
1121 fileBuffer
.append(entryPointList
[i
]);
1122 fileBuffer
.append(" (ImageHandle, SystemTable));\r\n");
1123 fileBuffer
.append(" ASSERT (FALSE);\r\n");
1124 fileBuffer
.append(" }\r\n");
1129 fileBuffer
.append(" return mDriverEntryPointStatus;\r\n");
1131 fileBuffer
.append("}\r\n\r\n");
1133 fileBuffer
.append("VOID\r\n");
1134 fileBuffer
.append("EFIAPI\r\n");
1135 fileBuffer
.append("ExitDriver (\r\n");
1136 fileBuffer
.append(" IN EFI_STATUS Status\r\n");
1137 fileBuffer
.append(" )\r\n\r\n");
1138 fileBuffer
.append("{\r\n");
1139 if (entryPointCount
<= 1) {
1140 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
1142 .append(" ProcessLibraryDestructorList (gImageHandle, gST);\r\n");
1143 fileBuffer
.append(" }\r\n");
1145 .append(" gBS->Exit (gImageHandle, Status, 0, NULL);\r\n");
1148 .append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");
1149 fileBuffer
.append(" mDriverEntryPointStatus = Status;\r\n");
1150 fileBuffer
.append(" }\r\n");
1151 fileBuffer
.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");
1152 fileBuffer
.append(" ASSERT (FALSE);\r\n");
1154 fileBuffer
.append("}\r\n\r\n");
1159 // Add ModuleUnloadImage for DxeDriver and UefiDriver module type.
1161 entryPointList
= SurfaceAreaQuery
.getModuleUnloadImageArray();
1163 // Remover duplicate unload entry point.
1165 entryPointList
= CommonDefinition
.remDupString(entryPointList
);
1166 entryPointCount
= 0;
1167 if (entryPointList
!= null) {
1168 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1169 fileBuffer
.append("EFI_STATUS\r\n");
1170 fileBuffer
.append("EFIAPI\r\n");
1171 fileBuffer
.append(entryPointList
[i
]);
1172 fileBuffer
.append(" (\r\n");
1174 .append(" IN EFI_HANDLE ImageHandle\r\n");
1175 fileBuffer
.append(" );\r\n");
1181 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");
1182 fileBuffer
.append(Integer
.toString(entryPointCount
));
1183 fileBuffer
.append(";\r\n\r\n");
1185 fileBuffer
.append("EFI_STATUS\n");
1186 fileBuffer
.append("EFIAPI\r\n");
1187 fileBuffer
.append("ProcessModuleUnloadList (\r\n");
1188 fileBuffer
.append(" IN EFI_HANDLE ImageHandle\r\n");
1189 fileBuffer
.append(" )\r\n");
1190 fileBuffer
.append("{\r\n");
1192 if (entryPointCount
== 0) {
1193 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
1194 } else if (entryPointCount
== 1) {
1195 fileBuffer
.append(" return ");
1196 fileBuffer
.append(entryPointList
[0]);
1197 fileBuffer
.append("(ImageHandle);\r\n");
1199 fileBuffer
.append(" EFI_STATUS Status;\r\n\r\n");
1200 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n\r\n");
1201 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1203 fileBuffer
.append(" Status = ");
1204 fileBuffer
.append(entryPointList
[i
]);
1205 fileBuffer
.append("(ImageHandle);\r\n");
1207 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
1208 fileBuffer
.append(" ");
1209 fileBuffer
.append(entryPointList
[i
]);
1210 fileBuffer
.append("(ImageHandle);\r\n");
1211 fileBuffer
.append(" } else {\r\n");
1212 fileBuffer
.append(" Status = ");
1213 fileBuffer
.append(entryPointList
[i
]);
1214 fileBuffer
.append("(ImageHandle);\r\n");
1215 fileBuffer
.append(" }\r\n");
1218 fileBuffer
.append(" return Status;\r\n");
1220 fileBuffer
.append("}\r\n\r\n");
1228 * This function gets GUIDs from SPD file accrodeing to <PPIs> information
1229 * and write those GUIDs to AutoGen.c.
1232 * String Buffer for Autogen.c file.
1233 * @throws BuildException
1234 * Guid must set value!
1236 void PpiGuidToAutogenC(StringBuffer fileBuffer
) throws AutoGenException
{
1237 String
[] cNameGuid
= null;
1240 // Get the all PPI adn PPI Notify from MSA file,
1241 // then add those PPI ,and PPI Notify name to list.
1244 String
[] ppiList
= SurfaceAreaQuery
.getPpiArray(this.arch
);
1245 for (int i
= 0; i
< ppiList
.length
; i
++) {
1246 this.mPpiList
.add(ppiList
[i
]);
1249 String
[] ppiNotifyList
= SurfaceAreaQuery
.getPpiNotifyArray(this.arch
);
1250 for (int i
= 0; i
< ppiNotifyList
.length
; i
++) {
1251 this.mPpiList
.add(ppiNotifyList
[i
]);
1255 // Find CNAME and GUID from dependence SPD file and write to Autogen.c
1257 Iterator ppiIterator
= this.mPpiList
.iterator();
1258 String ppiKeyWord
= null;
1259 while (ppiIterator
.hasNext()) {
1260 ppiKeyWord
= ppiIterator
.next().toString();
1261 cNameGuid
= GlobalData
.getPpiGuid(this.mDepPkgList
, ppiKeyWord
);
1262 if (cNameGuid
!= null) {
1264 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1265 fileBuffer
.append(cNameGuid
[0]);
1266 fileBuffer
.append(" = { ");
1267 fileBuffer
.append(CommonDefinition
.formatGuidName(cNameGuid
[1]));
1268 fileBuffer
.append(" } ;");
1271 // If can't find Ppi GUID declaration in every package
1273 throw new AutoGenException("Can not find Ppi GUID ["
1274 + ppiKeyWord
+ "] declaration in any SPD package!");
1280 * ProtocolGuidToAutogenc
1282 * This function gets GUIDs from SPD file accrodeing to <Protocol>
1283 * information and write those GUIDs to AutoGen.c.
1286 * String Buffer for Autogen.c file.
1287 * @throws BuildException
1288 * Protocol name must set.
1290 void ProtocolGuidToAutogenC(StringBuffer fileBuffer
) throws BuildException
{
1291 String
[] cNameGuid
= null;
1293 String
[] protocolList
= SurfaceAreaQuery
.getProtocolArray(this.arch
);
1296 // Add result to Autogen global list.
1298 for (int i
= 0; i
< protocolList
.length
; i
++) {
1299 this.mProtocolList
.add(protocolList
[i
]);
1302 String
[] protocolNotifyList
= SurfaceAreaQuery
1303 .getProtocolNotifyArray(this.arch
);
1305 for (int i
= 0; i
< protocolNotifyList
.length
; i
++) {
1306 this.mProtocolList
.add(protocolNotifyList
[i
]);
1310 // Get the NAME and GUID from dependence SPD and write to Autogen.c
1312 Iterator protocolIterator
= this.mProtocolList
.iterator();
1313 String protocolKeyWord
= null;
1316 while (protocolIterator
.hasNext()) {
1317 protocolKeyWord
= protocolIterator
.next().toString();
1318 cNameGuid
= GlobalData
.getProtocolGuid(this.mDepPkgList
, protocolKeyWord
);
1319 if (cNameGuid
!= null) {
1321 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1322 fileBuffer
.append(cNameGuid
[0]);
1323 fileBuffer
.append(" = { ");
1324 fileBuffer
.append(CommonDefinition
.formatGuidName(cNameGuid
[1]));
1325 fileBuffer
.append(" } ;");
1328 // If can't find protocol GUID declaration in every package
1330 throw new BuildException("Can not find protocol Guid ["
1331 + protocolKeyWord
+ "] declaration in any SPD package!");
1337 * GuidGuidToAutogenc
1339 * This function gets GUIDs from SPD file accrodeing to <Guids> information
1340 * and write those GUIDs to AutoGen.c.
1343 * String Buffer for Autogen.c file.
1346 void GuidGuidToAutogenC(StringBuffer fileBuffer
) throws AutoGenException
{
1347 String
[] cNameGuid
= null;
1348 String guidKeyWord
= null;
1350 String
[] guidList
= SurfaceAreaQuery
.getGuidEntryArray(this.arch
);
1352 for (int i
= 0; i
< guidList
.length
; i
++) {
1353 this.mGuidList
.add(guidList
[i
]);
1357 Iterator guidIterator
= this.mGuidList
.iterator();
1358 while (guidIterator
.hasNext()) {
1359 guidKeyWord
= guidIterator
.next().toString();
1360 cNameGuid
= GlobalData
.getGuid(this.mDepPkgList
, guidKeyWord
);
1362 if (cNameGuid
!= null) {
1364 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1365 fileBuffer
.append(cNameGuid
[0]);
1366 fileBuffer
.append(" = { ");
1367 fileBuffer
.append(CommonDefinition
.formatGuidName(cNameGuid
[1]));
1368 fileBuffer
.append("} ;");
1371 // If can't find GUID declaration in every package
1373 throw new AutoGenException("Can not find Guid [" + guidKeyWord
1374 + "] declaration in any SPD package. ");
1381 * LibInstanceToAutogenC
1383 * This function adds dependent library instance to autogen.c,which
1384 * includeing library's constructor, destructor, and library dependent ppi,
1385 * protocol, guid, pcd information.
1388 * String buffer for AutoGen.c
1389 * @throws BuildException
1391 void LibInstanceToAutogenC(StringBuffer fileBuffer
) throws BuildException
{
1393 String moduleType
= this.moduleId
.getModuleType();
1395 // Add library constructor to AutoGen.c
1397 LibConstructorToAutogenC(libConstructList
, moduleType
,
1398 fileBuffer
/* autogenC */);
1400 // Add library destructor to AutoGen.c
1402 LibDestructorToAutogenC(libDestructList
, moduleType
, fileBuffer
/* autogenC */);
1403 } catch (Exception e
) {
1404 throw new BuildException(e
.getMessage());
1409 * LibConstructorToAutogenc
1411 * This function writes library constructor list to AutoGen.c. The library
1412 * constructor's parameter and return value depend on module type.
1414 * @param libInstanceList
1415 * List of library construct name.
1419 * String buffer for AutoGen.c
1422 void LibConstructorToAutogenC(List
<String
> libInstanceList
,
1423 String moduleType
, StringBuffer fileBuffer
) throws Exception
{
1424 boolean isFirst
= true;
1427 // The library constructor's parameter and return value depend on
1430 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1431 switch (CommonDefinition
.getModuleType(moduleType
)) {
1432 case CommonDefinition
.ModuleTypeBase
:
1433 fileBuffer
.append("RETURN_STATUS\r\n");
1434 fileBuffer
.append("EFIAPI\r\n");
1435 fileBuffer
.append(libInstanceList
.get(i
));
1436 fileBuffer
.append(" (\r\n");
1437 fileBuffer
.append(" VOID\r\n");
1438 fileBuffer
.append(" );\r\n");
1441 case CommonDefinition
.ModuleTypePeiCore
:
1442 case CommonDefinition
.ModuleTypePeim
:
1443 fileBuffer
.append("EFI_STATUS\r\n");
1444 fileBuffer
.append("EFIAPI\r\n");
1445 fileBuffer
.append(libInstanceList
.get(i
));
1446 fileBuffer
.append(" (\r\n");
1448 .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1450 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1451 fileBuffer
.append(" );\r\n");
1454 case CommonDefinition
.ModuleTypeDxeCore
:
1455 case CommonDefinition
.ModuleTypeDxeDriver
:
1456 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1457 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1458 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1459 case CommonDefinition
.ModuleTypeUefiDriver
:
1460 case CommonDefinition
.ModuleTypeUefiApplication
:
1461 fileBuffer
.append("EFI_STATUS\r\n");
1462 fileBuffer
.append("EFIAPI\r\n");
1463 fileBuffer
.append(libInstanceList
.get(i
));
1464 fileBuffer
.append(" (\r\n");
1465 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1466 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1467 fileBuffer
.append(" );\r\n");
1473 // Add ProcessLibraryConstructorList in AutoGen.c
1475 fileBuffer
.append("VOID\r\n");
1476 fileBuffer
.append("EFIAPI\r\n");
1477 fileBuffer
.append("ProcessLibraryConstructorList (\r\n");
1478 switch (CommonDefinition
.getModuleType(moduleType
)) {
1479 case CommonDefinition
.ModuleTypeBase
:
1480 fileBuffer
.append(" VOID\r\n");
1483 case CommonDefinition
.ModuleTypePeiCore
:
1484 case CommonDefinition
.ModuleTypePeim
:
1485 fileBuffer
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1487 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1490 case CommonDefinition
.ModuleTypeDxeCore
:
1491 case CommonDefinition
.ModuleTypeDxeDriver
:
1492 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1493 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1494 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1495 case CommonDefinition
.ModuleTypeUefiDriver
:
1496 case CommonDefinition
.ModuleTypeUefiApplication
:
1497 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1498 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1502 fileBuffer
.append(" )\r\n");
1503 fileBuffer
.append("{\r\n");
1505 // If no constructor function, return EFI_SUCCESS.
1507 //if (libInstanceList.size() == 0){
1508 // fileBuffer.append(" return EFI_SUCCESS;\r\n");
1510 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1512 fileBuffer
.append(" EFI_STATUS Status;\r\n");
1513 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n");
1514 fileBuffer
.append("\r\n");
1517 switch (CommonDefinition
.getModuleType(moduleType
)) {
1518 case CommonDefinition
.ModuleTypeBase
:
1519 fileBuffer
.append(" Status = ");
1520 fileBuffer
.append(libInstanceList
.get(i
));
1521 fileBuffer
.append("();\r\n");
1522 fileBuffer
.append(" VOID\r\n");
1524 case CommonDefinition
.ModuleTypePeiCore
:
1525 case CommonDefinition
.ModuleTypePeim
:
1526 fileBuffer
.append(" Status = ");
1527 fileBuffer
.append(libInstanceList
.get(i
));
1528 fileBuffer
.append(" (FfsHeader, PeiServices);\r\n");
1530 case CommonDefinition
.ModuleTypeDxeCore
:
1531 case CommonDefinition
.ModuleTypeDxeDriver
:
1532 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1533 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1534 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1535 case CommonDefinition
.ModuleTypeUefiDriver
:
1536 case CommonDefinition
.ModuleTypeUefiApplication
:
1537 fileBuffer
.append(" Status = ");
1538 fileBuffer
.append(libInstanceList
.get(i
));
1539 fileBuffer
.append(" (ImageHandle, SystemTable);\r\n");
1542 EdkLog
.log(EdkLog
.EDK_INFO
,"Autogen doesn't know how to deal with module type - " + moduleType
+ "!");
1544 fileBuffer
.append(" ASSERT_EFI_ERROR (Status);\r\n");
1546 fileBuffer
.append("}\r\n");
1550 * LibDestructorToAutogenc
1552 * This function writes library destructor list to AutoGen.c. The library
1553 * destructor's parameter and return value depend on module type.
1555 * @param libInstanceList
1556 * List of library destructor name.
1560 * String buffer for AutoGen.c
1563 void LibDestructorToAutogenC(List
<String
> libInstanceList
,
1564 String moduleType
, StringBuffer fileBuffer
) throws Exception
{
1565 boolean isFirst
= true;
1566 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1567 switch (CommonDefinition
.getModuleType(moduleType
)) {
1568 case CommonDefinition
.ModuleTypeBase
:
1569 fileBuffer
.append("RETURN_STATUS\r\n");
1570 fileBuffer
.append("EFIAPI\r\n");
1571 fileBuffer
.append(libInstanceList
.get(i
));
1572 fileBuffer
.append(" (\r\n");
1573 fileBuffer
.append(" VOID\r\n");
1574 fileBuffer
.append(" );\r\n");
1576 case CommonDefinition
.ModuleTypePeiCore
:
1577 case CommonDefinition
.ModuleTypePeim
:
1578 fileBuffer
.append("EFI_STATUS\r\n");
1579 fileBuffer
.append("EFIAPI\r\n");
1580 fileBuffer
.append(libInstanceList
.get(i
));
1581 fileBuffer
.append(" (\r\n");
1583 .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1585 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1586 fileBuffer
.append(" );\r\n");
1588 case CommonDefinition
.ModuleTypeDxeCore
:
1589 case CommonDefinition
.ModuleTypeDxeDriver
:
1590 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1591 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1592 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1593 case CommonDefinition
.ModuleTypeUefiDriver
:
1594 case CommonDefinition
.ModuleTypeUefiApplication
:
1595 fileBuffer
.append("EFI_STATUS\r\n");
1596 fileBuffer
.append("EFIAPI\r\n");
1597 fileBuffer
.append(libInstanceList
.get(i
));
1598 fileBuffer
.append(" (\r\n");
1599 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1600 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1601 fileBuffer
.append(" );\r\n");
1607 // Write ProcessLibraryDestructor list to autogen.c
1609 switch (CommonDefinition
.getModuleType(moduleType
)) {
1610 case CommonDefinition
.ModuleTypeBase
:
1611 case CommonDefinition
.ModuleTypePeiCore
:
1612 case CommonDefinition
.ModuleTypePeim
:
1614 case CommonDefinition
.ModuleTypeDxeCore
:
1615 case CommonDefinition
.ModuleTypeDxeDriver
:
1616 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1617 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1618 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1619 case CommonDefinition
.ModuleTypeUefiDriver
:
1620 case CommonDefinition
.ModuleTypeUefiApplication
:
1621 fileBuffer
.append("VOID\r\n");
1622 fileBuffer
.append("EFIAPI\r\n");
1623 fileBuffer
.append("ProcessLibraryDestructorList (\r\n");
1624 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1625 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1626 fileBuffer
.append(" )\r\n");
1627 fileBuffer
.append("{\r\n");
1629 // If no library destructor function, return EFI_SUCCESS.
1632 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1634 fileBuffer
.append(" EFI_STATUS Status;\r\n");
1635 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n");
1636 fileBuffer
.append("\r\n");
1639 fileBuffer
.append(" Status = ");
1640 fileBuffer
.append(libInstanceList
.get(i
));
1641 fileBuffer
.append("(ImageHandle, SystemTable);\r\n");
1642 fileBuffer
.append(" ASSERT_EFI_ERROR (Status);\r\n");
1644 fileBuffer
.append("}\r\n");
1650 * ExternsDriverBindingToAutoGenC
1652 * This function is to write DRIVER_BINDING, COMPONENT_NAME,
1653 * DRIVER_CONFIGURATION, DRIVER_DIAGNOSTIC in AutoGen.c.
1656 * String buffer for AutoGen.c
1658 void ExternsDriverBindingToAutoGenC(StringBuffer fileBuffer
)
1659 throws BuildException
{
1662 // Check what <extern> contains. And the number of following elements
1663 // under <extern> should be same. 1. DRIVER_BINDING 2. COMPONENT_NAME
1664 // 3.DRIVER_CONFIGURATION 4. DRIVER_DIAGNOSTIC
1667 String
[] drvBindList
= SurfaceAreaQuery
.getDriverBindingArray();
1670 // If component name protocol,component configuration protocol,
1671 // component diagnostic protocol is not null or empty, check
1672 // if every one have the same number of the driver binding protocol.
1674 if (drvBindList
== null || drvBindList
.length
== 0) {
1678 String
[] compNamList
= SurfaceAreaQuery
.getComponentNameArray();
1679 String
[] compConfList
= SurfaceAreaQuery
.getDriverConfigArray();
1680 String
[] compDiagList
= SurfaceAreaQuery
.getDriverDiagArray();
1685 // Write driver binding protocol extern to autogen.c
1687 for (int i
= 0; i
< drvBindList
.length
; i
++) {
1688 fileBuffer
.append("extern EFI_DRIVER_BINDING_PROTOCOL ");
1689 fileBuffer
.append(drvBindList
[i
]);
1690 fileBuffer
.append(";\r\n");
1694 // Write component name protocol extern to autogen.c
1696 if (compNamList
!= null && compNamList
.length
!= 0) {
1697 if (drvBindList
.length
!= compNamList
.length
) {
1698 throw new BuildException(
1699 "Different number of Driver Binding and Component Name protocols!");
1703 for (int i
= 0; i
< compNamList
.length
; i
++) {
1704 fileBuffer
.append("extern EFI_COMPONENT_NAME_PROTOCOL ");
1705 fileBuffer
.append(compNamList
[i
]);
1706 fileBuffer
.append(";\r\n");
1711 // Write driver configration protocol extern to autogen.c
1713 if (compConfList
!= null && compConfList
.length
!= 0) {
1714 if (drvBindList
.length
!= compConfList
.length
) {
1715 throw new BuildException(
1716 "Different number of Driver Binding and Driver Configuration protocols!");
1720 for (int i
= 0; i
< compConfList
.length
; i
++) {
1721 fileBuffer
.append("extern EFI_DRIVER_CONFIGURATION_PROTOCOL ");
1722 fileBuffer
.append(compConfList
[i
]);
1723 fileBuffer
.append(";\r\n");
1728 // Write driver dignastic protocol extern to autogen.c
1730 if (compDiagList
!= null && compDiagList
.length
!= 0) {
1731 if (drvBindList
.length
!= compDiagList
.length
) {
1732 throw new BuildException(
1733 "Different number of Driver Binding and Driver Diagnosis protocols!");
1737 for (int i
= 0; i
< compDiagList
.length
; i
++) {
1738 fileBuffer
.append("extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL ");
1739 fileBuffer
.append(compDiagList
[i
]);
1740 fileBuffer
.append(";\r\n");
1745 // Write driver module protocol bitmask.
1748 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverModelProtocolBitmask = ");
1749 fileBuffer
.append(Integer
.toString(BitMask
));
1750 fileBuffer
.append(";\r\n");
1753 // Write driver module protocol list entry
1756 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverModelProtocolListEntries = ");
1758 fileBuffer
.append(Integer
.toString(drvBindList
.length
));
1759 fileBuffer
.append(";\r\n");
1762 // Write drive module protocol list to autogen.c
1765 .append("GLOBAL_REMOVE_IF_UNREFERENCED const EFI_DRIVER_MODEL_PROTOCOL_LIST _gDriverModelProtocolList[] = {");
1766 for (int i
= 0; i
< drvBindList
.length
; i
++) {
1768 fileBuffer
.append(",");
1770 fileBuffer
.append("\r\n {\r\n");
1771 fileBuffer
.append(" &");
1772 fileBuffer
.append(drvBindList
[i
]);
1773 fileBuffer
.append(", \r\n");
1775 if (compNamList
!= null) {
1776 fileBuffer
.append(" &");
1777 fileBuffer
.append(compNamList
[i
]);
1778 fileBuffer
.append(", \r\n");
1780 fileBuffer
.append(" NULL, \r\n");
1783 if (compConfList
!= null) {
1784 fileBuffer
.append(" &");
1785 fileBuffer
.append(compConfList
[i
]);
1786 fileBuffer
.append(", \r\n");
1788 fileBuffer
.append(" NULL, \r\n");
1791 if (compDiagList
!= null) {
1792 fileBuffer
.append(" &");
1793 fileBuffer
.append(compDiagList
[i
]);
1794 fileBuffer
.append(", \r\n");
1796 fileBuffer
.append(" NULL, \r\n");
1798 fileBuffer
.append(" }");
1800 fileBuffer
.append("\r\n};\r\n");
1804 * ExternCallBackToAutoGenC
1806 * This function adds <SetVirtualAddressMapCallBack> and
1807 * <ExitBootServicesCallBack> infomation to AutoGen.c
1810 * String buffer for AutoGen.c
1811 * @throws BuildException
1813 void ExternCallBackToAutoGenC(StringBuffer fileBuffer
)
1814 throws BuildException
{
1816 // Collect module's <SetVirtualAddressMapCallBack> and
1817 // <ExitBootServiceCallBack> and add to setVirtualAddList
1818 // exitBootServiceList.
1820 String
[] setVirtuals
= SurfaceAreaQuery
.getSetVirtualAddressMapCallBackArray();
1821 String
[] exitBoots
= SurfaceAreaQuery
.getExitBootServicesCallBackArray();
1822 if (setVirtuals
!= null) {
1823 for (int j
= 0; j
< setVirtuals
.length
; j
++) {
1824 this.setVirtalAddList
.add(setVirtuals
[j
]);
1827 if (exitBoots
!= null) {
1828 for (int k
= 0; k
< exitBoots
.length
; k
++) {
1829 this.exitBootServiceList
.add(exitBoots
[k
]);
1833 // Add c code in autogen.c which relate to <SetVirtualAddressMapCallBack>
1834 // and <ExitBootServicesCallBack>
1836 String moduleType
= this.moduleId
.getModuleType();
1837 boolean UefiOrDxeModule
= false;
1840 switch (CommonDefinition
.getModuleType(moduleType
)) {
1841 case CommonDefinition
.ModuleTypeDxeDriver
:
1842 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1843 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1844 case CommonDefinition
.ModuleTypeUefiDriver
:
1845 case CommonDefinition
.ModuleTypeUefiApplication
:
1847 // Entry point lib for these module types needs to know the count
1850 UefiOrDxeModule
= true;
1852 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverSetVirtualAddressMapEventCount = ");
1855 // If the list is not valid or has no entries set count to zero else
1856 // set count to the number of valid entries
1859 if (this.setVirtalAddList
!= null) {
1860 for (i
= 0; i
< this.setVirtalAddList
.size(); i
++) {
1861 if (this.setVirtalAddList
.get(i
).equalsIgnoreCase("")) {
1868 fileBuffer
.append(Integer
.toString(Count
));
1869 fileBuffer
.append(";\r\n\r\n");
1875 if (this.setVirtalAddList
== null || this.setVirtalAddList
.size() == 0) {
1876 if (UefiOrDxeModule
) {
1878 // No data so make a NULL list
1881 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {\r\n");
1882 fileBuffer
.append(" NULL\r\n");
1883 fileBuffer
.append("};\r\n\r\n");
1887 // Write SetVirtualAddressMap function definition.
1889 for (i
= 0; i
< this.setVirtalAddList
.size(); i
++) {
1890 if (this.setVirtalAddList
.get(i
).equalsIgnoreCase("")) {
1893 fileBuffer
.append("VOID\r\n");
1894 fileBuffer
.append("EFIAPI\r\n");
1895 fileBuffer
.append(this.setVirtalAddList
.get(i
));
1896 fileBuffer
.append(" (\r\n");
1897 fileBuffer
.append(" IN EFI_EVENT Event,\r\n");
1898 fileBuffer
.append(" IN VOID *Context\r\n");
1899 fileBuffer
.append(" );\r\n\r\n");
1903 // Write SetVirtualAddressMap entry point array.
1906 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {");
1907 for (i
= 0; i
< this.setVirtalAddList
.size(); i
++) {
1908 if (this.setVirtalAddList
.get(i
).equalsIgnoreCase("")) {
1913 fileBuffer
.append("\r\n ");
1915 fileBuffer
.append(",\r\n ");
1918 fileBuffer
.append(this.setVirtalAddList
.get(i
));
1921 // If module is not DXE_DRIVER, DXE_RUNTIME_DIRVER, UEFI_DRIVER
1922 // UEFI_APPLICATION and DXE_SAL_DRIVER add the NULL at the end of
1923 // _gDriverSetVirtualAddressMapEvent list.
1925 if (!UefiOrDxeModule
) {
1926 fileBuffer
.append(",\r\n NULL");
1928 fileBuffer
.append("\r\n};\r\n\r\n");
1931 if (UefiOrDxeModule
) {
1933 // Entry point lib for these module types needs to know the count.
1936 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverExitBootServicesEventCount = ");
1939 // If the list is not valid or has no entries set count to zero else
1940 // set count to the number of valid entries.
1943 if (this.exitBootServiceList
!= null) {
1944 for (i
= 0; i
< this.exitBootServiceList
.size(); i
++) {
1945 if (this.exitBootServiceList
.get(i
).equalsIgnoreCase("")) {
1951 fileBuffer
.append(Integer
.toString(Count
));
1952 fileBuffer
.append(";\r\n\r\n");
1955 if (this.exitBootServiceList
== null || this.exitBootServiceList
.size() == 0) {
1956 if (UefiOrDxeModule
) {
1958 // No data so make a NULL list.
1961 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {\r\n");
1962 fileBuffer
.append(" NULL\r\n");
1963 fileBuffer
.append("};\r\n\r\n");
1967 // Write DriverExitBootServices function definition.
1969 for (i
= 0; i
< this.exitBootServiceList
.size(); i
++) {
1970 if (this.exitBootServiceList
.get(i
).equalsIgnoreCase("")) {
1974 fileBuffer
.append("VOID\r\n");
1975 fileBuffer
.append("EFIAPI\r\n");
1976 fileBuffer
.append(this.exitBootServiceList
.get(i
));
1977 fileBuffer
.append(" (\r\n");
1978 fileBuffer
.append(" IN EFI_EVENT Event,\r\n");
1979 fileBuffer
.append(" IN VOID *Context\r\n");
1980 fileBuffer
.append(" );\r\n\r\n");
1984 // Write DriverExitBootServices entry point array.
1987 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {");
1988 for (i
= 0; i
< this.exitBootServiceList
.size(); i
++) {
1989 if (this.exitBootServiceList
.get(i
).equalsIgnoreCase("")) {
1994 fileBuffer
.append("\r\n ");
1996 fileBuffer
.append(",\r\n ");
1998 fileBuffer
.append(this.exitBootServiceList
.get(i
));
2000 if (!UefiOrDxeModule
) {
2001 fileBuffer
.append(",\r\n NULL");
2003 fileBuffer
.append("\r\n};\r\n\r\n");
2008 private void copyFlashMapHToDebugDir() throws AutoGenException
{
2010 File inFile
= new File(fvDir
+ File
.separatorChar
+ CommonDefinition
.flashMapH
);
2011 int size
= (int)inFile
.length();
2012 byte[] buffer
= new byte[size
];
2013 File outFile
= new File (this.outputPath
+ File
.separatorChar
+ CommonDefinition
.tianoR8FlashMapH
);
2015 // If TianoR8FlashMap.h existed and the flashMap.h don't change,
2018 if ((!outFile
.exists()) ||(inFile
.lastModified() - outFile
.lastModified()) >= 0) {
2020 if (inFile
.exists()) {
2021 FileInputStream fis
= new FileInputStream (inFile
);
2023 FileOutputStream fos
= new FileOutputStream(outFile
);
2028 throw new AutoGenException("The file, flashMap.h doesn't exist!");
2030 } catch (Exception e
) {
2031 throw new AutoGenException(e
.getMessage());
2037 *This function first order the library instances, then collect
2038 *library instance 's PPI, Protocol, GUID,
2039 *SetVirtalAddressMapCallBack, ExitBootServiceCallBack, and
2040 *Destructor, Constructor.
2043 private void collectLibInstanceInfo(){
2046 String moduleType
= SurfaceAreaQuery
.getModuleType();
2047 String libConstructName
= null;
2048 String libDestructName
= null;
2049 String
[] setVirtuals
= null;
2050 String
[] exitBoots
= null;
2052 ModuleIdentification
[] libraryIdList
= SurfaceAreaQuery
2053 .getLibraryInstance(this.arch
);
2055 if (libraryIdList
!= null) {
2057 // Reorder library instance sequence.
2059 AutogenLibOrder libOrder
= new AutogenLibOrder(libraryIdList
,
2061 List
<ModuleIdentification
> orderList
= libOrder
2062 .orderLibInstance();
2064 if (orderList
!= null) {
2066 // Process library instance one by one.
2068 for (int i
= 0; i
< orderList
.size(); i
++) {
2071 // Get library instance basename.
2073 ModuleIdentification libInstanceId
= orderList
.get(i
);
2079 Map
<String
, XmlObject
> libDoc
= GlobalData
.getDoc(libInstanceId
, this.arch
);
2080 SurfaceAreaQuery
.push(libDoc
);
2082 // Get <PPis>, <Protocols>, <Guids> list of this library
2085 String
[] ppiList
= SurfaceAreaQuery
.getPpiArray(this.arch
);
2086 String
[] ppiNotifyList
= SurfaceAreaQuery
2087 .getPpiNotifyArray(this.arch
);
2088 String
[] protocolList
= SurfaceAreaQuery
2089 .getProtocolArray(this.arch
);
2090 String
[] protocolNotifyList
= SurfaceAreaQuery
2091 .getProtocolNotifyArray(this.arch
);
2092 String
[] guidList
= SurfaceAreaQuery
2093 .getGuidEntryArray(this.arch
);
2094 String
[] libraryClassList
= SurfaceAreaQuery
.getLibraryClasses(
2095 CommonDefinition
.AlwaysConsumed
,
2097 PackageIdentification
[] pkgList
= SurfaceAreaQuery
.getDependencePkg(this.arch
);
2100 // Add those ppi, protocol, guid in global ppi,
2104 for (index
= 0; index
< ppiList
.length
; index
++) {
2105 this.mPpiList
.add(ppiList
[index
]);
2108 for (index
= 0; index
< ppiNotifyList
.length
; index
++) {
2109 this.mPpiList
.add(ppiNotifyList
[index
]);
2112 for (index
= 0; index
< protocolList
.length
; index
++) {
2113 this.mProtocolList
.add(protocolList
[index
]);
2116 for (index
= 0; index
< protocolNotifyList
.length
; index
++) {
2117 this.mProtocolList
.add(protocolNotifyList
[index
]);
2120 for (index
= 0; index
< guidList
.length
; index
++) {
2121 this.mGuidList
.add(guidList
[index
]);
2123 for (index
= 0; index
< pkgList
.length
; index
++) {
2124 if (!this.mDepPkgList
.contains(pkgList
[index
])) {
2125 this.mDepPkgList
.add(pkgList
[index
]);
2128 for (index
= 0; index
< libraryClassList
.length
; index
++) {
2129 if (libraryClassList
[index
].equalsIgnoreCase(CommonDefinition
.pcdLibName
)) {
2130 this.isModuleLibraryInstanceUsePcd
= true;
2134 // If not yet parse this library instance's constructor
2135 // element,parse it.
2137 libConstructName
= SurfaceAreaQuery
2138 .getLibConstructorName();
2139 libDestructName
= SurfaceAreaQuery
2140 .getLibDestructorName();
2143 // Collect SetVirtualAddressMapCallBack and
2144 // ExitBootServiceCallBack.
2146 setVirtuals
= SurfaceAreaQuery
.getSetVirtualAddressMapCallBackArray();
2147 exitBoots
= SurfaceAreaQuery
.getExitBootServicesCallBackArray();
2148 if (setVirtuals
!= null) {
2149 for (int j
= 0; j
< setVirtuals
.length
; j
++) {
2150 this.setVirtalAddList
.add(setVirtuals
[j
]);
2153 if (exitBoots
!= null) {
2154 for (int k
= 0; k
< exitBoots
.length
; k
++) {
2155 this.exitBootServiceList
.add(exitBoots
[k
]);
2158 SurfaceAreaQuery
.pop();
2160 // Add dependent library instance constructor function.
2162 if (libConstructName
!= null) {
2163 this.libConstructList
.add(libConstructName
);
2166 // Add dependent library instance destructor fuction.
2168 if (libDestructName
!= null) {
2169 this.libDestructList
.add(libDestructName
);
2176 } catch (Exception e
) {
2177 System
.out
.println(e
.getMessage());
2178 System
.out
.println("Collect library instance failed!");