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
.build
.exception
.*;
37 import org
.tianocore
.build
.global
.GlobalData
;
38 import org
.tianocore
.build
.global
.SurfaceAreaQuery
;
39 import org
.tianocore
.build
.id
.ModuleIdentification
;
40 import org
.tianocore
.build
.id
.PackageIdentification
;
41 import org
.tianocore
.build
.pcd
.action
.PCDAutoGenAction
;
43 import org
.tianocore
.common
.logger
.EdkLog
;
46 * This class is to generate Autogen.h and Autogen.c according to module surface
47 * area or library surface area.
49 public class AutoGen
{
51 /// The output path of Autogen.h and Autogen.c
53 private String outputPath
;
56 /// The name of FV directory
61 /// The base name of module or library.
63 private ModuleIdentification moduleId
;
66 /// The build architecture
71 /// PcdAutogen instance which is used to manage how to generate the PCD
74 private PCDAutoGenAction myPcdAutogen
;
77 /// the one of type : NOT_PCD_DRIVER, PEI_PCD_DRIVER, DXE_PCD_DRIVER
79 private CommonDefinition
.PCD_DRIVER_TYPE pcdDriverType
;
82 /// Judge whether this module's library instance use PcdLib library class
84 private boolean isModuleLibraryInstanceUsePcd
;
87 /// The protocl list which records in module or library surface area and
88 /// it's dependence on library instance surface area.
90 private Set
<String
> mProtocolList
= new HashSet
<String
>();
93 /// The Ppi list which recorded in module or library surface area and its
94 /// dependency on library instance surface area.
96 private Set
<String
> mPpiList
= new HashSet
<String
>();
99 /// The Guid list which recoreded in module or library surface area and it's
100 /// dependence on library instance surface area.
102 private Set
<String
> mGuidList
= new HashSet
<String
>();
105 // The dependence package list which recoreded in module or library surface
106 // area and it's dependence on library instance surface are.
108 private List
<PackageIdentification
> mDepPkgList
= new LinkedList
<PackageIdentification
>();
111 // For non library module, add its library instance's construct and destructor to
114 private List
<String
> libConstructList
= new ArrayList
<String
>();
115 private List
<String
> libDestructList
= new ArrayList
<String
>();
118 // List to store SetVirtalAddressMapCallBack, ExitBootServiceCallBack
120 private List
<String
> setVirtalAddList
= new ArrayList
<String
>();
121 private List
<String
> exitBootServiceList
= new ArrayList
<String
>();
127 * This function mainly initialize some member variable.
130 * Output path of AutoGen file.
134 * Target architecture.
136 public AutoGen(String fvDir
, String outputPath
, ModuleIdentification moduleId
, String arch
) {
137 this.outputPath
= outputPath
;
138 this.moduleId
= moduleId
;
147 * This function save the content in stringBuffer to file.
152 * The content of AutoGen file in buffer.
153 * @return "true" successful, "false" failed.
155 private boolean saveFile(String fileName
, StringBuffer fileBuffer
) {
157 File autoGenH
= new File(fileName
);
160 // if the file exists, compare their content
162 if (autoGenH
.exists()) {
163 FileReader fIn
= new FileReader(autoGenH
);
164 char[] oldFileBuffer
= new char[(int) autoGenH
.length()];
165 fIn
.read(oldFileBuffer
, 0, (int) autoGenH
.length());
169 // if we got the same file, don't re-generate it to prevent
170 // sources depending on it from re-building
172 if (fileBuffer
.toString().compareTo(new String(oldFileBuffer
)) == 0) {
176 FileWriter fOut
= new FileWriter(autoGenH
);
177 fOut
.write(fileBuffer
.toString());
179 } catch (Exception e
) {
186 * genAutogen function
188 * This function call libGenAutoGen or moduleGenAutogen function, which
189 * dependence on generate library autogen or module autogen.
191 * @throws BuildException
192 * Failed to creat AutoGen.c & AutoGen.h.
194 public void genAutogen() throws BuildException
{
197 // If outputPath do not exist, create it.
199 File path
= new File(outputPath
);
203 // Check current is library or not, then call the corresponding
206 if (this.moduleId
.isLibrary()) {
212 } catch (Exception e
) {
213 throw new BuildException(
214 "Failed to create AutoGen.c & AutoGen.h!\n"
220 * moduleGenAutogen function
222 * This function generates AutoGen.c & AutoGen.h for module.
224 * @throws BuildException
225 * Faile to create module AutoGen.c & AutoGen.h.
227 void moduleGenAutogen() throws BuildException
{
230 collectLibInstanceInfo();
233 } catch (Exception e
) {
234 throw new BuildException(
235 "Faile to create module AutoGen.c & AutoGen.h!\n"
241 * libGenAutogen function
243 * This function generates AutoGen.c & AutoGen.h for library.
245 * @throws BuildException
246 * Faile to create library AutoGen.c & AutoGen.h
248 void libGenAutogen() throws BuildException
{
252 } catch (Exception e
) {
253 throw new BuildException(
254 "Failed to create library AutoGen.c & AutoGen.h!\n"
262 * This function generates AutoGen.h for module.
264 * @throws BuildException
265 * Failed to generate AutoGen.h.
267 void moduleGenAutogenH() throws AutoGenException
{
269 Set
<String
> libClassIncludeH
;
271 // List<String> headerFileList;
272 List
<String
> headerFileList
;
274 StringBuffer fileBuffer
= new StringBuffer(8192);
277 // Write Autogen.h header notation
279 fileBuffer
.append(CommonDefinition
.autogenHNotation
);
282 // Add #ifndef ${BaseName}_AUTOGENH
283 // #def ${BseeName}_AUTOGENH
285 fileBuffer
.append("#ifndef " + "_AUTOGENH_" + this.moduleId
.getGuid().replaceAll("-", "_") +"\r\n");
286 fileBuffer
.append("#define " + "_AUTOGENH_" + this.moduleId
.getGuid().replaceAll("-", "_") +"\r\n\r\n");
289 // Write the specification version and release version at the begine
290 // of autogen.h file.
291 // Note: the specification version and release version should
292 // be got from module surface area instead of hard code by it's
295 moduleType
= SurfaceAreaQuery
.getModuleType();
298 // Add "extern int __make_me_compile_correctly;" at begin of
301 fileBuffer
.append(CommonDefinition
.autoGenHbegin
);
304 // Put EFI_SPECIFICATION_VERSION, and EDK_RELEASE_VERSION.
306 String
[] specList
= SurfaceAreaQuery
.getExternSpecificaiton();
307 for (int i
= 0; i
< specList
.length
; i
++) {
308 fileBuffer
.append(CommonDefinition
.marcDefineStr
+ specList
[i
]
312 // Write consumed package's mdouleInfo related .h file to autogen.h
314 // PackageIdentification[] consumedPkgIdList = SurfaceAreaQuery
315 // .getDependencePkg(this.arch);
316 PackageIdentification
[] consumedPkgIdList
= SurfaceAreaQuery
317 .getDependencePkg(this.arch
);
318 if (consumedPkgIdList
!= null) {
319 headerFileList
= depPkgToAutogenH(consumedPkgIdList
, moduleType
);
320 item
= headerFileList
.iterator();
321 while (item
.hasNext()) {
322 fileBuffer
.append(item
.next().toString());
327 // Write library class's related *.h file to autogen.h.
329 String
[] libClassList
= SurfaceAreaQuery
330 .getLibraryClasses(CommonDefinition
.AlwaysConsumed
,this.arch
);
331 boolean isModuleConsumePcdLib
= false;
332 List
<String
> libClassArray
= new ArrayList
<String
>();
333 for (int index
= 0; index
< libClassList
.length
; index
++) {
334 libClassArray
.add(libClassList
[index
]);
336 // Search all library class of a module for PcdLib
338 if (libClassList
[index
].equalsIgnoreCase(CommonDefinition
.pcdLibName
)) {
339 isModuleConsumePcdLib
= true;
344 // If module do not use PCD but module's library use PCD.
346 if (!isModuleConsumePcdLib
&& this.isModuleLibraryInstanceUsePcd
) {
347 libClassArray
.add(CommonDefinition
.pcdLibName
);
350 libClassList
= new String
[libClassArray
.size()];
351 libClassArray
.toArray(libClassList
);
353 if (libClassList
!= null) {
354 libClassIncludeH
= LibraryClassToAutogenH(libClassList
);
355 item
= libClassIncludeH
.iterator();
356 while (item
.hasNext()) {
357 fileBuffer
.append(item
.next().toString());
361 libClassList
= SurfaceAreaQuery
362 .getLibraryClasses(CommonDefinition
.AlwaysProduced
, this.arch
);
363 if (libClassList
!= null) {
364 libClassIncludeH
= LibraryClassToAutogenH(libClassList
);
365 item
= libClassIncludeH
.iterator();
366 while (item
.hasNext()) {
367 fileBuffer
.append(item
.next().toString());
370 fileBuffer
.append("\r\n");
373 // If is TianoR8FlashMap, copy {Fv_DIR}/FlashMap.h to
374 // {DEST_DIR_DRBUG}/FlashMap.h
376 if (SurfaceAreaQuery
.isHaveTianoR8FlashMap()) {
377 fileBuffer
.append(CommonDefinition
.include
);
378 fileBuffer
.append(" <");
379 fileBuffer
.append(CommonDefinition
.tianoR8FlashMapH
+ ">\r\n");
380 copyFlashMapHToDebugDir();
383 // Write PCD autogen information to AutoGen.h.
385 if (this.myPcdAutogen
!= null) {
386 fileBuffer
.append("\r\n");
387 fileBuffer
.append(this.myPcdAutogen
.getHAutoGenString());
391 // Append the #endif at AutoGen.h
393 fileBuffer
.append("#endif\r\n");
396 // Save string buffer content in AutoGen.h.
398 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.h", fileBuffer
)) {
399 throw new BuildException("Failed to generate AutoGen.h !!!");
406 * This function generates AutoGen.c for module.
408 * @throws BuildException
409 * Failed to generate AutoGen.c.
411 void moduleGenAutogenC() throws AutoGenException
{
413 StringBuffer fileBuffer
= new StringBuffer(8192);
415 // Write Autogen.c header notation
417 fileBuffer
.append(CommonDefinition
.autogenCNotation
);
420 // Write #include <AutoGen.h> at beginning of AutoGen.c
422 fileBuffer
.append(CommonDefinition
.includeAutogenH
);
425 // Get the native MSA file infomation. Since before call autogen,
426 // the MSA native <Externs> information were overrided. So before
427 // process <Externs> it should be set the DOC as the Native MSA info.
429 Map
<String
, XmlObject
> doc
= GlobalData
.getNativeMsa(this.moduleId
);
430 SurfaceAreaQuery
.push(doc
);
433 // DriverBinding/ComponentName/DriverConfiguration/DriverDialog
437 ExternsDriverBindingToAutoGenC(fileBuffer
);
440 // Write DriverExitBootServicesEvent/DriverSetVirtualAddressMapEvent
443 ExternCallBackToAutoGenC(fileBuffer
);
446 // Write EntryPoint to autgoGen.c
448 String
[] entryPointList
= SurfaceAreaQuery
.getModuleEntryPointArray();
449 EntryPointToAutoGen(CommonDefinition
.remDupString(entryPointList
), fileBuffer
);
451 pcdDriverType
= SurfaceAreaQuery
.getPcdDriverType();
454 // Restore the DOC which include the FPD module info.
456 SurfaceAreaQuery
.pop();
459 // Write Guid to autogen.c
461 String guid
= CommonDefinition
.formatGuidName(SurfaceAreaQuery
465 .append("GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiCallerIdGuid = {");
467 throw new AutoGenException("Guid value must set!\n");
471 // Formate Guid as ANSI c form.Example:
472 // {0xd2b2b828, 0x826, 0x48a7,{0xb3, 0xdf, 0x98, 0x3c, 0x0, 0x60, 0x24,
476 fileBuffer
.append(guid
);
477 fileBuffer
.append("};\r\n");
480 // Generate library instance consumed protocol, guid, ppi, pcd list.
481 // Save those to this.protocolList, this.ppiList, this.pcdList,
482 // this.guidList. Write Consumed library constructor and desconstuct to
485 LibInstanceToAutogenC(fileBuffer
);
488 // Get module dependent Package identification.
490 PackageIdentification
[] packages
= SurfaceAreaQuery
.getDependencePkg(this.arch
);
491 for (int i
= 0; i
< packages
.length
; i
++) {
492 if (!this.mDepPkgList
.contains(packages
[i
])) {
493 this.mDepPkgList
.add(packages
[i
]);
499 // Write consumed ppi, guid, protocol to autogen.c
501 ProtocolGuidToAutogenC(fileBuffer
);
502 PpiGuidToAutogenC(fileBuffer
);
503 GuidGuidToAutogenC(fileBuffer
);
508 this.myPcdAutogen
= new PCDAutoGenAction(moduleId
,
514 this.myPcdAutogen
.execute();
515 } catch (Exception exp
) {
516 throw new PcdAutogenException (exp
.getMessage());
519 if (this.myPcdAutogen
!= null) {
520 fileBuffer
.append("\r\n");
521 fileBuffer
.append(this.myPcdAutogen
.getCAutoGenString());
524 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.c", fileBuffer
)) {
525 throw new BuildException("Failed to generate AutoGen.c !!!");
533 * This function generates AutoGen.h for library.
535 * @throws BuildException
536 * Failed to generate AutoGen.c.
538 void libGenAutogenH() throws AutoGenException
{
540 Set
<String
> libClassIncludeH
;
542 List
<String
> headerFileList
;
544 StringBuffer fileBuffer
= new StringBuffer(10240);
547 // Write Autogen.h header notation
549 fileBuffer
.append(CommonDefinition
.autogenHNotation
);
552 // Add #ifndef ${BaseName}_AUTOGENH
553 // #def ${BseeName}_AUTOGENH
555 fileBuffer
.append("#ifndef " + "_AUTOGENH_" + this.moduleId
.getGuid().replaceAll("-", "_") + "\r\n");
556 fileBuffer
.append("#define " + "_AUTOGENH_" + this.moduleId
.getGuid().replaceAll("-", "_") + "\r\n\r\n");
559 // Write EFI_SPECIFICATION_VERSION and EDK_RELEASE_VERSION
560 // to autogen.h file.
561 // Note: the specification version and release version should
562 // be get from module surface area instead of hard code.
564 fileBuffer
.append(CommonDefinition
.autoGenHbegin
);
565 String
[] specList
= SurfaceAreaQuery
.getExternSpecificaiton();
566 for (int i
= 0; i
< specList
.length
; i
++) {
567 fileBuffer
.append(CommonDefinition
.marcDefineStr
+ specList
[i
]
570 // fileBuffer.append(CommonDefinition.autoGenHLine1);
571 // fileBuffer.append(CommonDefinition.autoGenHLine2);
574 // Write consumed package's mdouleInfo related *.h file to autogen.h.
576 moduleType
= SurfaceAreaQuery
.getModuleType();
577 PackageIdentification
[] cosumedPkglist
= SurfaceAreaQuery
578 .getDependencePkg(this.arch
);
579 headerFileList
= depPkgToAutogenH(cosumedPkglist
, moduleType
);
580 item
= headerFileList
.iterator();
581 while (item
.hasNext()) {
582 fileBuffer
.append(item
.next().toString());
585 // Write library class's related *.h file to autogen.h
587 String
[] libClassList
= SurfaceAreaQuery
588 .getLibraryClasses(CommonDefinition
.AlwaysConsumed
, this.arch
);
589 if (libClassList
!= null) {
590 libClassIncludeH
= LibraryClassToAutogenH(libClassList
);
591 item
= libClassIncludeH
.iterator();
592 while (item
.hasNext()) {
593 fileBuffer
.append(item
.next().toString());
597 libClassList
= SurfaceAreaQuery
598 .getLibraryClasses(CommonDefinition
.AlwaysProduced
, this.arch
);
599 if (libClassList
!= null) {
600 libClassIncludeH
= LibraryClassToAutogenH(libClassList
);
601 item
= libClassIncludeH
.iterator();
602 while (item
.hasNext()) {
603 fileBuffer
.append(item
.next().toString());
606 fileBuffer
.append("\r\n");
609 // If is TianoR8FlashMap, copy {Fv_DIR}/FlashMap.h to
610 // {DEST_DIR_DRBUG}/FlashMap.h
612 if (SurfaceAreaQuery
.isHaveTianoR8FlashMap()) {
613 fileBuffer
.append(CommonDefinition
.include
);
614 fileBuffer
.append(" <");
615 fileBuffer
.append(CommonDefinition
.tianoR8FlashMapH
+ ">\r\n");
616 copyFlashMapHToDebugDir();
620 // Write PCD information to library AutoGen.h.
622 if (this.myPcdAutogen
!= null) {
623 fileBuffer
.append("\r\n");
624 fileBuffer
.append(this.myPcdAutogen
.getHAutoGenString());
628 // Append the #endif at AutoGen.h
630 fileBuffer
.append("#endif\r\n");
633 // Save content of string buffer to AutoGen.h file.
635 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.h", fileBuffer
)) {
636 throw new BuildException("Failed to generate AutoGen.h !!!");
643 * This function generates AutoGen.h for library.
645 * @throws BuildException
646 * Failed to generate AutoGen.c.
648 void libGenAutogenC() throws BuildException
, PcdAutogenException
{
649 StringBuffer fileBuffer
= new StringBuffer(10240);
652 // Write Autogen.c header notation
654 fileBuffer
.append(CommonDefinition
.autogenCNotation
);
656 fileBuffer
.append(CommonDefinition
.autoGenCLine1
);
657 fileBuffer
.append("\r\n");
662 this.myPcdAutogen
= new PCDAutoGenAction(moduleId
,
665 SurfaceAreaQuery
.getModulePcdEntryNameArray(),
668 this.myPcdAutogen
.execute();
669 } catch (Exception e
) {
670 throw new PcdAutogenException(e
.getMessage());
673 if (this.myPcdAutogen
!= null) {
674 fileBuffer
.append("\r\n");
675 fileBuffer
.append(this.myPcdAutogen
.getCAutoGenString());
678 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.c", fileBuffer
)) {
679 throw new BuildException("Failed to generate AutoGen.c !!!");
684 * LibraryClassToAutogenH
686 * This function returns *.h files declared by library classes which are
687 * consumed or produced by current build module or library.
689 * @param libClassList
690 * List of library class which consumed or produce by current
691 * build module or library.
692 * @return includeStrList List of *.h file.
694 Set
<String
> LibraryClassToAutogenH(String
[] libClassList
)
695 throws AutoGenException
{
696 Set
<String
> includStrList
= new LinkedHashSet
<String
>();
697 String includerName
[];
701 // Get include file from GlobalData's SPDTable according to
702 // library class name.
704 for (int i
= 0; i
< libClassList
.length
; i
++) {
705 includerName
= GlobalData
.getLibraryClassHeaderFiles(
706 SurfaceAreaQuery
.getDependencePkg(this.arch
),
708 if (includerName
== null) {
709 throw new AutoGenException("Can not find library class ["
710 + libClassList
[i
] + "] declaration in any SPD package. ");
712 for (int j
= 0; j
< includerName
.length
; j
++) {
713 String includeNameStr
= includerName
[j
];
714 if (includeNameStr
!= null) {
715 str
= CommonDefinition
.include
+ " " + "<";
716 str
= str
+ includeNameStr
+ ">\r\n";
717 includStrList
.add(str
);
718 includeNameStr
= null;
722 return includStrList
;
728 * This function add include file in AutoGen.h file.
730 * @param packageNameList
731 * List of module depended package.
736 List
<String
> depPkgToAutogenH(PackageIdentification
[] packageNameList
,
737 String moduleType
) throws AutoGenException
{
739 List
<String
> includeStrList
= new LinkedList
<String
>();
741 String includeStr
= "";
744 // Get include file from moduleInfo file
746 for (int i
= 0; i
< packageNameList
.length
; i
++) {
747 pkgHeader
= GlobalData
.getPackageHeaderFiles(packageNameList
[i
],
749 if (pkgHeader
== null) {
750 throw new AutoGenException("Can not find package ["
752 + "] declaration in any SPD package. ");
753 } else if (!pkgHeader
.equalsIgnoreCase("")) {
754 includeStr
= CommonDefinition
.include
+ " <" + pkgHeader
756 includeStrList
.add(includeStr
);
760 return includeStrList
;
764 * EntryPointToAutoGen
766 * This function convert <ModuleEntryPoint> & <ModuleUnloadImage>
767 * information in mas to AutoGen.c
769 * @param entryPointList
770 * List of entry point.
772 * String buffer fo AutoGen.c.
775 void EntryPointToAutoGen(String
[] entryPointList
, StringBuffer fileBuffer
)
776 throws BuildException
{
778 String typeStr
= SurfaceAreaQuery
.getModuleType();
781 // The parameters and return value of entryPoint is difference
782 // for difference module type.
784 switch (CommonDefinition
.getModuleType(typeStr
)) {
786 case CommonDefinition
.ModuleTypePeiCore
:
787 if (entryPointList
== null ||entryPointList
.length
!= 1 ) {
788 throw new BuildException(
789 "Module type = 'PEI_CORE', can have only one module entry point!");
791 fileBuffer
.append("EFI_STATUS\r\n");
792 fileBuffer
.append("EFIAPI\r\n");
793 fileBuffer
.append(entryPointList
[0]);
794 fileBuffer
.append(" (\r\n");
796 .append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n");
798 .append(" IN VOID *OldCoreData\r\n");
799 fileBuffer
.append(" );\r\n\r\n");
801 fileBuffer
.append("EFI_STATUS\r\n");
802 fileBuffer
.append("EFIAPI\r\n");
803 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
805 .append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n");
807 .append(" IN VOID *OldCoreData\r\n");
808 fileBuffer
.append(" )\r\n\r\n");
809 fileBuffer
.append("{\r\n");
810 fileBuffer
.append(" return ");
811 fileBuffer
.append(entryPointList
[0]);
812 fileBuffer
.append(" (PeiStartupDescriptor, OldCoreData);\r\n");
813 fileBuffer
.append("}\r\n\r\n");
817 case CommonDefinition
.ModuleTypeDxeCore
:
818 fileBuffer
.append("const UINT32 _gUefiDriverRevision = 0;\r\n");
819 if (entryPointList
== null || entryPointList
.length
!= 1) {
820 throw new BuildException(
821 "Module type = 'DXE_CORE', can have only one module entry point!");
824 fileBuffer
.append("VOID\r\n");
825 fileBuffer
.append("EFIAPI\r\n");
826 fileBuffer
.append(entryPointList
[0]);
827 fileBuffer
.append(" (\n");
828 fileBuffer
.append(" IN VOID *HobStart\r\n");
829 fileBuffer
.append(" );\r\n\r\n");
831 fileBuffer
.append("VOID\r\n");
832 fileBuffer
.append("EFIAPI\r\n");
833 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
834 fileBuffer
.append(" IN VOID *HobStart\r\n");
835 fileBuffer
.append(" )\r\n\r\n");
836 fileBuffer
.append("{\r\n");
837 fileBuffer
.append(" ");
838 fileBuffer
.append(entryPointList
[0]);
839 fileBuffer
.append(" (HobStart);\r\n");
840 fileBuffer
.append("}\r\n\r\n");
844 case CommonDefinition
.ModuleTypePeim
:
845 int entryPointCount
= 0;
847 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = 0;\r\n");
848 if (entryPointList
== null || entryPointList
.length
== 0) {
849 fileBuffer
.append("EFI_STATUS\r\n");
850 fileBuffer
.append("EFIAPI\r\n");
851 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
852 fileBuffer
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
853 fileBuffer
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
854 fileBuffer
.append(" )\r\n\r\n");
855 fileBuffer
.append("{\r\n");
856 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
857 fileBuffer
.append("}\r\n\r\n");
860 for (int i
= 0; i
< entryPointList
.length
; i
++) {
861 fileBuffer
.append("EFI_STATUS\r\n");
862 fileBuffer
.append("EFIAPI\r\n");
863 fileBuffer
.append(entryPointList
[i
]);
864 fileBuffer
.append(" (\r\n");
866 .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
868 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
869 fileBuffer
.append(" );\r\n");
874 fileBuffer
.append("EFI_STATUS\r\n");
875 fileBuffer
.append("EFIAPI\r\n");
876 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
877 fileBuffer
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
878 fileBuffer
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
879 fileBuffer
.append(" )\r\n\r\n");
880 fileBuffer
.append("{\r\n");
881 if (entryPointCount
== 1) {
882 fileBuffer
.append(" return ");
883 fileBuffer
.append(entryPointList
[0]);
884 fileBuffer
.append(" (FfsHeader, PeiServices);\r\n");
886 fileBuffer
.append(" EFI_STATUS Status;\r\n");
887 fileBuffer
.append(" EFI_STATUS CombinedStatus;\r\n\r\n");
888 fileBuffer
.append(" CombinedStatus = EFI_LOAD_ERROR;\r\n\r\n");
889 for (int i
= 0; i
< entryPointList
.length
; i
++) {
890 if (!entryPointList
[i
].equals("")) {
891 fileBuffer
.append(" Status = ");
892 fileBuffer
.append(entryPointList
[i
]);
893 fileBuffer
.append(" (FfsHeader, PeiServices);\r\n");
895 .append(" if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {\r\n");
896 fileBuffer
.append(" CombinedStatus = Status;\r\n");
897 fileBuffer
.append(" }\r\n\r\n");
902 fileBuffer
.append(" return CombinedStatus;\r\n");
904 fileBuffer
.append("}\r\n\r\n");
907 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
910 // If entryPoint is null, create an empty ProcessModuleEntryPointList
913 if (entryPointList
== null || entryPointList
.length
== 0) {
915 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
916 fileBuffer
.append(Integer
.toString(entryPointCount
));
917 fileBuffer
.append(";\r\n");
918 fileBuffer
.append("EFI_STATUS\r\n");
919 fileBuffer
.append("EFIAPI\r\n");
920 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
921 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
922 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
923 fileBuffer
.append(" )\r\n\r\n");
924 fileBuffer
.append("{\r\n");
925 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
926 fileBuffer
.append("}\r\n\r\n");
929 for (int i
= 0; i
< entryPointList
.length
; i
++) {
930 fileBuffer
.append("EFI_STATUS\r\n");
931 fileBuffer
.append("EFIAPI\r\n");
932 fileBuffer
.append(entryPointList
[i
]);
933 fileBuffer
.append(" (\r\n");
934 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
935 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
936 fileBuffer
.append(" );\r\n");
940 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
941 fileBuffer
.append(Integer
.toString(entryPointCount
));
942 fileBuffer
.append(";\r\n");
944 .append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");
946 .append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n\r\n");
948 fileBuffer
.append("EFI_STATUS\r\n");
949 fileBuffer
.append("EFIAPI\r\n");
950 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
951 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
952 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
953 fileBuffer
.append(" )\r\n\r\n");
954 fileBuffer
.append("{\r\n");
957 for (int i
= 0; i
< entryPointList
.length
; i
++) {
959 .append(" if (SetJump (&mJumpContext) == 0) {\r\n");
960 fileBuffer
.append(" ExitDriver (");
961 fileBuffer
.append(entryPointList
[i
]);
962 fileBuffer
.append(" (ImageHandle, SystemTable));\r\n");
963 fileBuffer
.append(" ASSERT (FALSE);\r\n");
964 fileBuffer
.append(" }\r\n");
967 fileBuffer
.append(" return mDriverEntryPointStatus;\r\n");
968 fileBuffer
.append("}\r\n\r\n");
970 fileBuffer
.append("VOID\r\n");
971 fileBuffer
.append("EFIAPI\r\n");
972 fileBuffer
.append("ExitDriver (\r\n");
973 fileBuffer
.append(" IN EFI_STATUS Status\n");
974 fileBuffer
.append(" )\r\n\r\n");
975 fileBuffer
.append("{\r\n");
977 .append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");
978 fileBuffer
.append(" mDriverEntryPointStatus = Status;\r\n");
979 fileBuffer
.append(" }\r\n");
980 fileBuffer
.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");
981 fileBuffer
.append(" ASSERT (FALSE);\r\n");
982 fileBuffer
.append("}\r\n\r\n");
988 // Add "ModuleUnloadImage" for DxeSmmDriver module type;
990 entryPointList
= SurfaceAreaQuery
.getModuleUnloadImageArray();
991 entryPointList
= CommonDefinition
.remDupString(entryPointList
);
994 if (entryPointList
!= null) {
995 for (int i
= 0; i
< entryPointList
.length
; i
++) {
996 fileBuffer
.append("EFI_STATUS\r\n");
997 fileBuffer
.append("EFIAPI\r\n");
998 fileBuffer
.append(entryPointList
[i
]);
999 fileBuffer
.append(" (\r\n");
1001 .append(" IN EFI_HANDLE ImageHandle\r\n");
1002 fileBuffer
.append(" );\r\n");
1008 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");
1009 fileBuffer
.append(Integer
.toString(entryPointCount
));
1010 fileBuffer
.append(";\r\n\r\n");
1012 fileBuffer
.append("EFI_STATUS\r\n");
1013 fileBuffer
.append("EFIAPI\r\n");
1014 fileBuffer
.append("ProcessModuleUnloadList (\r\n");
1015 fileBuffer
.append(" IN EFI_HANDLE ImageHandle\r\n");
1016 fileBuffer
.append(" )\r\n");
1017 fileBuffer
.append("{\r\n");
1019 if (entryPointCount
== 0) {
1020 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
1021 } else if (entryPointCount
== 1) {
1022 fileBuffer
.append(" return ");
1023 fileBuffer
.append(entryPointList
[0]);
1024 fileBuffer
.append("(ImageHandle);\r\n");
1026 fileBuffer
.append(" EFI_STATUS Status;\r\n\r\n");
1027 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n\r\n");
1028 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1030 fileBuffer
.append(" Status = ");
1031 fileBuffer
.append(entryPointList
[i
]);
1032 fileBuffer
.append("(ImageHandle);\r\n");
1034 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
1035 fileBuffer
.append(" ");
1036 fileBuffer
.append(entryPointList
[i
]);
1037 fileBuffer
.append("(ImageHandle);\r\n");
1038 fileBuffer
.append(" } else {\r\n");
1039 fileBuffer
.append(" Status = ");
1040 fileBuffer
.append(entryPointList
[i
]);
1041 fileBuffer
.append("(ImageHandle);\r\n");
1042 fileBuffer
.append(" }\r\n");
1045 fileBuffer
.append(" return Status;\r\n");
1047 fileBuffer
.append("}\r\n\r\n");
1050 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1051 case CommonDefinition
.ModuleTypeDxeDriver
:
1052 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1053 case CommonDefinition
.ModuleTypeUefiDriver
:
1054 case CommonDefinition
.ModuleTypeUefiApplication
:
1055 entryPointCount
= 0;
1056 fileBuffer
.append("const UINT32 _gUefiDriverRevision = 0;\r\n");
1058 // If entry point is null, create a empty ProcessModuleEntryPointList function.
1060 if (entryPointList
== null || entryPointList
.length
== 0) {
1062 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = 0;\r\n");
1063 fileBuffer
.append("EFI_STATUS\r\n");
1064 fileBuffer
.append("EFIAPI\r\n");
1065 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
1066 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1067 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1068 fileBuffer
.append(" )\r\n\r\n");
1069 fileBuffer
.append("{\r\n");
1070 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
1071 fileBuffer
.append("}\r\n");
1074 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1076 fileBuffer
.append("EFI_STATUS\r\n");
1077 fileBuffer
.append("EFIAPI\r\n");
1078 fileBuffer
.append(entryPointList
[i
]);
1079 fileBuffer
.append(" (\r\n");
1080 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1081 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1082 fileBuffer
.append(" );\r\n");
1087 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
1088 fileBuffer
.append(Integer
.toString(entryPointCount
));
1089 fileBuffer
.append(";\r\n");
1090 if (entryPointCount
> 1) {
1092 .append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");
1094 .append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n");
1096 fileBuffer
.append("\n");
1098 fileBuffer
.append("EFI_STATUS\r\n");
1099 fileBuffer
.append("EFIAPI\r\n");
1100 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
1101 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1102 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1103 fileBuffer
.append(" )\r\n\r\n");
1104 fileBuffer
.append("{\r\n");
1106 if (entryPointCount
== 1) {
1107 fileBuffer
.append(" return (");
1108 fileBuffer
.append(entryPointList
[0]);
1109 fileBuffer
.append(" (ImageHandle, SystemTable));\r\n");
1111 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1112 if (!entryPointList
[i
].equals("")) {
1114 .append(" if (SetJump (&mJumpContext) == 0) {\r\n");
1115 fileBuffer
.append(" ExitDriver (");
1116 fileBuffer
.append(entryPointList
[i
]);
1117 fileBuffer
.append(" (ImageHandle, SystemTable));\r\n");
1118 fileBuffer
.append(" ASSERT (FALSE);\r\n");
1119 fileBuffer
.append(" }\r\n");
1124 fileBuffer
.append(" return mDriverEntryPointStatus;\r\n");
1126 fileBuffer
.append("}\r\n\r\n");
1128 fileBuffer
.append("VOID\r\n");
1129 fileBuffer
.append("EFIAPI\r\n");
1130 fileBuffer
.append("ExitDriver (\r\n");
1131 fileBuffer
.append(" IN EFI_STATUS Status\r\n");
1132 fileBuffer
.append(" )\r\n\r\n");
1133 fileBuffer
.append("{\r\n");
1134 if (entryPointCount
<= 1) {
1135 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
1137 .append(" ProcessLibraryDestructorList (gImageHandle, gST);\r\n");
1138 fileBuffer
.append(" }\r\n");
1140 .append(" gBS->Exit (gImageHandle, Status, 0, NULL);\r\n");
1143 .append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");
1144 fileBuffer
.append(" mDriverEntryPointStatus = Status;\r\n");
1145 fileBuffer
.append(" }\r\n");
1146 fileBuffer
.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");
1147 fileBuffer
.append(" ASSERT (FALSE);\r\n");
1149 fileBuffer
.append("}\r\n\r\n");
1154 // Add ModuleUnloadImage for DxeDriver and UefiDriver module type.
1156 entryPointList
= SurfaceAreaQuery
.getModuleUnloadImageArray();
1158 // Remover duplicate unload entry point.
1160 entryPointList
= CommonDefinition
.remDupString(entryPointList
);
1161 entryPointCount
= 0;
1162 if (entryPointList
!= null) {
1163 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1164 fileBuffer
.append("EFI_STATUS\r\n");
1165 fileBuffer
.append("EFIAPI\r\n");
1166 fileBuffer
.append(entryPointList
[i
]);
1167 fileBuffer
.append(" (\r\n");
1169 .append(" IN EFI_HANDLE ImageHandle\r\n");
1170 fileBuffer
.append(" );\r\n");
1176 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");
1177 fileBuffer
.append(Integer
.toString(entryPointCount
));
1178 fileBuffer
.append(";\r\n\r\n");
1180 fileBuffer
.append("EFI_STATUS\n");
1181 fileBuffer
.append("EFIAPI\r\n");
1182 fileBuffer
.append("ProcessModuleUnloadList (\r\n");
1183 fileBuffer
.append(" IN EFI_HANDLE ImageHandle\r\n");
1184 fileBuffer
.append(" )\r\n");
1185 fileBuffer
.append("{\r\n");
1187 if (entryPointCount
== 0) {
1188 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
1189 } else if (entryPointCount
== 1) {
1190 fileBuffer
.append(" return ");
1191 fileBuffer
.append(entryPointList
[0]);
1192 fileBuffer
.append("(ImageHandle);\r\n");
1194 fileBuffer
.append(" EFI_STATUS Status;\r\n\r\n");
1195 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n\r\n");
1196 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1198 fileBuffer
.append(" Status = ");
1199 fileBuffer
.append(entryPointList
[i
]);
1200 fileBuffer
.append("(ImageHandle);\r\n");
1202 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
1203 fileBuffer
.append(" ");
1204 fileBuffer
.append(entryPointList
[i
]);
1205 fileBuffer
.append("(ImageHandle);\r\n");
1206 fileBuffer
.append(" } else {\r\n");
1207 fileBuffer
.append(" Status = ");
1208 fileBuffer
.append(entryPointList
[i
]);
1209 fileBuffer
.append("(ImageHandle);\r\n");
1210 fileBuffer
.append(" }\r\n");
1213 fileBuffer
.append(" return Status;\r\n");
1215 fileBuffer
.append("}\r\n\r\n");
1223 * This function gets GUIDs from SPD file accrodeing to <PPIs> information
1224 * and write those GUIDs to AutoGen.c.
1227 * String Buffer for Autogen.c file.
1228 * @throws BuildException
1229 * Guid must set value!
1231 void PpiGuidToAutogenC(StringBuffer fileBuffer
) throws AutoGenException
{
1232 String
[] cNameGuid
= null;
1235 // Get the all PPI adn PPI Notify from MSA file,
1236 // then add those PPI ,and PPI Notify name to list.
1239 String
[] ppiList
= SurfaceAreaQuery
.getPpiArray(this.arch
);
1240 for (int i
= 0; i
< ppiList
.length
; i
++) {
1241 this.mPpiList
.add(ppiList
[i
]);
1244 String
[] ppiNotifyList
= SurfaceAreaQuery
.getPpiNotifyArray(this.arch
);
1245 for (int i
= 0; i
< ppiNotifyList
.length
; i
++) {
1246 this.mPpiList
.add(ppiNotifyList
[i
]);
1250 // Find CNAME and GUID from dependence SPD file and write to Autogen.c
1252 Iterator ppiIterator
= this.mPpiList
.iterator();
1253 String ppiKeyWord
= null;
1254 while (ppiIterator
.hasNext()) {
1255 ppiKeyWord
= ppiIterator
.next().toString();
1256 cNameGuid
= GlobalData
.getPpiGuid(this.mDepPkgList
, ppiKeyWord
);
1257 if (cNameGuid
!= null) {
1259 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1260 fileBuffer
.append(cNameGuid
[0]);
1261 fileBuffer
.append(" = { ");
1262 fileBuffer
.append(CommonDefinition
.formatGuidName(cNameGuid
[1]));
1263 fileBuffer
.append(" } ;");
1266 // If can't find Ppi GUID declaration in every package
1268 throw new AutoGenException("Can not find Ppi GUID ["
1269 + ppiKeyWord
+ "] declaration in any SPD package!");
1275 * ProtocolGuidToAutogenc
1277 * This function gets GUIDs from SPD file accrodeing to <Protocol>
1278 * information and write those GUIDs to AutoGen.c.
1281 * String Buffer for Autogen.c file.
1282 * @throws BuildException
1283 * Protocol name must set.
1285 void ProtocolGuidToAutogenC(StringBuffer fileBuffer
) throws BuildException
{
1286 String
[] cNameGuid
= null;
1288 String
[] protocolList
= SurfaceAreaQuery
.getProtocolArray(this.arch
);
1291 // Add result to Autogen global list.
1293 for (int i
= 0; i
< protocolList
.length
; i
++) {
1294 this.mProtocolList
.add(protocolList
[i
]);
1297 String
[] protocolNotifyList
= SurfaceAreaQuery
1298 .getProtocolNotifyArray(this.arch
);
1300 for (int i
= 0; i
< protocolNotifyList
.length
; i
++) {
1301 this.mProtocolList
.add(protocolNotifyList
[i
]);
1305 // Get the NAME and GUID from dependence SPD and write to Autogen.c
1307 Iterator protocolIterator
= this.mProtocolList
.iterator();
1308 String protocolKeyWord
= null;
1311 while (protocolIterator
.hasNext()) {
1312 protocolKeyWord
= protocolIterator
.next().toString();
1313 cNameGuid
= GlobalData
.getProtocolGuid(this.mDepPkgList
, protocolKeyWord
);
1314 if (cNameGuid
!= null) {
1316 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1317 fileBuffer
.append(cNameGuid
[0]);
1318 fileBuffer
.append(" = { ");
1319 fileBuffer
.append(CommonDefinition
.formatGuidName(cNameGuid
[1]));
1320 fileBuffer
.append(" } ;");
1323 // If can't find protocol GUID declaration in every package
1325 throw new BuildException("Can not find protocol Guid ["
1326 + protocolKeyWord
+ "] declaration in any SPD package!");
1332 * GuidGuidToAutogenc
1334 * This function gets GUIDs from SPD file accrodeing to <Guids> information
1335 * and write those GUIDs to AutoGen.c.
1338 * String Buffer for Autogen.c file.
1341 void GuidGuidToAutogenC(StringBuffer fileBuffer
) throws AutoGenException
{
1342 String
[] cNameGuid
= null;
1343 String guidKeyWord
= null;
1345 String
[] guidList
= SurfaceAreaQuery
.getGuidEntryArray(this.arch
);
1347 for (int i
= 0; i
< guidList
.length
; i
++) {
1348 this.mGuidList
.add(guidList
[i
]);
1352 Iterator guidIterator
= this.mGuidList
.iterator();
1353 while (guidIterator
.hasNext()) {
1354 guidKeyWord
= guidIterator
.next().toString();
1355 cNameGuid
= GlobalData
.getGuid(this.mDepPkgList
, guidKeyWord
);
1357 if (cNameGuid
!= null) {
1359 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1360 fileBuffer
.append(cNameGuid
[0]);
1361 fileBuffer
.append(" = { ");
1362 fileBuffer
.append(CommonDefinition
.formatGuidName(cNameGuid
[1]));
1363 fileBuffer
.append("} ;");
1366 // If can't find GUID declaration in every package
1368 throw new AutoGenException("Can not find Guid [" + guidKeyWord
1369 + "] declaration in any SPD package. ");
1376 * LibInstanceToAutogenC
1378 * This function adds dependent library instance to autogen.c,which
1379 * includeing library's constructor, destructor, and library dependent ppi,
1380 * protocol, guid, pcd information.
1383 * String buffer for AutoGen.c
1384 * @throws BuildException
1386 void LibInstanceToAutogenC(StringBuffer fileBuffer
) throws BuildException
{
1388 String moduleType
= this.moduleId
.getModuleType();
1390 // Add library constructor to AutoGen.c
1392 LibConstructorToAutogenC(libConstructList
, moduleType
,
1393 fileBuffer
/* autogenC */);
1395 // Add library destructor to AutoGen.c
1397 LibDestructorToAutogenC(libDestructList
, moduleType
, fileBuffer
/* autogenC */);
1398 } catch (Exception e
) {
1399 throw new BuildException(e
.getMessage());
1404 * LibConstructorToAutogenc
1406 * This function writes library constructor list to AutoGen.c. The library
1407 * constructor's parameter and return value depend on module type.
1409 * @param libInstanceList
1410 * List of library construct name.
1414 * String buffer for AutoGen.c
1417 void LibConstructorToAutogenC(List
<String
> libInstanceList
,
1418 String moduleType
, StringBuffer fileBuffer
) throws Exception
{
1419 boolean isFirst
= true;
1422 // The library constructor's parameter and return value depend on
1425 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1426 switch (CommonDefinition
.getModuleType(moduleType
)) {
1427 case CommonDefinition
.ModuleTypeBase
:
1428 fileBuffer
.append("RETURN_STATUS\r\n");
1429 fileBuffer
.append("EFIAPI\r\n");
1430 fileBuffer
.append(libInstanceList
.get(i
));
1431 fileBuffer
.append(" (\r\n");
1432 fileBuffer
.append(" VOID\r\n");
1433 fileBuffer
.append(" );\r\n");
1436 case CommonDefinition
.ModuleTypePeiCore
:
1437 case CommonDefinition
.ModuleTypePeim
:
1438 fileBuffer
.append("EFI_STATUS\r\n");
1439 fileBuffer
.append("EFIAPI\r\n");
1440 fileBuffer
.append(libInstanceList
.get(i
));
1441 fileBuffer
.append(" (\r\n");
1443 .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1445 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1446 fileBuffer
.append(" );\r\n");
1449 case CommonDefinition
.ModuleTypeDxeCore
:
1450 case CommonDefinition
.ModuleTypeDxeDriver
:
1451 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1452 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1453 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1454 case CommonDefinition
.ModuleTypeUefiDriver
:
1455 case CommonDefinition
.ModuleTypeUefiApplication
:
1456 fileBuffer
.append("EFI_STATUS\r\n");
1457 fileBuffer
.append("EFIAPI\r\n");
1458 fileBuffer
.append(libInstanceList
.get(i
));
1459 fileBuffer
.append(" (\r\n");
1460 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1461 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1462 fileBuffer
.append(" );\r\n");
1468 // Add ProcessLibraryConstructorList in AutoGen.c
1470 fileBuffer
.append("VOID\r\n");
1471 fileBuffer
.append("EFIAPI\r\n");
1472 fileBuffer
.append("ProcessLibraryConstructorList (\r\n");
1473 switch (CommonDefinition
.getModuleType(moduleType
)) {
1474 case CommonDefinition
.ModuleTypeBase
:
1475 fileBuffer
.append(" VOID\r\n");
1478 case CommonDefinition
.ModuleTypePeiCore
:
1479 case CommonDefinition
.ModuleTypePeim
:
1480 fileBuffer
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1482 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1485 case CommonDefinition
.ModuleTypeDxeCore
:
1486 case CommonDefinition
.ModuleTypeDxeDriver
:
1487 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1488 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1489 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1490 case CommonDefinition
.ModuleTypeUefiDriver
:
1491 case CommonDefinition
.ModuleTypeUefiApplication
:
1492 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1493 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1497 fileBuffer
.append(" )\r\n");
1498 fileBuffer
.append("{\r\n");
1500 // If no constructor function, return EFI_SUCCESS.
1502 //if (libInstanceList.size() == 0){
1503 // fileBuffer.append(" return EFI_SUCCESS;\r\n");
1505 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1507 fileBuffer
.append(" EFI_STATUS Status;\r\n");
1508 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n");
1509 fileBuffer
.append("\r\n");
1512 switch (CommonDefinition
.getModuleType(moduleType
)) {
1513 case CommonDefinition
.ModuleTypeBase
:
1514 fileBuffer
.append(" Status = ");
1515 fileBuffer
.append(libInstanceList
.get(i
));
1516 fileBuffer
.append("();\r\n");
1517 fileBuffer
.append(" VOID\r\n");
1519 case CommonDefinition
.ModuleTypePeiCore
:
1520 case CommonDefinition
.ModuleTypePeim
:
1521 fileBuffer
.append(" Status = ");
1522 fileBuffer
.append(libInstanceList
.get(i
));
1523 fileBuffer
.append(" (FfsHeader, PeiServices);\r\n");
1525 case CommonDefinition
.ModuleTypeDxeCore
:
1526 case CommonDefinition
.ModuleTypeDxeDriver
:
1527 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1528 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1529 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1530 case CommonDefinition
.ModuleTypeUefiDriver
:
1531 case CommonDefinition
.ModuleTypeUefiApplication
:
1532 fileBuffer
.append(" Status = ");
1533 fileBuffer
.append(libInstanceList
.get(i
));
1534 fileBuffer
.append(" (ImageHandle, SystemTable);\r\n");
1537 EdkLog
.log(EdkLog
.EDK_INFO
,"Autogen doesn't know how to deal with module type - " + moduleType
+ "!");
1539 fileBuffer
.append(" ASSERT_EFI_ERROR (Status);\r\n");
1541 fileBuffer
.append("}\r\n");
1545 * LibDestructorToAutogenc
1547 * This function writes library destructor list to AutoGen.c. The library
1548 * destructor's parameter and return value depend on module type.
1550 * @param libInstanceList
1551 * List of library destructor name.
1555 * String buffer for AutoGen.c
1558 void LibDestructorToAutogenC(List
<String
> libInstanceList
,
1559 String moduleType
, StringBuffer fileBuffer
) throws Exception
{
1560 boolean isFirst
= true;
1561 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1562 switch (CommonDefinition
.getModuleType(moduleType
)) {
1563 case CommonDefinition
.ModuleTypeBase
:
1564 fileBuffer
.append("RETURN_STATUS\r\n");
1565 fileBuffer
.append("EFIAPI\r\n");
1566 fileBuffer
.append(libInstanceList
.get(i
));
1567 fileBuffer
.append(" (\r\n");
1568 fileBuffer
.append(" VOID\r\n");
1569 fileBuffer
.append(" );\r\n");
1571 case CommonDefinition
.ModuleTypePeiCore
:
1572 case CommonDefinition
.ModuleTypePeim
:
1573 fileBuffer
.append("EFI_STATUS\r\n");
1574 fileBuffer
.append("EFIAPI\r\n");
1575 fileBuffer
.append(libInstanceList
.get(i
));
1576 fileBuffer
.append(" (\r\n");
1578 .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1580 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1581 fileBuffer
.append(" );\r\n");
1583 case CommonDefinition
.ModuleTypeDxeCore
:
1584 case CommonDefinition
.ModuleTypeDxeDriver
:
1585 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1586 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1587 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1588 case CommonDefinition
.ModuleTypeUefiDriver
:
1589 case CommonDefinition
.ModuleTypeUefiApplication
:
1590 fileBuffer
.append("EFI_STATUS\r\n");
1591 fileBuffer
.append("EFIAPI\r\n");
1592 fileBuffer
.append(libInstanceList
.get(i
));
1593 fileBuffer
.append(" (\r\n");
1594 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1595 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1596 fileBuffer
.append(" );\r\n");
1602 // Write ProcessLibraryDestructor list to autogen.c
1604 switch (CommonDefinition
.getModuleType(moduleType
)) {
1605 case CommonDefinition
.ModuleTypeBase
:
1606 case CommonDefinition
.ModuleTypePeiCore
:
1607 case CommonDefinition
.ModuleTypePeim
:
1609 case CommonDefinition
.ModuleTypeDxeCore
:
1610 case CommonDefinition
.ModuleTypeDxeDriver
:
1611 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1612 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1613 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1614 case CommonDefinition
.ModuleTypeUefiDriver
:
1615 case CommonDefinition
.ModuleTypeUefiApplication
:
1616 fileBuffer
.append("VOID\r\n");
1617 fileBuffer
.append("EFIAPI\r\n");
1618 fileBuffer
.append("ProcessLibraryDestructorList (\r\n");
1619 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1620 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1621 fileBuffer
.append(" )\r\n");
1622 fileBuffer
.append("{\r\n");
1624 // If no library destructor function, return EFI_SUCCESS.
1627 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1629 fileBuffer
.append(" EFI_STATUS Status;\r\n");
1630 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n");
1631 fileBuffer
.append("\r\n");
1634 fileBuffer
.append(" Status = ");
1635 fileBuffer
.append(libInstanceList
.get(i
));
1636 fileBuffer
.append("(ImageHandle, SystemTable);\r\n");
1637 fileBuffer
.append(" ASSERT_EFI_ERROR (Status);\r\n");
1639 fileBuffer
.append("}\r\n");
1645 * ExternsDriverBindingToAutoGenC
1647 * This function is to write DRIVER_BINDING, COMPONENT_NAME,
1648 * DRIVER_CONFIGURATION, DRIVER_DIAGNOSTIC in AutoGen.c.
1651 * String buffer for AutoGen.c
1653 void ExternsDriverBindingToAutoGenC(StringBuffer fileBuffer
)
1654 throws BuildException
{
1657 // Check what <extern> contains. And the number of following elements
1658 // under <extern> should be same. 1. DRIVER_BINDING 2. COMPONENT_NAME
1659 // 3.DRIVER_CONFIGURATION 4. DRIVER_DIAGNOSTIC
1662 String
[] drvBindList
= SurfaceAreaQuery
.getDriverBindingArray();
1665 // If component name protocol,component configuration protocol,
1666 // component diagnostic protocol is not null or empty, check
1667 // if every one have the same number of the driver binding protocol.
1669 if (drvBindList
== null || drvBindList
.length
== 0) {
1673 String
[] compNamList
= SurfaceAreaQuery
.getComponentNameArray();
1674 String
[] compConfList
= SurfaceAreaQuery
.getDriverConfigArray();
1675 String
[] compDiagList
= SurfaceAreaQuery
.getDriverDiagArray();
1680 // Write driver binding protocol extern to autogen.c
1682 for (int i
= 0; i
< drvBindList
.length
; i
++) {
1683 fileBuffer
.append("extern EFI_DRIVER_BINDING_PROTOCOL ");
1684 fileBuffer
.append(drvBindList
[i
]);
1685 fileBuffer
.append(";\r\n");
1689 // Write component name protocol extern to autogen.c
1691 if (compNamList
!= null && compNamList
.length
!= 0) {
1692 if (drvBindList
.length
!= compNamList
.length
) {
1693 throw new BuildException(
1694 "Different number of Driver Binding and Component Name protocols!");
1698 for (int i
= 0; i
< compNamList
.length
; i
++) {
1699 fileBuffer
.append("extern EFI_COMPONENT_NAME_PROTOCOL ");
1700 fileBuffer
.append(compNamList
[i
]);
1701 fileBuffer
.append(";\r\n");
1706 // Write driver configration protocol extern to autogen.c
1708 if (compConfList
!= null && compConfList
.length
!= 0) {
1709 if (drvBindList
.length
!= compConfList
.length
) {
1710 throw new BuildException(
1711 "Different number of Driver Binding and Driver Configuration protocols!");
1715 for (int i
= 0; i
< compConfList
.length
; i
++) {
1716 fileBuffer
.append("extern EFI_DRIVER_CONFIGURATION_PROTOCOL ");
1717 fileBuffer
.append(compConfList
[i
]);
1718 fileBuffer
.append(";\r\n");
1723 // Write driver dignastic protocol extern to autogen.c
1725 if (compDiagList
!= null && compDiagList
.length
!= 0) {
1726 if (drvBindList
.length
!= compDiagList
.length
) {
1727 throw new BuildException(
1728 "Different number of Driver Binding and Driver Diagnosis protocols!");
1732 for (int i
= 0; i
< compDiagList
.length
; i
++) {
1733 fileBuffer
.append("extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL ");
1734 fileBuffer
.append(compDiagList
[i
]);
1735 fileBuffer
.append(";\r\n");
1740 // Write driver module protocol bitmask.
1743 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverModelProtocolBitmask = ");
1744 fileBuffer
.append(Integer
.toString(BitMask
));
1745 fileBuffer
.append(";\r\n");
1748 // Write driver module protocol list entry
1751 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverModelProtocolListEntries = ");
1753 fileBuffer
.append(Integer
.toString(drvBindList
.length
));
1754 fileBuffer
.append(";\r\n");
1757 // Write drive module protocol list to autogen.c
1760 .append("GLOBAL_REMOVE_IF_UNREFERENCED const EFI_DRIVER_MODEL_PROTOCOL_LIST _gDriverModelProtocolList[] = {");
1761 for (int i
= 0; i
< drvBindList
.length
; i
++) {
1763 fileBuffer
.append(",");
1765 fileBuffer
.append("\r\n {\r\n");
1766 fileBuffer
.append(" &");
1767 fileBuffer
.append(drvBindList
[i
]);
1768 fileBuffer
.append(", \r\n");
1770 if (compNamList
!= null) {
1771 fileBuffer
.append(" &");
1772 fileBuffer
.append(compNamList
[i
]);
1773 fileBuffer
.append(", \r\n");
1775 fileBuffer
.append(" NULL, \r\n");
1778 if (compConfList
!= null) {
1779 fileBuffer
.append(" &");
1780 fileBuffer
.append(compConfList
[i
]);
1781 fileBuffer
.append(", \r\n");
1783 fileBuffer
.append(" NULL, \r\n");
1786 if (compDiagList
!= null) {
1787 fileBuffer
.append(" &");
1788 fileBuffer
.append(compDiagList
[i
]);
1789 fileBuffer
.append(", \r\n");
1791 fileBuffer
.append(" NULL, \r\n");
1793 fileBuffer
.append(" }");
1795 fileBuffer
.append("\r\n};\r\n");
1799 * ExternCallBackToAutoGenC
1801 * This function adds <SetVirtualAddressMapCallBack> and
1802 * <ExitBootServicesCallBack> infomation to AutoGen.c
1805 * String buffer for AutoGen.c
1806 * @throws BuildException
1808 void ExternCallBackToAutoGenC(StringBuffer fileBuffer
)
1809 throws BuildException
{
1811 // Collect module's <SetVirtualAddressMapCallBack> and
1812 // <ExitBootServiceCallBack> and add to setVirtualAddList
1813 // exitBootServiceList.
1815 String
[] setVirtuals
= SurfaceAreaQuery
.getSetVirtualAddressMapCallBackArray();
1816 String
[] exitBoots
= SurfaceAreaQuery
.getExitBootServicesCallBackArray();
1817 if (setVirtuals
!= null) {
1818 for (int j
= 0; j
< setVirtuals
.length
; j
++) {
1819 this.setVirtalAddList
.add(setVirtuals
[j
]);
1822 if (exitBoots
!= null) {
1823 for (int k
= 0; k
< exitBoots
.length
; k
++) {
1824 this.exitBootServiceList
.add(exitBoots
[k
]);
1828 // Add c code in autogen.c which relate to <SetVirtualAddressMapCallBack>
1829 // and <ExitBootServicesCallBack>
1831 String moduleType
= this.moduleId
.getModuleType();
1832 boolean UefiOrDxeModule
= false;
1835 switch (CommonDefinition
.getModuleType(moduleType
)) {
1836 case CommonDefinition
.ModuleTypeDxeDriver
:
1837 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1838 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1839 case CommonDefinition
.ModuleTypeUefiDriver
:
1840 case CommonDefinition
.ModuleTypeUefiApplication
:
1842 // Entry point lib for these module types needs to know the count
1845 UefiOrDxeModule
= true;
1847 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverSetVirtualAddressMapEventCount = ");
1850 // If the list is not valid or has no entries set count to zero else
1851 // set count to the number of valid entries
1854 if (this.setVirtalAddList
!= null) {
1855 for (i
= 0; i
< this.setVirtalAddList
.size(); i
++) {
1856 if (this.setVirtalAddList
.get(i
).equalsIgnoreCase("")) {
1863 fileBuffer
.append(Integer
.toString(Count
));
1864 fileBuffer
.append(";\r\n\r\n");
1870 if (this.setVirtalAddList
== null || this.setVirtalAddList
.size() == 0) {
1871 if (UefiOrDxeModule
) {
1873 // No data so make a NULL list
1876 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {\r\n");
1877 fileBuffer
.append(" NULL\r\n");
1878 fileBuffer
.append("};\r\n\r\n");
1882 // Write SetVirtualAddressMap function definition.
1884 for (i
= 0; i
< this.setVirtalAddList
.size(); i
++) {
1885 if (this.setVirtalAddList
.get(i
).equalsIgnoreCase("")) {
1888 fileBuffer
.append("VOID\r\n");
1889 fileBuffer
.append("EFIAPI\r\n");
1890 fileBuffer
.append(this.setVirtalAddList
.get(i
));
1891 fileBuffer
.append(" (\r\n");
1892 fileBuffer
.append(" IN EFI_EVENT Event,\r\n");
1893 fileBuffer
.append(" IN VOID *Context\r\n");
1894 fileBuffer
.append(" );\r\n\r\n");
1898 // Write SetVirtualAddressMap entry point array.
1901 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {");
1902 for (i
= 0; i
< this.setVirtalAddList
.size(); i
++) {
1903 if (this.setVirtalAddList
.get(i
).equalsIgnoreCase("")) {
1908 fileBuffer
.append("\r\n ");
1910 fileBuffer
.append(",\r\n ");
1913 fileBuffer
.append(this.setVirtalAddList
.get(i
));
1916 // If module is not DXE_DRIVER, DXE_RUNTIME_DIRVER, UEFI_DRIVER
1917 // UEFI_APPLICATION and DXE_SAL_DRIVER add the NULL at the end of
1918 // _gDriverSetVirtualAddressMapEvent list.
1920 if (!UefiOrDxeModule
) {
1921 fileBuffer
.append(",\r\n NULL");
1923 fileBuffer
.append("\r\n};\r\n\r\n");
1926 if (UefiOrDxeModule
) {
1928 // Entry point lib for these module types needs to know the count.
1931 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverExitBootServicesEventCount = ");
1934 // If the list is not valid or has no entries set count to zero else
1935 // set count to the number of valid entries.
1938 if (this.exitBootServiceList
!= null) {
1939 for (i
= 0; i
< this.exitBootServiceList
.size(); i
++) {
1940 if (this.exitBootServiceList
.get(i
).equalsIgnoreCase("")) {
1946 fileBuffer
.append(Integer
.toString(Count
));
1947 fileBuffer
.append(";\r\n\r\n");
1950 if (this.exitBootServiceList
== null || this.exitBootServiceList
.size() == 0) {
1951 if (UefiOrDxeModule
) {
1953 // No data so make a NULL list.
1956 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {\r\n");
1957 fileBuffer
.append(" NULL\r\n");
1958 fileBuffer
.append("};\r\n\r\n");
1962 // Write DriverExitBootServices function definition.
1964 for (i
= 0; i
< this.exitBootServiceList
.size(); i
++) {
1965 if (this.exitBootServiceList
.get(i
).equalsIgnoreCase("")) {
1969 fileBuffer
.append("VOID\r\n");
1970 fileBuffer
.append("EFIAPI\r\n");
1971 fileBuffer
.append(this.exitBootServiceList
.get(i
));
1972 fileBuffer
.append(" (\r\n");
1973 fileBuffer
.append(" IN EFI_EVENT Event,\r\n");
1974 fileBuffer
.append(" IN VOID *Context\r\n");
1975 fileBuffer
.append(" );\r\n\r\n");
1979 // Write DriverExitBootServices entry point array.
1982 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {");
1983 for (i
= 0; i
< this.exitBootServiceList
.size(); i
++) {
1984 if (this.exitBootServiceList
.get(i
).equalsIgnoreCase("")) {
1989 fileBuffer
.append("\r\n ");
1991 fileBuffer
.append(",\r\n ");
1993 fileBuffer
.append(this.exitBootServiceList
.get(i
));
1995 if (!UefiOrDxeModule
) {
1996 fileBuffer
.append(",\r\n NULL");
1998 fileBuffer
.append("\r\n};\r\n\r\n");
2003 private void copyFlashMapHToDebugDir() throws AutoGenException
{
2005 File inFile
= new File(fvDir
+ File
.separatorChar
+ CommonDefinition
.flashMapH
);
2006 int size
= (int)inFile
.length();
2007 byte[] buffer
= new byte[size
];
2008 File outFile
= new File (this.outputPath
+ File
.separatorChar
+ CommonDefinition
.tianoR8FlashMapH
);
2010 // If TianoR8FlashMap.h existed and the flashMap.h don't change,
2013 if ((!outFile
.exists()) ||(inFile
.lastModified() - outFile
.lastModified()) >= 0) {
2015 if (inFile
.exists()) {
2016 FileInputStream fis
= new FileInputStream (inFile
);
2018 FileOutputStream fos
= new FileOutputStream(outFile
);
2023 throw new AutoGenException("The file, flashMap.h doesn't exist!");
2025 } catch (Exception e
) {
2026 throw new AutoGenException(e
.getMessage());
2032 *This function first order the library instances, then collect
2033 *library instance 's PPI, Protocol, GUID,
2034 *SetVirtalAddressMapCallBack, ExitBootServiceCallBack, and
2035 *Destructor, Constructor.
2038 private void collectLibInstanceInfo(){
2041 String libConstructName
= null;
2042 String libDestructName
= null;
2043 String
[] setVirtuals
= null;
2044 String
[] exitBoots
= null;
2046 ModuleIdentification
[] libraryIdList
= SurfaceAreaQuery
2047 .getLibraryInstance(this.arch
);
2049 if (libraryIdList
!= null) {
2051 // Reorder library instance sequence.
2053 AutogenLibOrder libOrder
= new AutogenLibOrder(libraryIdList
,
2055 List
<ModuleIdentification
> orderList
= libOrder
2056 .orderLibInstance();
2058 if (orderList
!= null) {
2060 // Process library instance one by one.
2062 for (int i
= 0; i
< orderList
.size(); i
++) {
2065 // Get library instance basename.
2067 ModuleIdentification libInstanceId
= orderList
.get(i
);
2073 Map
<String
, XmlObject
> libDoc
= GlobalData
.getDoc(libInstanceId
, this.arch
);
2074 SurfaceAreaQuery
.push(libDoc
);
2076 // Get <PPis>, <Protocols>, <Guids> list of this library
2079 String
[] ppiList
= SurfaceAreaQuery
.getPpiArray(this.arch
);
2080 String
[] ppiNotifyList
= SurfaceAreaQuery
2081 .getPpiNotifyArray(this.arch
);
2082 String
[] protocolList
= SurfaceAreaQuery
2083 .getProtocolArray(this.arch
);
2084 String
[] protocolNotifyList
= SurfaceAreaQuery
2085 .getProtocolNotifyArray(this.arch
);
2086 String
[] guidList
= SurfaceAreaQuery
2087 .getGuidEntryArray(this.arch
);
2088 String
[] libraryClassList
= SurfaceAreaQuery
.getLibraryClasses(
2089 CommonDefinition
.AlwaysConsumed
,
2091 PackageIdentification
[] pkgList
= SurfaceAreaQuery
.getDependencePkg(this.arch
);
2094 // Add those ppi, protocol, guid in global ppi,
2098 for (index
= 0; index
< ppiList
.length
; index
++) {
2099 this.mPpiList
.add(ppiList
[index
]);
2102 for (index
= 0; index
< ppiNotifyList
.length
; index
++) {
2103 this.mPpiList
.add(ppiNotifyList
[index
]);
2106 for (index
= 0; index
< protocolList
.length
; index
++) {
2107 this.mProtocolList
.add(protocolList
[index
]);
2110 for (index
= 0; index
< protocolNotifyList
.length
; index
++) {
2111 this.mProtocolList
.add(protocolNotifyList
[index
]);
2114 for (index
= 0; index
< guidList
.length
; index
++) {
2115 this.mGuidList
.add(guidList
[index
]);
2117 for (index
= 0; index
< pkgList
.length
; index
++) {
2118 if (!this.mDepPkgList
.contains(pkgList
[index
])) {
2119 this.mDepPkgList
.add(pkgList
[index
]);
2122 for (index
= 0; index
< libraryClassList
.length
; index
++) {
2123 if (libraryClassList
[index
].equalsIgnoreCase(CommonDefinition
.pcdLibName
)) {
2124 this.isModuleLibraryInstanceUsePcd
= true;
2128 // If not yet parse this library instance's constructor
2129 // element,parse it.
2131 libConstructName
= SurfaceAreaQuery
2132 .getLibConstructorName();
2133 libDestructName
= SurfaceAreaQuery
2134 .getLibDestructorName();
2137 // Collect SetVirtualAddressMapCallBack and
2138 // ExitBootServiceCallBack.
2140 setVirtuals
= SurfaceAreaQuery
.getSetVirtualAddressMapCallBackArray();
2141 exitBoots
= SurfaceAreaQuery
.getExitBootServicesCallBackArray();
2142 if (setVirtuals
!= null) {
2143 for (int j
= 0; j
< setVirtuals
.length
; j
++) {
2144 this.setVirtalAddList
.add(setVirtuals
[j
]);
2147 if (exitBoots
!= null) {
2148 for (int k
= 0; k
< exitBoots
.length
; k
++) {
2149 this.exitBootServiceList
.add(exitBoots
[k
]);
2152 SurfaceAreaQuery
.pop();
2154 // Add dependent library instance constructor function.
2156 if (libConstructName
!= null) {
2157 this.libConstructList
.add(libConstructName
);
2160 // Add dependent library instance destructor fuction.
2162 if (libDestructName
!= null) {
2163 this.libDestructList
.add(libDestructName
);
2170 } catch (Exception e
) {
2171 System
.out
.println(e
.getMessage());
2172 System
.out
.println("Collect library instance failed!");