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
;
20 import org
.tianocore
.build
.global
.GlobalData
;
21 import org
.tianocore
.build
.global
.Spd
;
22 import org
.tianocore
.build
.global
.SurfaceAreaQuery
;
23 import org
.tianocore
.build
.id
.ModuleIdentification
;
24 import org
.tianocore
.build
.id
.PackageIdentification
;
25 import org
.tianocore
.GuidsDocument
;
26 import org
.tianocore
.LibraryClassDocument
.LibraryClass
;
27 import org
.tianocore
.PPIsDocument
;
28 import org
.tianocore
.ProtocolsDocument
;
29 import org
.tianocore
.build
.pcd
.action
.PCDAutoGenAction
;
30 import org
.tianocore
.build
.exception
.*;
31 import org
.tianocore
.logger
.EdkLog
;
32 import org
.apache
.tools
.ant
.BuildException
;
33 import org
.apache
.xmlbeans
.XmlObject
;
36 import java
.io
.FileReader
;
37 import java
.io
.FileWriter
;
38 import java
.util
.ArrayList
;
39 import java
.util
.HashSet
;
40 import java
.util
.Iterator
;
41 import java
.util
.LinkedList
;
42 import java
.util
.List
;
47 * This class is to generate Autogen.h and Autogen.c according to module surface
48 * area or library surface area.
50 public class AutoGen
{
52 // / The output path of Autogen.h and Autogen.c
54 private String outputPath
;
57 // / The base name of module or library.
59 private ModuleIdentification moduleId
;
62 // / The build architecture
67 // / PcdAutogen instance which is used to manage how to generate the PCD
70 private PCDAutoGenAction myPcdAutogen
;
73 // / The protocl list which records in module or library surface area and
74 // / it's dependence on library instance surface area.
76 private Set
<String
> mProtocolList
= new HashSet
<String
>();
79 // / The Ppi list which recorded in module or library surface area and its
80 // / dependency on library instance surface area.
82 private Set
<String
> mPpiList
= new HashSet
<String
>();
85 // / The Guid list which recoreded in module or library surface area and it's
86 // / dependence on library instance surface area.
88 private Set
<String
> mGuidList
= new HashSet
<String
>();
91 // The dependence package list which recoreded in module or library surface
92 // area and it's dependence on library instance surface are.
94 private List
<PackageIdentification
> mDepPkgList
= new LinkedList
<PackageIdentification
>();
98 * This function mainly initialize some member variable.
101 * Output path of AutoGen file.
105 * Target architecture.
107 public AutoGen(String outputPath
, ModuleIdentification moduleId
, String arch
) {
108 this.outputPath
= outputPath
;
109 this.moduleId
= moduleId
;
117 * This function save the content in stringBuffer to file.
122 * The content of AutoGen file in buffer.
123 * @return "true" successful, "false" failed.
125 private boolean saveFile(String fileName
, StringBuffer fileBuffer
) {
127 File autoGenH
= new File(fileName
);
130 // if the file exists, compare their content
132 if (autoGenH
.exists()) {
133 FileReader fIn
= new FileReader(autoGenH
);
134 char[] oldFileBuffer
= new char[(int) autoGenH
.length()];
135 fIn
.read(oldFileBuffer
, 0, (int) autoGenH
.length());
139 // if we got the same file, don't re-generate it to prevent
140 // sources depending on it from re-building
142 if (fileBuffer
.toString().compareTo(new String(oldFileBuffer
)) == 0) {
146 FileWriter fOut
= new FileWriter(autoGenH
);
147 fOut
.write(fileBuffer
.toString());
149 } catch (Exception e
) {
156 * genAutogen function
158 * This function call libGenAutoGen or moduleGenAutogen function, which
159 * dependence on generate library autogen or module autogen.
161 * @throws BuildException
162 * Failed to creat AutoGen.c & AutoGen.h.
164 public void genAutogen() throws BuildException
{
167 // If outputPath do not exist, create it.
169 File path
= new File(outputPath
);
173 // Check current is library or not, then call the corresponding
176 if (this.moduleId
.isLibrary()) {
182 } catch (Exception e
) {
183 throw new BuildException(
184 "Failed to create AutoGen.c & AutoGen.h!\n"
190 * moduleGenAutogen function
192 * This function generates AutoGen.c & AutoGen.h for module.
194 * @throws BuildException
195 * Faile to create module AutoGen.c & AutoGen.h.
197 void moduleGenAutogen() throws BuildException
{
202 } catch (Exception e
) {
203 throw new BuildException(
204 "Faile to create module AutoGen.c & AutoGen.h!\n"
210 * libGenAutogen function
212 * This function generates AutoGen.c & AutoGen.h for library.
214 * @throws BuildException
215 * Faile to create library AutoGen.c & AutoGen.h
217 void libGenAutogen() throws BuildException
{
221 } catch (Exception e
) {
222 throw new BuildException(
223 "Faile to create library AutoGen.c & AutoGen.h!\n"
231 * This function generates AutoGen.h for module.
233 * @throws BuildException
234 * Failed to generate AutoGen.h.
236 void moduleGenAutogenH() throws AutoGenException
{
238 Set
<String
> libClassIncludeH
;
240 // List<String> headerFileList;
241 List
<String
> headerFileList
;
243 StringBuffer fileBuffer
= new StringBuffer(8192);
246 // Write Autogen.h header notation
248 fileBuffer
.append(CommonDefinition
.autogenHNotation
);
251 // Add #ifndef ${BaseName}_AUTOGENH
252 // #def ${BseeName}_AUTOGENH
254 fileBuffer
.append("#ifndef " + this.moduleId
.getName().toUpperCase()
256 fileBuffer
.append("#define " + this.moduleId
.getName().toUpperCase()
257 + "_AUTOGENH\r\n\r\n");
260 // Write the specification version and release version at the begine
261 // of autogen.h file.
262 // Note: the specification version and release version should
263 // be got from module surface area instead of hard code by it's
266 moduleType
= SurfaceAreaQuery
.getModuleType();
269 // Add "extern int __make_me_compile_correctly;" at begin of
272 fileBuffer
.append(CommonDefinition
.autoGenHbegin
);
275 // Put EFI_SPECIFICATION_VERSION, and EDK_RELEASE_VERSION.
277 String
[] specList
= SurfaceAreaQuery
.getExternSpecificaiton();
278 for (int i
= 0; i
< specList
.length
; i
++) {
279 fileBuffer
.append(CommonDefinition
.marcDefineStr
+ specList
[i
]
283 // Write consumed package's mdouleInfo related .h file to autogen.h
285 // PackageIdentification[] consumedPkgIdList = SurfaceAreaQuery
286 // .getDependencePkg(this.arch);
287 PackageIdentification
[] consumedPkgIdList
= SurfaceAreaQuery
288 .getDependencePkg(this.arch
);
289 if (consumedPkgIdList
!= null) {
290 headerFileList
= depPkgToAutogenH(consumedPkgIdList
, moduleType
);
291 item
= headerFileList
.iterator();
292 while (item
.hasNext()) {
293 fileBuffer
.append(item
.next().toString());
298 // Write library class's related *.h file to autogen.h.
300 String
[] libClassList
= SurfaceAreaQuery
301 .getLibraryClasses(CommonDefinition
.AlwaysConsumed
);
302 if (libClassList
!= null) {
303 libClassIncludeH
= LibraryClassToAutogenH(libClassList
);
304 item
= libClassIncludeH
.iterator();
305 while (item
.hasNext()) {
306 fileBuffer
.append(item
.next().toString());
310 libClassList
= SurfaceAreaQuery
311 .getLibraryClasses(CommonDefinition
.AlwaysProduced
);
312 if (libClassList
!= null) {
313 libClassIncludeH
= LibraryClassToAutogenH(libClassList
);
314 item
= libClassIncludeH
.iterator();
315 while (item
.hasNext()) {
316 fileBuffer
.append(item
.next().toString());
319 fileBuffer
.append("\r\n");
322 // Write PCD autogen information to AutoGen.h.
324 if (this.myPcdAutogen
!= null) {
325 fileBuffer
.append("\r\n");
326 fileBuffer
.append(this.myPcdAutogen
.OutputH());
330 // Append the #endif at AutoGen.h
332 fileBuffer
.append("#endif\r\n");
335 // Save string buffer content in AutoGen.h.
337 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.h", fileBuffer
)) {
338 throw new BuildException("Failed to generate AutoGen.h !!!");
345 * This function generates AutoGen.c for module.
347 * @throws BuildException
348 * Failed to generate AutoGen.c.
350 void moduleGenAutogenC() throws AutoGenException
{
352 StringBuffer fileBuffer
= new StringBuffer(8192);
354 // Write Autogen.c header notation
356 fileBuffer
.append(CommonDefinition
.autogenCNotation
);
359 // Write #include <AutoGen.h> at beginning of AutoGen.c
361 fileBuffer
.append(CommonDefinition
.includeAutogenH
);
364 // Get the native MSA file infomation. Since before call autogen,
365 // the MSA native <Externs> information were overrided. So before
366 // process <Externs> it should be set the DOC as the Native MSA info.
368 Map
<String
, XmlObject
> doc
= GlobalData
.getNativeMsa(this.moduleId
);
369 SurfaceAreaQuery
.push(doc
);
372 // DriverBinding/ComponentName/DriverConfiguration/DriverDialog
376 ExternsDriverBindingToAutoGenC(fileBuffer
);
379 // Write DriverExitBootServicesEvent/DriverSetVirtualAddressMapEvent
382 ExternCallBackToAutoGenC(fileBuffer
);
385 // Write EntryPoint to autgoGen.c
387 String
[] entryPointList
= SurfaceAreaQuery
.getModuleEntryPointArray();
388 EntryPointToAutoGen(CommonDefinition
.remDupString(entryPointList
), fileBuffer
);
392 // Restore the DOC which include the FPD module info.
394 SurfaceAreaQuery
.pop();
397 // Write Guid to autogen.c
399 String guid
= CommonDefinition
.formatGuidName(SurfaceAreaQuery
403 .append("GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiCallerIdGuid = {");
405 throw new AutoGenException("Guid value must set!\n");
409 // Formate Guid as ANSI c form.Example:
410 // {0xd2b2b828, 0x826, 0x48a7,{0xb3, 0xdf, 0x98, 0x3c, 0x0, 0x60, 0x24,
414 fileBuffer
.append(guid
);
415 fileBuffer
.append("};\r\n");
418 // Generate library instance consumed protocol, guid, ppi, pcd list.
419 // Save those to this.protocolList, this.ppiList, this.pcdList,
420 // this.guidList. Write Consumed library constructor and desconstuct to
423 LibInstanceToAutogenC(fileBuffer
);
426 // Get module dependent Package identification.
428 PackageIdentification
[] packages
= SurfaceAreaQuery
.getDependencePkg(this.arch
);
429 for (int i
= 0; i
< packages
.length
; i
++){
430 if (!this.mDepPkgList
.contains(packages
[i
])){
431 this.mDepPkgList
.add(packages
[i
]);
437 // Write consumed ppi, guid, protocol to autogen.c
439 ProtocolGuidToAutogenC(fileBuffer
);
440 PpiGuidToAutogenC(fileBuffer
);
441 GuidGuidToAutogenC(fileBuffer
);
444 // Call pcd autogen. PCDAutoGenAction tool only need module name and
445 // isPcdEmulatedDriver as parameter. Library inherits PCD and module's
446 // PCD information has been collected in FPDParser task by
448 // Note : when PCD image tool ready,
449 // isPCDEmulatedDriver parameter will be removed.
452 // this.myPcdAutogen = new PCDAutoGenAction(moduleId.getName(),
453 // moduleId.getGuid(), moduleId.getPackage().getName(), moduleId.getPackage().getGuid(),this.arch,moduleId.getVersion(),false, null);
454 this.myPcdAutogen
= new PCDAutoGenAction(moduleId
.getName(),null,null,null, this.arch
,null,false, null);
455 this.myPcdAutogen
.execute();
456 } catch (Exception e
) {
457 throw new BuildException("PCD Autogen failed:" + e
.getMessage());
460 if (this.myPcdAutogen
!= null) {
461 fileBuffer
.append("\r\n");
462 fileBuffer
.append(this.myPcdAutogen
.OutputC());
465 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.c", fileBuffer
)) {
466 throw new BuildException("Failed to generate AutoGen.c !!!");
474 * This function generates AutoGen.h for library.
476 * @throws BuildException
477 * Failed to generate AutoGen.c.
479 void libGenAutogenH() throws AutoGenException
{
481 Set
<String
> libClassIncludeH
;
483 List
<String
> headerFileList
;
485 StringBuffer fileBuffer
= new StringBuffer(10240);
488 // Write Autogen.h header notation
490 fileBuffer
.append(CommonDefinition
.autogenHNotation
);
493 // Add #ifndef ${BaseName}_AUTOGENH
494 // #def ${BseeName}_AUTOGENH
496 fileBuffer
.append("#ifndef " + this.moduleId
.getName().toUpperCase()
498 fileBuffer
.append("#define " + this.moduleId
.getName().toUpperCase()
499 + "_AUTOGENH\r\n\r\n");
502 // Write EFI_SPECIFICATION_VERSION and EDK_RELEASE_VERSION
503 // to autogen.h file.
504 // Note: the specification version and release version should
505 // be get from module surface area instead of hard code.
507 fileBuffer
.append(CommonDefinition
.autoGenHbegin
);
508 String
[] specList
= SurfaceAreaQuery
.getExternSpecificaiton();
509 for (int i
= 0; i
< specList
.length
; i
++) {
510 fileBuffer
.append(CommonDefinition
.marcDefineStr
+ specList
[i
]
513 // fileBuffer.append(CommonDefinition.autoGenHLine1);
514 // fileBuffer.append(CommonDefinition.autoGenHLine2);
517 // Write consumed package's mdouleInfo related *.h file to autogen.h.
519 moduleType
= SurfaceAreaQuery
.getModuleType();
520 PackageIdentification
[] cosumedPkglist
= SurfaceAreaQuery
521 .getDependencePkg(this.arch
);
522 headerFileList
= depPkgToAutogenH(cosumedPkglist
, moduleType
);
523 item
= headerFileList
.iterator();
524 while (item
.hasNext()) {
525 fileBuffer
.append(item
.next().toString());
528 // Write library class's related *.h file to autogen.h
530 String
[] libClassList
= SurfaceAreaQuery
531 .getLibraryClasses(CommonDefinition
.AlwaysConsumed
);
532 if (libClassList
!= null) {
533 libClassIncludeH
= LibraryClassToAutogenH(libClassList
);
534 item
= libClassIncludeH
.iterator();
535 while (item
.hasNext()) {
536 fileBuffer
.append(item
.next().toString());
540 libClassList
= SurfaceAreaQuery
541 .getLibraryClasses(CommonDefinition
.AlwaysProduced
);
542 if (libClassList
!= null) {
543 libClassIncludeH
= LibraryClassToAutogenH(libClassList
);
544 item
= libClassIncludeH
.iterator();
545 while (item
.hasNext()) {
546 fileBuffer
.append(item
.next().toString());
549 fileBuffer
.append("\r\n");
552 // Write PCD information to library AutoGen.h.
554 if (this.myPcdAutogen
!= null) {
555 fileBuffer
.append("\r\n");
556 fileBuffer
.append(this.myPcdAutogen
.OutputH());
560 // Append the #endif at AutoGen.h
562 fileBuffer
.append("#endif\r\n");
565 // Save content of string buffer to AutoGen.h file.
567 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.h", fileBuffer
)) {
568 throw new BuildException("Failed to generate AutoGen.h !!!");
575 * This function generates AutoGen.h for library.
577 * @throws BuildException
578 * Failed to generate AutoGen.c.
580 void libGenAutogenC() throws BuildException
{
581 StringBuffer fileBuffer
= new StringBuffer(10240);
584 // Write Autogen.c header notation
586 fileBuffer
.append(CommonDefinition
.autogenCNotation
);
588 fileBuffer
.append(CommonDefinition
.autoGenCLine1
);
589 fileBuffer
.append("\r\n");
592 // Call pcd autogen. PCDAutoGenAction tool only need module name and
593 // isPcdEmulatedDriver as parameter. Library inherit PCD and module's
594 // PCD information has been collected in FPDParser task by
596 // Note : when PCD image tool ready,
597 // isPCDEmulatedDriver parameter will be removed.
600 // this.myPcdAutogen = new PCDAutoGenAction(this.moduleId.getName(),
601 // this.moduleId.getGuid(),moduleId.getPackage().getName(),moduleId.getPackage().getGuid(), this.arch, moduleId.getVersion(),true, SurfaceAreaQuery.getModulePcdEntryNameArray());
602 this.myPcdAutogen
= new PCDAutoGenAction(this.moduleId
.getName(),
609 SurfaceAreaQuery
.getModulePcdEntryNameArray());
611 this.myPcdAutogen
.execute();
612 } catch (Exception e
) {
613 throw new BuildException(e
.getMessage());
616 if (this.myPcdAutogen
!= null) {
617 fileBuffer
.append("\r\n");
618 fileBuffer
.append(this.myPcdAutogen
.OutputC());
621 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.c", fileBuffer
)) {
622 throw new BuildException("Failed to generate AutoGen.c !!!");
627 * LibraryClassToAutogenH
629 * This function returns *.h files declared by library classes which are
630 * consumed or produced by current build module or library.
632 * @param libClassList
633 * List of library class which consumed or produce by current
634 * build module or library.
635 * @return includeStrList List of *.h file.
637 Set
<String
> LibraryClassToAutogenH(String
[] libClassList
)
638 throws AutoGenException
{
639 Set
<String
> includStrList
= new HashSet
<String
>();
640 String includerName
[];
644 // Get include file from GlobalData's SPDTable according to
645 // library class name.
648 for (int i
= 0; i
< libClassList
.length
; i
++) {
649 includerName
= GlobalData
.getLibraryClassHeaderFiles(
650 SurfaceAreaQuery
.getDependencePkg(this.arch
),
652 if (includerName
== null) {
653 throw new AutoGenException("Can not find library class ["
654 + libClassList
[i
] + "] declaration in every packages. ");
656 for (int j
= 0; j
< includerName
.length
; j
++) {
657 String includeNameStr
= includerName
[j
];
658 if (includeNameStr
!= null) {
659 str
= CommonDefinition
.include
+ " " + "<";
660 str
= str
+ includeNameStr
+ ">\r\n";
661 includStrList
.add(str
);
662 includeNameStr
= null;
666 return includStrList
;
672 * This function add include file in AutoGen.h file.
674 * @param packageNameList
675 * List of module depended package.
680 List
<String
> depPkgToAutogenH(PackageIdentification
[] packageNameList
,
681 String moduleType
) throws AutoGenException
{
683 List
<String
> includeStrList
= new LinkedList
<String
>();
685 String includeStr
= "";
688 // Get include file from moduleInfo file
690 for (int i
= 0; i
< packageNameList
.length
; i
++) {
691 pkgHeader
= GlobalData
.getPackageHeaderFiles(packageNameList
[i
],
693 if (pkgHeader
== null) {
694 throw new AutoGenException("Can not find package ["
696 + "] declaration in every packages. ");
697 } else if (!pkgHeader
.equalsIgnoreCase("")) {
698 includeStr
= CommonDefinition
.include
+ " <" + pkgHeader
700 includeStrList
.add(includeStr
);
704 return includeStrList
;
708 * EntryPointToAutoGen
710 * This function convert <ModuleEntryPoint> & <ModuleUnloadImage>
711 * information in mas to AutoGen.c
713 * @param entryPointList
714 * List of entry point.
716 * String buffer fo AutoGen.c.
719 void EntryPointToAutoGen(String
[] entryPointList
, StringBuffer fileBuffer
)
720 throws BuildException
{
722 String typeStr
= SurfaceAreaQuery
.getModuleType();
725 // The parameters and return value of entryPoint is difference
726 // for difference module type.
728 switch (CommonDefinition
.getModuleType(typeStr
)) {
730 case CommonDefinition
.ModuleTypePeiCore
:
731 if (entryPointList
== null ||entryPointList
.length
!= 1 ) {
732 throw new BuildException(
733 "Module type = 'PEI_CORE', only have one module entry point!");
735 fileBuffer
.append("EFI_STATUS\r\n");
736 fileBuffer
.append("EFIAPI\r\n");
737 fileBuffer
.append(entryPointList
[0]);
738 fileBuffer
.append(" (\r\n");
740 .append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n");
742 .append(" IN VOID *OldCoreData\r\n");
743 fileBuffer
.append(" );\r\n\r\n");
745 fileBuffer
.append("EFI_STATUS\r\n");
746 fileBuffer
.append("EFIAPI\r\n");
747 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
749 .append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n");
751 .append(" IN VOID *OldCoreData\r\n");
752 fileBuffer
.append(" )\r\n\r\n");
753 fileBuffer
.append("{\r\n");
754 fileBuffer
.append(" return ");
755 fileBuffer
.append(entryPointList
[0]);
756 fileBuffer
.append(" (PeiStartupDescriptor, OldCoreData);\r\n");
757 fileBuffer
.append("}\r\n\r\n");
761 case CommonDefinition
.ModuleTypeDxeCore
:
762 fileBuffer
.append("const UINT32 _gUefiDriverRevision = 0;\r\n");
763 if (entryPointList
== null || entryPointList
.length
!= 1) {
764 throw new BuildException(
765 "Module type = 'DXE_CORE', only have one module entry point!");
768 fileBuffer
.append("VOID\r\n");
769 fileBuffer
.append("EFIAPI\r\n");
770 fileBuffer
.append(entryPointList
[0]);
771 fileBuffer
.append(" (\n");
772 fileBuffer
.append(" IN VOID *HobStart\r\n");
773 fileBuffer
.append(" );\r\n\r\n");
775 fileBuffer
.append("VOID\r\n");
776 fileBuffer
.append("EFIAPI\r\n");
777 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
778 fileBuffer
.append(" IN VOID *HobStart\r\n");
779 fileBuffer
.append(" )\r\n\r\n");
780 fileBuffer
.append("{\r\n");
781 fileBuffer
.append(" ");
782 fileBuffer
.append(entryPointList
[0]);
783 fileBuffer
.append(" (HobStart);\r\n");
784 fileBuffer
.append("}\r\n\r\n");
788 case CommonDefinition
.ModuleTypePeim
:
789 int entryPointCount
= 0;
791 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = 0;\r\n");
792 if (entryPointList
== null || entryPointList
.length
== 0) {
793 fileBuffer
.append("EFI_STATUS\r\n");
794 fileBuffer
.append("EFIAPI\r\n");
795 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
796 fileBuffer
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
797 fileBuffer
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
798 fileBuffer
.append(" )\r\n\r\n");
799 fileBuffer
.append("{\r\n");
800 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
801 fileBuffer
.append("}\r\n\r\n");
804 for (int i
= 0; i
< entryPointList
.length
; i
++) {
805 fileBuffer
.append("EFI_STATUS\r\n");
806 fileBuffer
.append("EFIAPI\r\n");
807 fileBuffer
.append(entryPointList
[i
]);
808 fileBuffer
.append(" (\r\n");
810 .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
812 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
813 fileBuffer
.append(" );\r\n");
818 fileBuffer
.append("EFI_STATUS\r\n");
819 fileBuffer
.append("EFIAPI\r\n");
820 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
821 fileBuffer
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
822 fileBuffer
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
823 fileBuffer
.append(" )\r\n\r\n");
824 fileBuffer
.append("{\r\n");
825 if (entryPointCount
== 1) {
826 fileBuffer
.append(" return ");
827 fileBuffer
.append(entryPointList
[0]);
828 fileBuffer
.append(" (FfsHeader, PeiServices);\r\n");
830 fileBuffer
.append(" EFI_STATUS Status;\r\n");
831 fileBuffer
.append(" EFI_STATUS CombinedStatus;\r\n\r\n");
832 fileBuffer
.append(" CombinedStatus = EFI_LOAD_ERROR;\r\n\r\n");
833 for (int i
= 0; i
< entryPointList
.length
; i
++) {
834 if (!entryPointList
[i
].equals("")) {
835 fileBuffer
.append(" Status = ");
836 fileBuffer
.append(entryPointList
[i
]);
837 fileBuffer
.append(" (FfsHeader, PeiServices);\r\n");
839 .append(" if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {\r\n");
840 fileBuffer
.append(" CombinedStatus = Status;\r\n");
841 fileBuffer
.append(" }\r\n\r\n");
846 fileBuffer
.append(" return CombinedStatus;\r\n");
848 fileBuffer
.append("}\r\n\r\n");
851 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
854 // If entryPoint is null, create an empty ProcessModuleEntryPointList
857 if (entryPointList
== null || entryPointList
.length
== 0){
859 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
860 fileBuffer
.append(Integer
.toString(entryPointCount
));
861 fileBuffer
.append(";\r\n");
862 fileBuffer
.append("EFI_STATUS\r\n");
863 fileBuffer
.append("EFIAPI\r\n");
864 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
865 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
866 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
867 fileBuffer
.append(" )\r\n\r\n");
868 fileBuffer
.append("{\r\n");
869 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
870 fileBuffer
.append("}\r\n\r\n");
873 for (int i
= 0; i
< entryPointList
.length
; i
++) {
874 fileBuffer
.append("EFI_STATUS\r\n");
875 fileBuffer
.append("EFIAPI\r\n");
876 fileBuffer
.append(entryPointList
[i
]);
877 fileBuffer
.append(" (\r\n");
878 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
879 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
880 fileBuffer
.append(" );\r\n");
884 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
885 fileBuffer
.append(Integer
.toString(entryPointCount
));
886 fileBuffer
.append(";\r\n");
888 .append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");
890 .append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n\r\n");
892 fileBuffer
.append("EFI_STATUS\r\n");
893 fileBuffer
.append("EFIAPI\r\n");
894 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
895 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
896 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
897 fileBuffer
.append(" )\r\n\r\n");
898 fileBuffer
.append("{\r\n");
901 for (int i
= 0; i
< entryPointList
.length
; i
++) {
903 .append(" if (SetJump (&mJumpContext) == 0) {\r\n");
904 fileBuffer
.append(" ExitDriver (");
905 fileBuffer
.append(entryPointList
[i
]);
906 fileBuffer
.append(" (ImageHandle, SystemTable));\r\n");
907 fileBuffer
.append(" ASSERT (FALSE);\r\n");
908 fileBuffer
.append(" }\r\n");
911 fileBuffer
.append(" return mDriverEntryPointStatus;\r\n");
912 fileBuffer
.append("}\r\n\r\n");
914 fileBuffer
.append("VOID\r\n");
915 fileBuffer
.append("EFIAPI\r\n");
916 fileBuffer
.append("ExitDriver (\r\n");
917 fileBuffer
.append(" IN EFI_STATUS Status\n");
918 fileBuffer
.append(" )\r\n\r\n");
919 fileBuffer
.append("{\r\n");
921 .append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");
922 fileBuffer
.append(" mDriverEntryPointStatus = Status;\r\n");
923 fileBuffer
.append(" }\r\n");
924 fileBuffer
.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");
925 fileBuffer
.append(" ASSERT (FALSE);\r\n");
926 fileBuffer
.append("}\r\n\r\n");
932 // Add "ModuleUnloadImage" for DxeSmmDriver module type;
934 entryPointList
= SurfaceAreaQuery
.getModuleUnloadImageArray();
935 entryPointList
= CommonDefinition
.remDupString(entryPointList
);
938 if (entryPointList
!= null) {
939 for (int i
= 0; i
< entryPointList
.length
; i
++) {
940 fileBuffer
.append("EFI_STATUS\r\n");
941 fileBuffer
.append("EFIAPI\r\n");
942 fileBuffer
.append(entryPointList
[i
]);
943 fileBuffer
.append(" (\r\n");
945 .append(" IN EFI_HANDLE ImageHandle\r\n");
946 fileBuffer
.append(" );\r\n");
952 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");
953 fileBuffer
.append(Integer
.toString(entryPointCount
));
954 fileBuffer
.append(";\r\n\r\n");
956 fileBuffer
.append("EFI_STATUS\r\n");
957 fileBuffer
.append("EFIAPI\r\n");
958 fileBuffer
.append("ProcessModuleUnloadList (\r\n");
959 fileBuffer
.append(" IN EFI_HANDLE ImageHandle\r\n");
960 fileBuffer
.append(" )\r\n");
961 fileBuffer
.append("{\r\n");
963 if (entryPointCount
== 0) {
964 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
965 } else if (entryPointCount
== 1) {
966 fileBuffer
.append(" return ");
967 fileBuffer
.append(entryPointList
[0]);
968 fileBuffer
.append("(ImageHandle);\r\n");
970 fileBuffer
.append(" EFI_STATUS Status;\r\n\r\n");
971 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n\r\n");
972 for (int i
= 0; i
< entryPointList
.length
; i
++) {
974 fileBuffer
.append(" Status = ");
975 fileBuffer
.append(entryPointList
[i
]);
976 fileBuffer
.append("(ImageHandle);\r\n");
978 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
979 fileBuffer
.append(" ");
980 fileBuffer
.append(entryPointList
[i
]);
981 fileBuffer
.append("(ImageHandle);\r\n");
982 fileBuffer
.append(" } else {\r\n");
983 fileBuffer
.append(" Status = ");
984 fileBuffer
.append(entryPointList
[i
]);
985 fileBuffer
.append("(ImageHandle);\r\n");
986 fileBuffer
.append(" }\r\n");
989 fileBuffer
.append(" return Status;\r\n");
991 fileBuffer
.append("}\r\n\r\n");
994 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
995 case CommonDefinition
.ModuleTypeDxeDriver
:
996 case CommonDefinition
.ModuleTypeDxeSalDriver
:
997 case CommonDefinition
.ModuleTypeUefiDriver
:
998 case CommonDefinition
.ModuleTypeUefiApplication
:
1000 fileBuffer
.append("const UINT32 _gUefiDriverRevision = 0;\r\n");
1002 // If entry point is null, create a empty ProcessModuleEntryPointList function.
1004 if (entryPointList
== null || entryPointList
.length
== 0){
1006 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = 0;\r\n");
1007 fileBuffer
.append("EFI_STATUS\r\n");
1008 fileBuffer
.append("EFIAPI\r\n");
1009 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
1010 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1011 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1012 fileBuffer
.append(" )\r\n\r\n");
1013 fileBuffer
.append("{\r\n");
1014 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
1015 fileBuffer
.append("}\r\n");
1018 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1020 fileBuffer
.append("EFI_STATUS\r\n");
1021 fileBuffer
.append("EFIAPI\r\n");
1022 fileBuffer
.append(entryPointList
[i
]);
1023 fileBuffer
.append(" (\r\n");
1024 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1025 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1026 fileBuffer
.append(" );\r\n");
1031 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
1032 fileBuffer
.append(Integer
.toString(entryPointCount
));
1033 fileBuffer
.append(";\r\n");
1034 if (entryPointCount
> 1) {
1036 .append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");
1038 .append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n");
1040 fileBuffer
.append("\n");
1042 fileBuffer
.append("EFI_STATUS\r\n");
1043 fileBuffer
.append("EFIAPI\r\n");
1044 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
1045 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1046 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1047 fileBuffer
.append(" )\r\n\r\n");
1048 fileBuffer
.append("{\r\n");
1050 if (entryPointCount
== 1) {
1051 fileBuffer
.append(" return (");
1052 fileBuffer
.append(entryPointList
[0]);
1053 fileBuffer
.append(" (ImageHandle, SystemTable));\r\n");
1055 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1056 if (!entryPointList
[i
].equals("")) {
1058 .append(" if (SetJump (&mJumpContext) == 0) {\r\n");
1059 fileBuffer
.append(" ExitDriver (");
1060 fileBuffer
.append(entryPointList
[i
]);
1061 fileBuffer
.append(" (ImageHandle, SystemTable));\r\n");
1062 fileBuffer
.append(" ASSERT (FALSE);\r\n");
1063 fileBuffer
.append(" }\r\n");
1068 fileBuffer
.append(" return mDriverEntryPointStatus;\r\n");
1070 fileBuffer
.append("}\r\n\r\n");
1072 fileBuffer
.append("VOID\n");
1073 fileBuffer
.append("EFIAPI\n");
1074 fileBuffer
.append("ExitDriver (\r\n");
1075 fileBuffer
.append(" IN EFI_STATUS Status\n");
1076 fileBuffer
.append(" )\r\n\r\n");
1077 fileBuffer
.append("{\r\n");
1078 if (entryPointCount
<= 1) {
1079 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
1081 .append(" ProcessLibraryDestructorList (gImageHandle, gST);\r\n");
1082 fileBuffer
.append(" }\r\n");
1084 .append(" gBS->Exit (gImageHandle, Status, 0, NULL);\r\n");
1087 .append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");
1088 fileBuffer
.append(" mDriverEntryPointStatus = Status;\r\n");
1089 fileBuffer
.append(" }\r\n");
1090 fileBuffer
.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");
1091 fileBuffer
.append(" ASSERT (FALSE);\r\n");
1093 fileBuffer
.append("}\r\n\r\n");
1098 // Add ModuleUnloadImage for DxeDriver and UefiDriver module type.
1100 entryPointList
= SurfaceAreaQuery
.getModuleUnloadImageArray();
1102 // Remover duplicate unload entry point.
1104 entryPointList
= CommonDefinition
.remDupString(entryPointList
);
1105 entryPointCount
= 0;
1106 if (entryPointList
!= null) {
1107 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1108 fileBuffer
.append("EFI_STATUS\r\n");
1109 fileBuffer
.append("EFIAPI\r\n");
1110 fileBuffer
.append(entryPointList
[i
]);
1111 fileBuffer
.append(" (\r\n");
1113 .append(" IN EFI_HANDLE ImageHandle\r\n");
1114 fileBuffer
.append(" );\r\n");
1120 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");
1121 fileBuffer
.append(Integer
.toString(entryPointCount
));
1122 fileBuffer
.append(";\r\n\r\n");
1124 fileBuffer
.append("EFI_STATUS\n");
1125 fileBuffer
.append("EFIAPI\r\n");
1126 fileBuffer
.append("ProcessModuleUnloadList (\r\n");
1127 fileBuffer
.append(" IN EFI_HANDLE ImageHandle\r\n");
1128 fileBuffer
.append(" )\r\n");
1129 fileBuffer
.append("{\r\n");
1131 if (entryPointCount
== 0) {
1132 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
1133 } else if (entryPointCount
== 1) {
1134 fileBuffer
.append(" return ");
1135 fileBuffer
.append(entryPointList
[0]);
1136 fileBuffer
.append("(ImageHandle);\r\n");
1138 fileBuffer
.append(" EFI_STATUS Status;\r\n\r\n");
1139 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n\r\n");
1140 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1142 fileBuffer
.append(" Status = ");
1143 fileBuffer
.append(entryPointList
[i
]);
1144 fileBuffer
.append("(ImageHandle);\r\n");
1146 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
1147 fileBuffer
.append(" ");
1148 fileBuffer
.append(entryPointList
[i
]);
1149 fileBuffer
.append("(ImageHandle);\r\n");
1150 fileBuffer
.append(" } else {\r\n");
1151 fileBuffer
.append(" Status = ");
1152 fileBuffer
.append(entryPointList
[i
]);
1153 fileBuffer
.append("(ImageHandle);\r\n");
1154 fileBuffer
.append(" }\r\n");
1157 fileBuffer
.append(" return Status;\r\n");
1159 fileBuffer
.append("}\r\n\r\n");
1167 * This function gets GUIDs from SPD file accrodeing to <PPIs> information
1168 * and write those GUIDs to AutoGen.c.
1171 * String Buffer for Autogen.c file.
1172 * @throws BuildException
1173 * Guid must set value!
1175 void PpiGuidToAutogenC(StringBuffer fileBuffer
) throws AutoGenException
{
1176 String
[] cNameGuid
= null;
1179 // Get the all PPI adn PPI Notify from MSA file,
1180 // then add those PPI ,and PPI Notify name to list.
1183 String
[] ppiList
= SurfaceAreaQuery
.getPpiArray(this.arch
);
1184 for (int i
= 0; i
< ppiList
.length
; i
++) {
1185 this.mPpiList
.add(ppiList
[i
]);
1188 String
[] ppiNotifyList
= SurfaceAreaQuery
.getPpiNotifyArray(this.arch
);
1189 for (int i
= 0; i
< ppiNotifyList
.length
; i
++) {
1190 this.mPpiList
.add(ppiNotifyList
[i
]);
1194 // Find CNAME and GUID from dependence SPD file and write to Autogen.c
1196 Iterator ppiIterator
= this.mPpiList
.iterator();
1197 String ppiKeyWord
= null;
1198 while (ppiIterator
.hasNext()) {
1199 ppiKeyWord
= ppiIterator
.next().toString();
1200 cNameGuid
= GlobalData
.getPpiGuid(this.mDepPkgList
, ppiKeyWord
);
1201 if (cNameGuid
!= null) {
1203 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1204 fileBuffer
.append(cNameGuid
[0]);
1205 fileBuffer
.append(" = { ");
1206 fileBuffer
.append(CommonDefinition
.formatGuidName(cNameGuid
[1]));
1207 fileBuffer
.append(" } ;");
1210 // If can't find Ppi GUID declaration in every package
1212 throw new AutoGenException("Can not find Ppi GUID ["
1213 + ppiKeyWord
+ "] declaration in every packages. ");
1219 * ProtocolGuidToAutogenc
1221 * This function gets GUIDs from SPD file accrodeing to <Protocol>
1222 * information and write those GUIDs to AutoGen.c.
1225 * String Buffer for Autogen.c file.
1226 * @throws BuildException
1227 * Protocol name must set.
1229 void ProtocolGuidToAutogenC(StringBuffer fileBuffer
) throws BuildException
{
1230 String
[] cNameGuid
= null;
1232 String
[] protocolList
= SurfaceAreaQuery
.getProtocolArray(this.arch
);
1235 // Add result to Autogen global list.
1237 for (int i
= 0; i
< protocolList
.length
; i
++) {
1238 this.mProtocolList
.add(protocolList
[i
]);
1241 String
[] protocolNotifyList
= SurfaceAreaQuery
1242 .getProtocolNotifyArray(this.arch
);
1244 for (int i
= 0; i
< protocolNotifyList
.length
; i
++) {
1245 this.mProtocolList
.add(protocolNotifyList
[i
]);
1249 // Get the NAME and GUID from dependence SPD and write to Autogen.c
1251 Iterator protocolIterator
= this.mProtocolList
.iterator();
1252 String protocolKeyWord
= null;
1255 while (protocolIterator
.hasNext()) {
1256 protocolKeyWord
= protocolIterator
.next().toString();
1257 cNameGuid
= GlobalData
.getProtocolGuid(this.mDepPkgList
, protocolKeyWord
);
1258 if (cNameGuid
!= null) {
1260 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1261 fileBuffer
.append(cNameGuid
[0]);
1262 fileBuffer
.append(" = { ");
1263 fileBuffer
.append(CommonDefinition
.formatGuidName(cNameGuid
[1]));
1264 fileBuffer
.append(" } ;");
1267 // If can't find protocol GUID declaration in every package
1269 throw new BuildException("Can not find protocol Guid ["
1270 + protocolKeyWord
+ "] declaration in every packages. ");
1276 * GuidGuidToAutogenc
1278 * This function gets GUIDs from SPD file accrodeing to <Guids> information
1279 * and write those GUIDs to AutoGen.c.
1282 * String Buffer for Autogen.c file.
1285 void GuidGuidToAutogenC(StringBuffer fileBuffer
) throws AutoGenException
{
1286 String
[] cNameGuid
= null;
1287 String guidKeyWord
= null;
1289 String
[] guidList
= SurfaceAreaQuery
.getGuidEntryArray(this.arch
);
1291 for (int i
= 0; i
< guidList
.length
; i
++) {
1292 this.mGuidList
.add(guidList
[i
]);
1296 Iterator guidIterator
= this.mGuidList
.iterator();
1297 while (guidIterator
.hasNext()) {
1298 guidKeyWord
= guidIterator
.next().toString();
1299 cNameGuid
= GlobalData
.getGuid(this.mDepPkgList
, guidKeyWord
);
1301 if (cNameGuid
!= null) {
1303 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1304 fileBuffer
.append(cNameGuid
[0]);
1305 fileBuffer
.append(" = { ");
1306 fileBuffer
.append(CommonDefinition
.formatGuidName(cNameGuid
[1]));
1307 fileBuffer
.append("} ;");
1310 // If can't find GUID declaration in every package
1312 throw new AutoGenException("Can not find Guid [" + guidKeyWord
1313 + "] declaration in every packages. ");
1320 * LibInstanceToAutogenC
1322 * This function adds dependent library instance to autogen.c,which
1323 * includeing library's constructor, destructor, and library dependent ppi,
1324 * protocol, guid, pcd information.
1327 * String buffer for AutoGen.c
1328 * @throws BuildException
1330 void LibInstanceToAutogenC(StringBuffer fileBuffer
) throws BuildException
{
1333 String moduleType
= SurfaceAreaQuery
.getModuleType();
1334 List
<String
> libConstructList
= new ArrayList
<String
>();
1335 List
<String
> libDestructList
= new ArrayList
<String
>();
1337 String libConstructName
= null;
1338 String libDestructName
= null;
1339 ModuleIdentification
[] libraryIdList
= SurfaceAreaQuery
1340 .getLibraryInstance(this.arch
);
1343 if (libraryIdList
!= null) {
1345 // Reorder library instance sequence.
1347 AutogenLibOrder libOrder
= new AutogenLibOrder(libraryIdList
,
1349 List
<ModuleIdentification
> orderList
= libOrder
1350 .orderLibInstance();
1352 if (orderList
!= null) {
1354 // Process library instance one by one.
1356 for (int i
= 0; i
< orderList
.size(); i
++) {
1359 // Get library instance basename.
1361 ModuleIdentification libInstanceId
= orderList
.get(i
);
1367 Map
<String
, XmlObject
> libDoc
= GlobalData
.getDoc(
1368 libInstanceId
, this.arch
);
1369 SurfaceAreaQuery
.push(libDoc
);
1372 // Get <PPis>, <Protocols>, <Guids> list of this library
1375 String
[] ppiList
= SurfaceAreaQuery
.getPpiArray(this.arch
);
1376 String
[] ppiNotifyList
= SurfaceAreaQuery
1377 .getPpiNotifyArray(this.arch
);
1378 String
[] protocolList
= SurfaceAreaQuery
1379 .getProtocolArray(this.arch
);
1380 String
[] protocolNotifyList
= SurfaceAreaQuery
1381 .getProtocolNotifyArray(this.arch
);
1382 String
[] guidList
= SurfaceAreaQuery
1383 .getGuidEntryArray(this.arch
);
1384 PackageIdentification
[] pkgList
= SurfaceAreaQuery
.getDependencePkg(this.arch
);
1387 // Add those ppi, protocol, guid in global ppi,
1391 for (index
= 0; index
< ppiList
.length
; index
++) {
1392 this.mPpiList
.add(ppiList
[index
]);
1395 for (index
= 0; index
< ppiNotifyList
.length
; index
++) {
1396 this.mPpiList
.add(ppiNotifyList
[index
]);
1399 for (index
= 0; index
< protocolList
.length
; index
++) {
1400 this.mProtocolList
.add(protocolList
[index
]);
1403 for (index
= 0; index
< protocolNotifyList
.length
; index
++) {
1404 this.mProtocolList
.add(protocolNotifyList
[index
]);
1407 for (index
= 0; index
< guidList
.length
; index
++) {
1408 this.mGuidList
.add(guidList
[index
]);
1410 for (index
= 0; index
< pkgList
.length
; index
++){
1411 if (!this.mDepPkgList
.contains(pkgList
[index
])){
1412 this.mDepPkgList
.add(pkgList
[index
]);
1417 // If not yet parse this library instance's constructor
1418 // element,parse it.
1420 libConstructName
= SurfaceAreaQuery
1421 .getLibConstructorName();
1422 libDestructName
= SurfaceAreaQuery
1423 .getLibDestructorName();
1425 SurfaceAreaQuery
.pop();
1427 // Add dependent library instance constructor function.
1429 if (libConstructName
!= null) {
1430 libConstructList
.add(libConstructName
);
1433 // Add dependent library instance destructor fuction.
1435 if (libDestructName
!= null) {
1436 libDestructList
.add(libDestructName
);
1443 // Add library constructor to AutoGen.c
1445 LibConstructorToAutogenC(libConstructList
, moduleType
,
1446 fileBuffer
/* autogenC */);
1448 // Add library destructor to AutoGen.c
1450 LibDestructorToAutogenC(libDestructList
, moduleType
, fileBuffer
/* autogenC */);
1453 } catch (Exception e
) {
1454 throw new BuildException(e
.getMessage());
1459 * LibConstructorToAutogenc
1461 * This function writes library constructor list to AutoGen.c. The library
1462 * constructor's parameter and return value depend on module type.
1464 * @param libInstanceList
1465 * List of library construct name.
1469 * String buffer for AutoGen.c
1472 void LibConstructorToAutogenC(List
<String
> libInstanceList
,
1473 String moduleType
, StringBuffer fileBuffer
) throws Exception
{
1474 boolean isFirst
= true;
1477 // The library constructor's parameter and return value depend on
1480 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1481 switch (CommonDefinition
.getModuleType(moduleType
)) {
1482 case CommonDefinition
.ModuleTypeBase
:
1483 fileBuffer
.append("RETURN_STATUS\r\n");
1484 fileBuffer
.append(libInstanceList
.get(i
));
1485 fileBuffer
.append(" (\r\n");
1486 fileBuffer
.append(" VOID\r\n");
1487 fileBuffer
.append(" );\r\n");
1490 case CommonDefinition
.ModuleTypePeiCore
:
1491 case CommonDefinition
.ModuleTypePeim
:
1492 fileBuffer
.append("EFI_STATUS\r\n");
1493 fileBuffer
.append(libInstanceList
.get(i
));
1494 fileBuffer
.append(" (\r\n");
1496 .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1498 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1499 fileBuffer
.append(" );\r\n");
1502 case CommonDefinition
.ModuleTypeDxeCore
:
1503 case CommonDefinition
.ModuleTypeDxeDriver
:
1504 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1505 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1506 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1507 case CommonDefinition
.ModuleTypeUefiDriver
:
1508 case CommonDefinition
.ModuleTypeUefiApplication
:
1509 fileBuffer
.append("EFI_STATUS\r\n");
1510 fileBuffer
.append(libInstanceList
.get(i
));
1511 fileBuffer
.append(" (\r\n");
1512 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1513 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1514 fileBuffer
.append(" );\r\n");
1520 // Add ProcessLibraryConstructorList in AutoGen.c
1522 fileBuffer
.append("VOID\r\n");
1523 fileBuffer
.append("ProcessLibraryConstructorList (\r\n");
1524 switch (CommonDefinition
.getModuleType(moduleType
)) {
1525 case CommonDefinition
.ModuleTypeBase
:
1526 fileBuffer
.append(" VOID\r\n");
1529 case CommonDefinition
.ModuleTypePeiCore
:
1530 case CommonDefinition
.ModuleTypePeim
:
1531 fileBuffer
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1533 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1536 case CommonDefinition
.ModuleTypeDxeCore
:
1537 case CommonDefinition
.ModuleTypeDxeDriver
:
1538 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1539 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1540 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1541 case CommonDefinition
.ModuleTypeUefiDriver
:
1542 case CommonDefinition
.ModuleTypeUefiApplication
:
1543 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1544 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1548 fileBuffer
.append(" )\r\n");
1549 fileBuffer
.append("{\r\n");
1551 // If no constructor function, return EFI_SUCCESS.
1553 //if (libInstanceList.size() == 0){
1554 // fileBuffer.append(" return EFI_SUCCESS;\r\n");
1556 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1558 fileBuffer
.append(" EFI_STATUS Status;\r\n");
1559 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n");
1560 fileBuffer
.append("\r\n");
1563 switch (CommonDefinition
.getModuleType(moduleType
)) {
1564 case CommonDefinition
.ModuleTypeBase
:
1565 fileBuffer
.append(" Status = ");
1566 fileBuffer
.append(libInstanceList
.get(i
));
1567 fileBuffer
.append("();\r\n");
1568 fileBuffer
.append(" VOID\r\n");
1570 case CommonDefinition
.ModuleTypePeiCore
:
1571 case CommonDefinition
.ModuleTypePeim
:
1572 fileBuffer
.append(" Status = ");
1573 fileBuffer
.append(libInstanceList
.get(i
));
1574 fileBuffer
.append(" (FfsHeader, PeiServices);\r\n");
1576 case CommonDefinition
.ModuleTypeDxeCore
:
1577 case CommonDefinition
.ModuleTypeDxeDriver
:
1578 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1579 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1580 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1581 case CommonDefinition
.ModuleTypeUefiDriver
:
1582 case CommonDefinition
.ModuleTypeUefiApplication
:
1583 fileBuffer
.append(" Status = ");
1584 fileBuffer
.append(libInstanceList
.get(i
));
1585 fileBuffer
.append(" (ImageHandle, SystemTable);\r\n");
1588 EdkLog
.log(EdkLog
.EDK_INFO
,"Autogen don't know how to deal with module type -"+ moduleType
+ " !");
1590 fileBuffer
.append(" ASSERT_EFI_ERROR (Status);\r\n");
1592 fileBuffer
.append("}\r\n");
1596 * LibDestructorToAutogenc
1598 * This function writes library destructor list to AutoGen.c. The library
1599 * destructor's parameter and return value depend on module type.
1601 * @param libInstanceList
1602 * List of library destructor name.
1606 * String buffer for AutoGen.c
1609 void LibDestructorToAutogenC(List
<String
> libInstanceList
,
1610 String moduleType
, StringBuffer fileBuffer
) throws Exception
{
1611 boolean isFirst
= true;
1612 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1613 switch (CommonDefinition
.getModuleType(moduleType
)) {
1614 case CommonDefinition
.ModuleTypeBase
:
1615 fileBuffer
.append("RETURN_STATUS\n");
1616 fileBuffer
.append(libInstanceList
.get(i
));
1617 fileBuffer
.append(" (\r\n");
1618 fileBuffer
.append(" VOID\r\n");
1619 fileBuffer
.append(" );\r\n");
1621 case CommonDefinition
.ModuleTypePeiCore
:
1622 case CommonDefinition
.ModuleTypePeim
:
1623 fileBuffer
.append("EFI_STATUS\r\n");
1624 fileBuffer
.append(libInstanceList
.get(i
));
1625 fileBuffer
.append(" (\r\n");
1627 .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1629 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1630 fileBuffer
.append(" );\r\n");
1632 case CommonDefinition
.ModuleTypeDxeCore
:
1633 case CommonDefinition
.ModuleTypeDxeDriver
:
1634 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1635 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1636 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1637 case CommonDefinition
.ModuleTypeUefiDriver
:
1638 case CommonDefinition
.ModuleTypeUefiApplication
:
1639 fileBuffer
.append("EFI_STATUS\r\n");
1640 fileBuffer
.append(libInstanceList
.get(i
));
1641 fileBuffer
.append(" (\r\n");
1642 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1643 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1644 fileBuffer
.append(" );\r\n");
1650 // Write ProcessLibraryDestructor list to autogen.c
1652 switch (CommonDefinition
.getModuleType(moduleType
)) {
1653 case CommonDefinition
.ModuleTypeBase
:
1654 case CommonDefinition
.ModuleTypePeiCore
:
1655 case CommonDefinition
.ModuleTypePeim
:
1657 case CommonDefinition
.ModuleTypeDxeCore
:
1658 case CommonDefinition
.ModuleTypeDxeDriver
:
1659 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1660 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1661 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1662 case CommonDefinition
.ModuleTypeUefiDriver
:
1663 case CommonDefinition
.ModuleTypeUefiApplication
:
1664 fileBuffer
.append("VOID\r\n");
1665 fileBuffer
.append("ProcessLibraryDestructorList (\r\n");
1666 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1667 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1668 fileBuffer
.append(" )\r\n");
1669 fileBuffer
.append("{\r\n");
1671 // If no library destructor function, return EFI_SUCCESS.
1674 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1676 fileBuffer
.append(" EFI_STATUS Status;\r\n");
1677 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n");
1678 fileBuffer
.append("\r\n");
1681 fileBuffer
.append(" Status = ");
1682 fileBuffer
.append(libInstanceList
.get(i
));
1683 fileBuffer
.append("(ImageHandle, SystemTable);\r\n");
1684 fileBuffer
.append(" ASSERT_EFI_ERROR (Status);\r\n");
1686 fileBuffer
.append("}\r\n");
1692 * ExternsDriverBindingToAutoGenC
1694 * This function is to write DRIVER_BINDING, COMPONENT_NAME,
1695 * DRIVER_CONFIGURATION, DRIVER_DIAGNOSTIC in AutoGen.c.
1698 * String buffer for AutoGen.c
1700 void ExternsDriverBindingToAutoGenC(StringBuffer fileBuffer
)
1701 throws BuildException
{
1704 // Check what <extern> contains. And the number of following elements
1705 // under <extern> should be same. 1. DRIVER_BINDING 2. COMPONENT_NAME
1706 // 3.DRIVER_CONFIGURATION 4. DRIVER_DIAGNOSTIC
1709 String
[] drvBindList
= SurfaceAreaQuery
.getDriverBindingArray();
1712 // If component name protocol,component configuration protocol,
1713 // component diagnostic protocol is not null or empty, check
1714 // if every one have the same number of the driver binding protocol.
1716 if (drvBindList
== null || drvBindList
.length
== 0) {
1720 String
[] compNamList
= SurfaceAreaQuery
.getComponentNameArray();
1721 String
[] compConfList
= SurfaceAreaQuery
.getDriverConfigArray();
1722 String
[] compDiagList
= SurfaceAreaQuery
.getDriverDiagArray();
1727 // Write driver binding protocol extern to autogen.c
1729 for (int i
= 0; i
< drvBindList
.length
; i
++) {
1730 fileBuffer
.append("extern EFI_DRIVER_BINDING_PROTOCOL ");
1731 fileBuffer
.append(drvBindList
[i
]);
1732 fileBuffer
.append(";\r\n");
1736 // Write component name protocol extern to autogen.c
1738 if (compNamList
!= null && compNamList
.length
!= 0) {
1739 if (drvBindList
.length
!= compNamList
.length
) {
1740 throw new BuildException(
1741 "Different number of Driver Binding and Component Name protocols!");
1745 for (int i
= 0; i
< compNamList
.length
; i
++) {
1746 fileBuffer
.append("extern EFI_COMPONENT_NAME_PROTOCOL ");
1747 fileBuffer
.append(compNamList
[i
]);
1748 fileBuffer
.append(";\r\n");
1753 // Write driver configration protocol extern to autogen.c
1755 if (compConfList
!= null && compConfList
.length
!= 0) {
1756 if (drvBindList
.length
!= compConfList
.length
) {
1757 throw new BuildException(
1758 "Different number of Driver Binding and Driver Configuration protocols!");
1762 for (int i
= 0; i
< compConfList
.length
; i
++) {
1763 fileBuffer
.append("extern EFI_DRIVER_CONFIGURATION_PROTOCOL ");
1764 fileBuffer
.append(compConfList
[i
]);
1765 fileBuffer
.append(";\r\n");
1770 // Write driver dignastic protocol extern to autogen.c
1772 if (compDiagList
!= null && compDiagList
.length
!= 0) {
1773 if (drvBindList
.length
!= compDiagList
.length
) {
1774 throw new BuildException(
1775 "Different number of Driver Binding and Driver Configuration protocols!");
1779 for (int i
= 0; i
< compDiagList
.length
; i
++) {
1780 fileBuffer
.append("extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL ");
1781 fileBuffer
.append(compDiagList
[i
]);
1782 fileBuffer
.append(";\r\n");
1787 // Write driver module protocol bitmask.
1790 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverModelProtocolBitmask = ");
1791 fileBuffer
.append(Integer
.toString(BitMask
));
1792 fileBuffer
.append(";\r\n");
1795 // Write driver module protocol list entry
1798 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverModelProtocolListEntries = ");
1800 fileBuffer
.append(Integer
.toString(drvBindList
.length
));
1801 fileBuffer
.append(";\r\n");
1804 // Write drive module protocol list to autogen.c
1807 .append("GLOBAL_REMOVE_IF_UNREFERENCED const EFI_DRIVER_MODEL_PROTOCOL_LIST _gDriverModelProtocolList[] = {");
1808 for (int i
= 0; i
< drvBindList
.length
; i
++) {
1810 fileBuffer
.append(",");
1812 fileBuffer
.append("\r\n {\r\n");
1813 fileBuffer
.append(" &");
1814 fileBuffer
.append(drvBindList
[i
]);
1815 fileBuffer
.append(", \r\n");
1817 if (compNamList
!= null) {
1818 fileBuffer
.append(" &");
1819 fileBuffer
.append(compNamList
[i
]);
1820 fileBuffer
.append(", \r\n");
1822 fileBuffer
.append(" NULL, \r\n");
1825 if (compConfList
!= null) {
1826 fileBuffer
.append(" &");
1827 fileBuffer
.append(compConfList
[i
]);
1828 fileBuffer
.append(", \r\n");
1830 fileBuffer
.append(" NULL, \r\n");
1833 if (compDiagList
!= null) {
1834 fileBuffer
.append(" &");
1835 fileBuffer
.append(compDiagList
[i
]);
1836 fileBuffer
.append(", \r\n");
1838 fileBuffer
.append(" NULL, \r\n");
1840 fileBuffer
.append(" }");
1842 fileBuffer
.append("\r\n};\r\n");
1846 * ExternCallBackToAutoGenC
1848 * This function adds <SetVirtualAddressMapCallBack> and
1849 * <ExitBootServicesCallBack> infomation to AutoGen.c
1852 * String buffer for AutoGen.c
1853 * @throws BuildException
1855 void ExternCallBackToAutoGenC(StringBuffer fileBuffer
)
1856 throws BuildException
{
1857 String
[] setVirtualList
= SurfaceAreaQuery
1858 .getSetVirtualAddressMapCallBackArray();
1859 String
[] exitBootList
= SurfaceAreaQuery
1860 .getExitBootServicesCallBackArray();
1861 String moduleType
= SurfaceAreaQuery
.getModuleType();
1862 boolean UefiOrDxeModule
= false;
1866 switch (CommonDefinition
.getModuleType(moduleType
)) {
1867 case CommonDefinition
.ModuleTypeDxeDriver
:
1868 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1869 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1870 case CommonDefinition
.ModuleTypeUefiDriver
:
1871 case CommonDefinition
.ModuleTypeUefiApplication
:
1873 // Entry point lib for these module types needs to know the count
1876 UefiOrDxeModule
= true;
1878 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverSetVirtualAddressMapEventCount = ");
1881 // If the list is not valid or has no entries set count to zero else
1882 // set count to the number of valid entries
1885 if (setVirtualList
!= null) {
1886 for (i
= 0; i
< setVirtualList
.length
; i
++) {
1887 if (setVirtualList
[i
].equalsIgnoreCase("")) {
1894 fileBuffer
.append(Integer
.toString(Count
));
1895 fileBuffer
.append(";\r\n\r\n");
1901 if (setVirtualList
== null) {
1902 if (UefiOrDxeModule
) {
1904 // No data so make a NULL list
1907 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {\r\n");
1908 fileBuffer
.append(" NULL\r\n");
1909 fileBuffer
.append("};\r\n\r\n");
1913 // Write SetVirtualAddressMap function definition.
1915 for (i
= 0; i
< setVirtualList
.length
; i
++) {
1916 if (setVirtualList
[i
].equalsIgnoreCase("")) {
1919 fileBuffer
.append("VOID\r\n");
1920 fileBuffer
.append("EFIAPI\r\n");
1921 fileBuffer
.append(setVirtualList
[i
]);
1922 fileBuffer
.append(" (\r\n");
1923 fileBuffer
.append(" IN EFI_EVENT Event,\r\n");
1924 fileBuffer
.append(" IN VOID *Context\r\n");
1925 fileBuffer
.append(" );\r\n\r\n");
1929 // Write SetVirtualAddressMap entry point array.
1932 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {");
1933 for (i
= 0; i
< setVirtualList
.length
; i
++) {
1934 if (setVirtualList
[i
].equalsIgnoreCase("")) {
1939 fileBuffer
.append("\r\n ");
1941 fileBuffer
.append(",\r\n ");
1944 fileBuffer
.append(setVirtualList
[i
]);
1947 // If module is not DXE_DRIVER, DXE_RUNTIME_DIRVER, UEFI_DRIVER
1948 // UEFI_APPLICATION and DXE_SAL_DRIVER add the NULL at the end of
1949 // _gDriverSetVirtualAddressMapEvent list.
1951 if (!UefiOrDxeModule
) {
1952 fileBuffer
.append(",\r\n NULL");
1954 fileBuffer
.append("\r\n};\r\n\r\n");
1957 if (UefiOrDxeModule
) {
1959 // Entry point lib for these module types needs to know the count.
1962 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverExitBootServicesEventCount = ");
1965 // If the list is not valid or has no entries set count to zero else
1966 // set count to the number of valid entries.
1969 if (exitBootList
!= null) {
1970 if (setVirtualList
!= null) {
1971 for (i
= 0; i
< exitBootList
.length
; i
++) {
1972 if (exitBootList
[i
].equalsIgnoreCase("")) {
1979 fileBuffer
.append(Integer
.toString(Count
));
1980 fileBuffer
.append(";\r\n\r\n");
1983 if (exitBootList
== null) {
1984 if (UefiOrDxeModule
) {
1986 // No data so make a NULL list.
1989 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {\r\n");
1990 fileBuffer
.append(" NULL\r\n");
1991 fileBuffer
.append("};\r\n\r\n");
1995 // Write DriverExitBootServices function definition.
1997 for (i
= 0; i
< exitBootList
.length
; i
++) {
1998 if (exitBootList
[i
].equalsIgnoreCase("")) {
2002 fileBuffer
.append("VOID\r\n");
2003 fileBuffer
.append("EFIAPI\r\n");
2004 fileBuffer
.append(exitBootList
[i
]);
2005 fileBuffer
.append(" (\r\n");
2006 fileBuffer
.append(" IN EFI_EVENT Event,\r\n");
2007 fileBuffer
.append(" IN VOID *Context\r\n");
2008 fileBuffer
.append(" );\r\n\r\n");
2012 // Write DriverExitBootServices entry point array.
2015 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {");
2016 for (i
= 0; i
< exitBootList
.length
; i
++) {
2017 if (exitBootList
[i
].equalsIgnoreCase("")) {
2022 fileBuffer
.append("\r\n ");
2024 fileBuffer
.append(",\r\n ");
2026 fileBuffer
.append(exitBootList
[i
]);
2028 if (!UefiOrDxeModule
) {
2029 fileBuffer
.append(",\r\n NULL");
2031 fileBuffer
.append("\r\n};\r\n\r\n");