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
.GuidsDocument
;
24 import org
.tianocore
.LibraryClassDocument
.LibraryClass
;
25 import org
.tianocore
.PPIsDocument
;
26 import org
.tianocore
.ProtocolsDocument
;
27 import org
.tianocore
.build
.pcd
.action
.PCDAutoGenAction
;
29 import org
.apache
.tools
.ant
.BuildException
;
30 import org
.apache
.xmlbeans
.XmlObject
;
33 import java
.io
.FileReader
;
34 import java
.io
.FileWriter
;
35 import java
.util
.ArrayList
;
36 import java
.util
.List
;
40 This class is to generate Autogen.h and Autogen.c according to module surface
41 area or library surface area.
43 public class AutoGen
{
45 /// The output path of Autogen.h and Autogen.c
47 private String outputPath
;
50 /// The base name of module or library.
52 private String baseName
;
55 /// The build architecture
60 /// PcdAutogen instance which is used to manage how to generate the PCD
63 private PCDAutoGenAction myPcdAutogen
;
66 /// The protocl list which records in module or library surface area and
67 /// it's dependence on library instance surface area.
69 private List
<String
> mProtocolList
= new ArrayList
<String
>();
72 /// The Ppi list which recorded in module or library surface area and its
73 /// dependency on library instance surface area.
75 private List
<String
> mPpiList
= new ArrayList
<String
>();
78 /// The Guid list which recoreded in module or library surface are and it's
79 /// dependence on library instance surface area.
81 private List
<GuidsDocument
.Guids
.GuidEntry
> mGuidList
= new ArrayList
<GuidsDocument
.Guids
.GuidEntry
>();
86 This function mainly initialize some member variable.
88 @param outputPath Output path of AutoGen file.
89 @param baseName Module base name.
90 @param arch Target architecture.
92 public AutoGen(String outputPath
, String baseName
, String arch
) {
93 this.outputPath
= outputPath
;
94 this.baseName
= baseName
;
102 This function save the content in stringBuffer to file.
104 @param fileName The name of file.
105 @param fileBuffer The content of AutoGen file in buffer.
106 @return "true" successful, "false" failed.
108 private boolean saveFile(String fileName
, StringBuffer fileBuffer
) {
110 File autoGenH
= new File(fileName
);
113 // if the file exists, compare their content
115 if (autoGenH
.exists()) {
116 FileReader fIn
= new FileReader(autoGenH
);
117 char[] oldFileBuffer
= new char[(int) autoGenH
.length()];
118 fIn
.read(oldFileBuffer
, 0, (int) autoGenH
.length());
122 // if we got the same file, don't re-generate it to prevent
123 // sources depending on it from re-building
125 if (fileBuffer
.toString().compareTo(new String(oldFileBuffer
)) == 0) {
129 FileWriter fOut
= new FileWriter(autoGenH
);
130 fOut
.write(fileBuffer
.toString());
132 } catch (Exception e
) {
141 This function call libGenAutoGen or moduleGenAutogen function, which
142 dependence on generate library autogen or module autogen.
144 @throws BuildException Failed to creat AutoGen.c & AutoGen.h.
146 public void genAutogen() throws BuildException
{
149 // If outputPath do not exist, create it.
151 File path
= new File(outputPath
);
155 // Check current is library or not, then call the corresponding
158 if (SurfaceAreaQuery
.getComponentType().equalsIgnoreCase(
159 CommonDefinition
.LibraryStr
)) {
165 } catch (Exception e
) {
166 throw new BuildException(
167 "Failed to create AutoGen.c & AutoGen.h!\n"
173 moduleGenAutogen function
175 This function generates AutoGen.c & AutoGen.h for module.
177 @throws BuildException Faile to create module AutoGen.c & AutoGen.h.
179 void moduleGenAutogen() throws BuildException
{
184 } catch (Exception e
) {
185 throw new BuildException(
186 "Faile to create module AutoGen.c & AutoGen.h!\n"
192 libGenAutogen function
194 This function generates AutoGen.c & AutoGen.h for library.
196 @throws BuildException
197 Faile to create library AutoGen.c & AutoGen.h
199 void libGenAutogen() throws BuildException
{
203 } catch (Exception e
) {
204 throw new BuildException(
205 "Faile to create library AutoGen.c & AutoGen.h!\n"
213 This function generates AutoGen.h for module.
215 @throws BuildException
216 Failed to generate AutoGen.h.
218 void moduleGenAutogenH() throws BuildException
{
220 List
<String
> libClassIncludeH
;
222 List
<String
> headerFileList
;
224 StringBuffer fileBuffer
= new StringBuffer(8192);
227 // Write Autogen.h header notation
229 fileBuffer
.append(CommonDefinition
.autogenHNotation
);
232 // Add #ifndef ${BaseName}_AUTOGENH
233 // #def ${BseeName}_AUTOGENH
235 fileBuffer
.append("#ifndef " + this.baseName
.toUpperCase() + "_AUTOGENH\r\n");
236 fileBuffer
.append("#define " + this.baseName
.toUpperCase() + "_AUTOGENH\r\n\r\n");
239 // Write the specification version and release version at the begine
240 // of autogen.h file.
241 // Note: the specification version and release version should
242 // be got from module surface area instead of hard code by it's moduleType.
244 moduleType
= SurfaceAreaQuery
.getModuleType();
245 switch (CommonDefinition
.getModuleType(moduleType
)) {
246 case CommonDefinition
.ModuleTypeDxeCore
:
247 case CommonDefinition
.ModuleTypeDxeDriver
:
248 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
249 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
250 case CommonDefinition
.ModuleTypeDxeSalDriver
:
251 case CommonDefinition
.ModuleTypeUefiDriver
:
252 case CommonDefinition
.ModuleTypeUefiApplication
:
253 fileBuffer
.append(CommonDefinition
.autoGenHLine1
);
256 fileBuffer
.append(CommonDefinition
.autoGenHVersionDefault
);
259 switch (CommonDefinition
.getModuleType(moduleType
)) {
260 case CommonDefinition
.ModuleTypeUefiDriver
:
261 case CommonDefinition
.ModuleTypeUefiApplication
:
262 fileBuffer
.append(CommonDefinition
.autoGenHReleaseDefault
);
265 fileBuffer
.append(CommonDefinition
.autoGenHLine2
);
270 // Add "extern int __make_me_compile_correctly;" at begin of
273 fileBuffer
.append(CommonDefinition
.autoGenHbegin
);
276 // Write consumed package's mdouleInfo related .h file to autogen.h
278 List
<String
> consumedPkgList
= SurfaceAreaQuery
279 .getIncludePackageName(this.arch
);
280 if (consumedPkgList
!= null) {
281 headerFileList
= IncludesToAutogenH(consumedPkgList
, moduleType
);
282 for (int i
= 0; i
< headerFileList
.size(); i
++) {
283 fileBuffer
.append(headerFileList
.get(i
));
288 // Write library class's related *.h file to autogen.h.
290 LibraryClass
[] libClassList
= SurfaceAreaQuery
291 .getLibraryClassArray(CommonDefinition
.AlwaysConsumed
);
292 if (libClassList
!= null) {
293 libClassIncludeH
= LibraryClassToAutogenH(libClassList
);
294 for (int i
= 0; i
< libClassIncludeH
.size(); i
++) {
295 fileBuffer
.append(libClassIncludeH
.get(i
));
299 libClassList
= SurfaceAreaQuery
300 .getLibraryClassArray(CommonDefinition
.AlwaysProduced
);
301 if (libClassList
!= null) {
302 libClassIncludeH
= LibraryClassToAutogenH(libClassList
);
303 for (int i
= 0; i
< libClassIncludeH
.size(); i
++) {
304 fileBuffer
.append(libClassIncludeH
.get(i
));
307 fileBuffer
.append("\r\n");
310 // Write PCD autogen information to AutoGen.h.
312 if (this.myPcdAutogen
!= null) {
313 fileBuffer
.append(this.myPcdAutogen
.OutputH());
317 // Append the #endif at AutoGen.h
319 fileBuffer
.append("#endif\r\n");
322 // Save string buffer content in AutoGen.h.
324 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.h", fileBuffer
)) {
325 throw new BuildException("Failed to generate AutoGen.h !!!");
332 This function generates AutoGen.c for module.
334 @throws BuildException
335 Failed to generate AutoGen.c.
337 void moduleGenAutogenC() throws BuildException
{
339 StringBuffer fileBuffer
= new StringBuffer(8192);
341 // Write Autogen.c header notation
343 fileBuffer
.append(CommonDefinition
.autogenCNotation
);
346 // Write #include <AutoGen.h> at beginning of AutoGen.c
348 fileBuffer
.append(CommonDefinition
.includeAutogenH
);
351 // Write DriverBinding/ComponentName/DriverConfiguration/DriverDialog
354 ExternsDriverBindingToAutoGenC(fileBuffer
);
357 // Write DriverExitBootServicesEvent/DriverSetVirtualAddressMapEvent
360 ExternCallBackToAutoGenC(fileBuffer
);
363 // Write EntryPoint to autgoGen.c
365 String
[] entryPointList
= SurfaceAreaQuery
.getModuleEntryPointArray();
366 if (entryPointList
!= null) {
367 EntryPointToAutoGen(entryPointList
, fileBuffer
);
371 // Write Guid to autogen.c
373 String guid
= SurfaceAreaQuery
.getModuleGuid();
375 .append("GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiCallerIdGuid = {");
377 throw new BuildException("Guid value must set!\n");
381 // Formate Guid as ANSI c form.Example:
382 // {0xd2b2b828, 0x826, 0x48a7,{0xb3, 0xdf, 0x98, 0x3c, 0x0, 0x60, 0x24, 0xf0}}
384 fileBuffer
.append(Spd
.formatGuidName(guid
));
385 fileBuffer
.append("};\r\n");
388 // Generate library instance consumed protocol, guid, ppi, pcd list.
389 // Save those to this.protocolList, this.ppiList, this.pcdList,
390 // this.guidList. Write Consumed library constructor and desconstuct to
393 LibInstanceToAutogenC(fileBuffer
);
396 // Write consumed ppi, guid, protocol to autogen.c
398 ProtocolGuidToAutogenC(fileBuffer
);
399 PpiGuidToAutogenC(fileBuffer
);
400 GuidGuidToAutogenC(fileBuffer
);
403 // Call pcd autogen. PCDAutoGenAction tool only need module name and
404 // isPcdEmulatedDriver as parameter. Library inherits PCD and module's
405 // PCD information has been collected in FPDParser task by
407 // Note : when PCD image tool ready,
408 // isPCDEmulatedDriver parameter will be removed.
411 this.myPcdAutogen
= new PCDAutoGenAction(baseName
,
412 baseName
.equalsIgnoreCase("PcdEmulatorPeim"));
413 this.myPcdAutogen
.execute();
414 } catch (Exception e
) {
415 throw new BuildException("PCD Autogen failed:" + e
.getMessage());
418 if (this.myPcdAutogen
!= null) {
419 fileBuffer
.append(this.myPcdAutogen
.OutputC());
422 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.c", fileBuffer
)) {
423 throw new BuildException("Failed to generate AutoGen.c !!!");
431 This function generates AutoGen.h for library.
433 @throws BuildException
434 Failed to generate AutoGen.c.
436 void libGenAutogenH() throws BuildException
{
438 List
<String
> libClassIncludeH
;
440 List
<String
> headerFileList
;
441 StringBuffer fileBuffer
= new StringBuffer(10240);
444 // Write Autogen.h header notation
446 fileBuffer
.append(CommonDefinition
.autogenHNotation
);
449 // Add #ifndef ${BaseName}_AUTOGENH
450 // #def ${BseeName}_AUTOGENH
452 fileBuffer
.append("#ifndef " + this.baseName
.toUpperCase() + "_AUTOGENH\r\n");
453 fileBuffer
.append("#define " + this.baseName
.toUpperCase() + "_AUTOGENH\r\n\r\n");
456 // Write EFI_SPECIFICATION_VERSION and EDK_RELEASE_VERSION
457 // to autogen.h file.
458 // Note: the specification version and release version should
459 // be get from module surface area instead of hard code.
461 fileBuffer
.append(CommonDefinition
.autoGenHbegin
);
462 fileBuffer
.append(CommonDefinition
.autoGenHLine1
);
463 fileBuffer
.append(CommonDefinition
.autoGenHLine2
);
466 // Write consumed package's mdouleInfo related *.h file to autogen.h.
468 moduleType
= SurfaceAreaQuery
.getModuleType();
469 List
<String
> cosumedPkglist
= SurfaceAreaQuery
470 .getIncludePackageName(this.arch
);
471 headerFileList
= IncludesToAutogenH(cosumedPkglist
, moduleType
);
472 for (int i
= 0; i
< headerFileList
.size(); i
++) {
473 fileBuffer
.append(headerFileList
.get(i
));
477 // Write library class's related *.h file to autogen.h
479 LibraryClass
[] libClassList
= SurfaceAreaQuery
480 .getLibraryClassArray(CommonDefinition
.AlwaysConsumed
);
481 if (libClassList
!= null) {
482 libClassIncludeH
= LibraryClassToAutogenH(libClassList
);
483 for (int i
= 0; i
< libClassIncludeH
.size(); i
++) {
484 fileBuffer
.append(libClassIncludeH
.get(i
));
488 libClassList
= SurfaceAreaQuery
489 .getLibraryClassArray(CommonDefinition
.AlwaysProduced
);
490 if (libClassList
!= null) {
491 libClassIncludeH
= LibraryClassToAutogenH(libClassList
);
492 for (int i
= 0; i
< libClassIncludeH
.size(); i
++) {
493 fileBuffer
.append(libClassIncludeH
.get(i
));
496 fileBuffer
.append("\r\n");
499 // Write PCD information to library AutoGen.h.
501 if (this.myPcdAutogen
!= null) {
502 fileBuffer
.append(this.myPcdAutogen
.OutputH());
506 // Append the #endif at AutoGen.h
508 fileBuffer
.append("#endif\r\n");
511 // Save content of string buffer to AutoGen.h file.
513 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.h", fileBuffer
)) {
514 throw new BuildException("Failed to generate AutoGen.h !!!");
521 This function generates AutoGen.h for library.
523 @throws BuildException
524 Failed to generate AutoGen.c.
526 void libGenAutogenC() throws BuildException
{
527 StringBuffer fileBuffer
= new StringBuffer(10240);
530 // Write Autogen.c header notation
532 fileBuffer
.append(CommonDefinition
.autogenCNotation
);
534 fileBuffer
.append(CommonDefinition
.autoGenCLine1
);
535 fileBuffer
.append("\r\n");
538 // Call pcd autogen. PCDAutoGenAction tool only need module name and
539 // isPcdEmulatedDriver as parameter. Library inherit PCD and module's
540 // PCD information has been collected in FPDParser task by
542 // Note : when PCD image tool ready,
543 // isPCDEmulatedDriver parameter will be removed.
546 this.myPcdAutogen
= new PCDAutoGenAction(baseName
, baseName
547 .equalsIgnoreCase("PcdEmulatorPeim"));
548 this.myPcdAutogen
.execute();
549 } catch (Exception e
) {
550 throw new BuildException(e
.getMessage());
553 if (this.myPcdAutogen
!= null) {
554 fileBuffer
.append(this.myPcdAutogen
.OutputC());
557 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.c", fileBuffer
)) {
558 throw new BuildException("Failed to generate AutoGen.c !!!");
563 LibraryClassToAutogenH
565 This function returns *.h files declared by library classes which are
566 consumed or produced by current build module or library.
568 @param libClassList List of library class which consumed or produce
569 by current build module or library.
570 @return includeStrList List of *.h file.
572 List
<String
> LibraryClassToAutogenH(LibraryClass
[] libClassList
) {
573 List
<String
> includStrList
= new ArrayList
<String
>();
578 // Get include file from GlobalData's SPDTable according to
579 // library class name.
581 for (int i
= 0; i
< libClassList
.length
; i
++) {
582 includerName
= GlobalData
.getLibClassIncluder(libClassList
[i
]
584 if (includerName
!= null) {
585 str
= CommonDefinition
.include
+ " " + "<";
586 str
= str
+ includerName
+ ">\r\n";
587 includStrList
.add(str
);
591 return includStrList
;
597 This function add include file in AutoGen.h file.
598 @param packageNameList List of module depended package.
599 @param moduleType Module type.
602 List
<String
> IncludesToAutogenH(List
<String
> packageNameList
,
605 List
<String
> includeStrList
= new ArrayList
<String
>();
606 String packageName
= "";
607 String includeStr
= "";
610 // Get include file from moduleInfo file
612 for (int i
= 0; i
< packageNameList
.size(); i
++) {
613 packageName
= packageNameList
.get(i
);
614 includeStr
= GlobalData
.getModuleInfoByPackageName(packageName
,
616 includeStrList
.add(includeStr
);
618 return includeStrList
;
624 This function convert <ModuleEntryPoint> & <ModuleUnloadImage> information
627 @param entryPointList List of entry point.
628 @param fileBuffer String buffer fo AutoGen.c.
631 void EntryPointToAutoGen(String
[] entryPointList
, StringBuffer fileBuffer
)
632 throws BuildException
{
634 String typeStr
= SurfaceAreaQuery
.getModuleType();
637 // The parameters and return value of entryPoint is difference
638 // for difference module type.
640 switch (CommonDefinition
.getModuleType(typeStr
)) {
642 case CommonDefinition
.ModuleTypePeiCore
:
643 if (entryPointList
.length
!= 1 || entryPointList
[0].equals("")) {
644 throw new BuildException(
645 "Module type = 'PEI_CORE', only have one module entry point!");
647 fileBuffer
.append("EFI_STATUS\r\n");
648 fileBuffer
.append("EFIAPI\r\n");
649 fileBuffer
.append(entryPointList
[0]);
650 fileBuffer
.append(" (\r\n");
652 .append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n");
654 .append(" IN VOID *OldCoreData\r\n");
655 fileBuffer
.append(" );\r\n\r\n");
657 fileBuffer
.append("EFI_STATUS\r\n");
658 fileBuffer
.append("EFIAPI\r\n");
659 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
661 .append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n");
663 .append(" IN VOID *OldCoreData\r\n");
664 fileBuffer
.append(" )\r\n\r\n");
665 fileBuffer
.append("{\r\n");
666 fileBuffer
.append(" return ");
667 fileBuffer
.append(entryPointList
[0]);
668 fileBuffer
.append(" (PeiStartupDescriptor, OldCoreData);\r\n");
669 fileBuffer
.append("}\r\n\r\n");
673 case CommonDefinition
.ModuleTypeDxeCore
:
674 fileBuffer
.append("const UINT32 _gUefiDriverRevision = 0;\r\n");
675 if (entryPointList
.length
!= 1 || entryPointList
[0].equals("")) {
676 throw new BuildException(
677 "Module type = 'DXE_CORE', only have one module entry point!");
680 fileBuffer
.append("VOID\r\n");
681 fileBuffer
.append("EFIAPI\r\n");
682 fileBuffer
.append(entryPointList
[0]);
683 fileBuffer
.append(" (\n");
684 fileBuffer
.append(" IN VOID *HobStart\r\n");
685 fileBuffer
.append(" );\r\n\r\n");
687 fileBuffer
.append("VOID\r\n");
688 fileBuffer
.append("EFIAPI\r\n");
689 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
690 fileBuffer
.append(" IN VOID *HobStart\r\n");
691 fileBuffer
.append(" )\r\n\r\n");
692 fileBuffer
.append("{\r\n");
693 fileBuffer
.append(" ");
694 fileBuffer
.append(entryPointList
[0]);
695 fileBuffer
.append(" (HobStart);\r\n");
696 fileBuffer
.append("}\r\n\r\n");
700 case CommonDefinition
.ModuleTypePeim
:
701 int entryPointCount
= 0;
703 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = 0;\r\n");
704 for (int i
= 0; i
< entryPointList
.length
; i
++) {
705 if (!entryPointList
[i
].equals("")) {
706 fileBuffer
.append("EFI_STATUS\r\n");
707 fileBuffer
.append("EFIAPI\r\n");
708 fileBuffer
.append(entryPointList
[i
]);
709 fileBuffer
.append(" (\r\n");
711 .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
713 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
714 fileBuffer
.append(" );\r\n");
721 fileBuffer
.append("EFI_STATUS\r\n");
722 fileBuffer
.append("EFIAPI\r\n");
723 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
724 fileBuffer
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
725 fileBuffer
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
726 fileBuffer
.append(" )\r\n\r\n");
727 fileBuffer
.append("{\r\n");
729 if (entryPointCount
== 0) {
730 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
731 } else if (entryPointCount
== 1) {
732 fileBuffer
.append(" return ");
733 fileBuffer
.append(entryPointList
[0]);
734 fileBuffer
.append(" (FfsHeader, PeiServices);\r\n");
736 fileBuffer
.append(" EFI_STATUS Status;\r\n");
737 fileBuffer
.append(" EFI_STATUS CombinedStatus;\r\n\r\n");
738 fileBuffer
.append(" CombinedStatus = EFI_LOAD_ERROR;\r\n\r\n");
739 for (int i
= 0; i
< entryPointList
.length
; i
++) {
740 if (!entryPointList
[i
].equals("")) {
741 fileBuffer
.append(" Status = ");
742 fileBuffer
.append(entryPointList
[i
]);
743 fileBuffer
.append(" (FfsHeader, PeiServices)\r\n");
745 .append(" if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {\r\n");
746 fileBuffer
.append(" CombinedStatus = Status;\r\n");
747 fileBuffer
.append(" }\r\n\r\n");
752 fileBuffer
.append(" return CombinedStatus;\r\n");
754 fileBuffer
.append("}\r\n\r\n");
757 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
759 for (int i
= 0; i
< entryPointList
.length
; i
++) {
760 if (!entryPointList
[i
].equals("")) {
761 fileBuffer
.append("EFI_STATUS\r\n");
762 fileBuffer
.append("EFIAPI\r\n");
763 fileBuffer
.append(entryPointList
[i
]);
764 fileBuffer
.append(" (\r\n");
765 fileBuffer
.append(" EFI_HANDLE ImageHandle,\r\n");
766 fileBuffer
.append(" EFI_SYSTEM_TABLE *SystemTable\r\n");
767 fileBuffer
.append(" );\r\n");
774 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
775 fileBuffer
.append(Integer
.toString(entryPointCount
));
776 fileBuffer
.append(";\r\n");
778 .append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");
780 .append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n\r\n");
782 fileBuffer
.append("EFI_STATUS\r\n");
783 fileBuffer
.append("EFIAPI\r\n");
784 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
785 fileBuffer
.append(" EFI_HANDLE ImageHandle,\r\n");
786 fileBuffer
.append(" EFI_SYSTEM_TABLE *SystemTable\r\n");
787 fileBuffer
.append(" )\r\n\r\n");
788 fileBuffer
.append("{\r\n");
790 for (int i
= 0; i
< entryPointList
.length
; i
++) {
791 if (!entryPointList
[i
].equals("")) {
793 .append(" if (SetJump (&mJumpContext) == 0) {\r\n");
794 fileBuffer
.append(" ExitDriver (");
795 fileBuffer
.append(entryPointList
[i
]);
796 fileBuffer
.append(" (ImageHandle, SystemTable));\r\n");
797 fileBuffer
.append(" ASSERT (FALSE);\r\n");
798 fileBuffer
.append(" }\r\n");
803 fileBuffer
.append(" return mDriverEntryPointStatus;\r\n");
804 fileBuffer
.append("}\r\n\r\n");
806 fileBuffer
.append("VOID\r\n");
807 fileBuffer
.append("EFIAPI\r\n");
808 fileBuffer
.append("ExitDriver (\r\n");
809 fileBuffer
.append(" IN EFI_STATUS Status\n");
810 fileBuffer
.append(" )\r\n\r\n");
811 fileBuffer
.append("{\r\n");
813 .append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");
814 fileBuffer
.append(" mDriverEntryPointStatus = Status;\r\n");
815 fileBuffer
.append(" }\r\n");
816 fileBuffer
.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");
817 fileBuffer
.append(" ASSERT (FALSE);\r\n");
818 fileBuffer
.append("}\r\n\r\n");
821 // Add "ModuleUnloadImage" for DxeSmmDriver module type;
823 entryPointList
= SurfaceAreaQuery
.getModuleUnloadImageArray();
825 if (entryPointList
!= null) {
826 for (int i
= 0; i
< entryPointList
.length
; i
++) {
827 if (!entryPointList
[i
].equals("")) {
828 fileBuffer
.append("EFI_STATUS\r\n");
829 fileBuffer
.append("EFIAPI\r\n");
830 fileBuffer
.append(entryPointList
[i
]);
831 fileBuffer
.append(" (\r\n");
833 .append(" EFI_HANDLE ImageHandle\r\n");
834 fileBuffer
.append(" );\r\n");
843 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");
844 fileBuffer
.append(Integer
.toString(entryPointCount
));
845 fileBuffer
.append(";\r\n\r\n");
847 if (entryPointList
!= null) {
848 for (int i
= 0; i
< entryPointList
.length
; i
++) {
849 if (!entryPointList
[i
].equals("")) {
850 fileBuffer
.append("EFI_STATUS\r\n");
851 fileBuffer
.append("EFIAPI\r\n");
852 fileBuffer
.append(entryPointList
[i
]);
853 fileBuffer
.append(" (\r\n");
855 .append(" EFI_HANDLE ImageHandle\r\n");
856 fileBuffer
.append(" );\r\n");
863 fileBuffer
.append("EFI_STATUS\r\n");
864 fileBuffer
.append("EFIAPI\r\n");
865 fileBuffer
.append("ProcessModuleUnloadList (\r\n");
866 fileBuffer
.append(" EFI_HANDLE ImageHandle\r\n");
867 fileBuffer
.append(" )\r\n");
868 fileBuffer
.append("{\r\n");
870 if (entryPointCount
== 0) {
871 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
872 } else if (entryPointCount
== 1) {
873 fileBuffer
.append(" return ");
874 fileBuffer
.append(entryPointList
[0]);
875 fileBuffer
.append("(ImageHandle);\r\n");
877 fileBuffer
.append(" EFI_STATUS Status;\r\n\r\n");
878 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n\r\n");
879 for (int i
= 0; i
< entryPointList
.length
; i
++) {
880 if (!entryPointList
[i
].equals("")) {
881 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
882 fileBuffer
.append(" ");
883 fileBuffer
.append(entryPointList
[i
]);
884 fileBuffer
.append("(ImageHandle);\r\n");
885 fileBuffer
.append(" } else {\r\n");
886 fileBuffer
.append(" Status = ");
887 fileBuffer
.append(entryPointList
[i
]);
888 fileBuffer
.append("(ImageHandle);\r\n");
889 fileBuffer
.append(" }\r\n");
894 fileBuffer
.append(" return Status;\r\n");
896 fileBuffer
.append("}\r\n\r\n");
899 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
900 case CommonDefinition
.ModuleTypeDxeDriver
:
901 case CommonDefinition
.ModuleTypeDxeSalDriver
:
902 case CommonDefinition
.ModuleTypeUefiDriver
:
903 case CommonDefinition
.ModuleTypeUefiApplication
:
905 fileBuffer
.append("const UINT32 _gUefiDriverRevision = 0;\r\n");
906 for (int i
= 0; i
< entryPointList
.length
; i
++) {
907 if (!entryPointList
[i
].equals("")) {
908 fileBuffer
.append("EFI_STATUS\r\n");
909 fileBuffer
.append("EFIAPI\r\n");
910 fileBuffer
.append(entryPointList
[i
]);
911 fileBuffer
.append(" (\r\n");
912 fileBuffer
.append(" EFI_HANDLE ImageHandle,\r\n");
913 fileBuffer
.append(" EFI_SYSTEM_TABLE *SystemTable\r\n");
914 fileBuffer
.append(" );\r\n");
922 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
923 fileBuffer
.append(Integer
.toString(entryPointCount
));
924 fileBuffer
.append(";\r\n");
925 if (entryPointCount
> 1) {
927 .append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");
929 .append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n");
931 fileBuffer
.append("\n");
933 fileBuffer
.append("EFI_STATUS\r\n");
934 fileBuffer
.append("EFIAPI\r\n");
935 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
936 fileBuffer
.append(" EFI_HANDLE ImageHandle,\r\n");
937 fileBuffer
.append(" EFI_SYSTEM_TABLE *SystemTable\r\n");
938 fileBuffer
.append(" )\r\n\r\n");
939 fileBuffer
.append("{\r\n");
941 if (entryPointCount
== 0) {
942 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
943 } else if (entryPointCount
== 1) {
944 fileBuffer
.append(" return (");
945 fileBuffer
.append(entryPointList
[0]);
946 fileBuffer
.append(" (ImageHandle, SystemTable));\r\n");
948 for (int i
= 0; i
< entryPointList
.length
; i
++) {
949 if (!entryPointList
[i
].equals("")) {
951 .append(" if (SetJump (&mJumpContext) == 0) {\r\n");
952 fileBuffer
.append(" ExitDriver (");
953 fileBuffer
.append(entryPointList
[i
]);
954 fileBuffer
.append(" (ImageHandle, SystemTable));\r\n");
955 fileBuffer
.append(" ASSERT (FALSE);\r\n");
956 fileBuffer
.append(" }\r\n");
961 fileBuffer
.append(" return mDriverEntryPointStatus;\r\n");
963 fileBuffer
.append("}\r\n\r\n");
965 fileBuffer
.append("VOID\n");
966 fileBuffer
.append("EFIAPI\n");
967 fileBuffer
.append("ExitDriver (\r\n");
968 fileBuffer
.append(" IN EFI_STATUS Status\n");
969 fileBuffer
.append(" )\r\n\r\n");
970 fileBuffer
.append("{\r\n");
971 if (entryPointCount
<= 1) {
972 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
974 .append(" ProcessLibraryDestructorList (gImageHandle, gST);\r\n");
975 fileBuffer
.append(" }\r\n");
977 .append(" gBS->Exit (gImageHandle, Status, 0, NULL);\r\n");
980 .append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");
981 fileBuffer
.append(" mDriverEntryPointStatus = Status;\r\n");
982 fileBuffer
.append(" }\r\n");
983 fileBuffer
.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");
984 fileBuffer
.append(" ASSERT (FALSE);\r\n");
986 fileBuffer
.append("}\r\n\r\n");
989 // Add ModuleUnloadImage for DxeDriver and UefiDriver module type.
991 entryPointList
= SurfaceAreaQuery
.getModuleUnloadImageArray();
993 if (entryPointList
!= null) {
994 for (int i
= 0; i
< entryPointList
.length
; i
++) {
995 if (!entryPointList
[i
].equals("")) {
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(" EFI_HANDLE ImageHandle\r\n");
1002 fileBuffer
.append(" );\r\n");
1011 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");
1012 fileBuffer
.append(Integer
.toString(entryPointCount
));
1013 fileBuffer
.append(";\r\n\r\n");
1015 if (entryPointList
!= null) {
1016 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1017 if (!entryPointList
[i
].equals("")) {
1018 fileBuffer
.append("EFI_STATUS\r\n");
1019 fileBuffer
.append("EFIAPI\r\n");
1020 fileBuffer
.append(entryPointList
[i
]);
1021 fileBuffer
.append(" (\r\n");
1023 .append(" EFI_HANDLE ImageHandle\r\n");
1024 fileBuffer
.append(" );\r\n");
1031 fileBuffer
.append("EFI_STATUS\n");
1032 fileBuffer
.append("EFIAPI\n");
1033 fileBuffer
.append("ProcessModuleUnloadList (\r\n");
1034 fileBuffer
.append(" EFI_HANDLE ImageHandle\r\n");
1035 fileBuffer
.append(" )\r\n");
1036 fileBuffer
.append("{\r\n");
1038 if (entryPointCount
== 0) {
1039 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
1040 } else if (entryPointCount
== 1) {
1041 fileBuffer
.append(" return ");
1042 fileBuffer
.append(entryPointList
[0]);
1043 fileBuffer
.append("(ImageHandle);\r\n");
1045 fileBuffer
.append(" EFI_STATUS Status;\r\n\r\n");
1046 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n\r\n");
1047 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1048 if (!entryPointList
[i
].equals("")) {
1049 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
1050 fileBuffer
.append(" ");
1051 fileBuffer
.append(entryPointList
[i
]);
1052 fileBuffer
.append("(ImageHandle);\r\n");
1053 fileBuffer
.append(" } else {\r\n");
1054 fileBuffer
.append(" Status = ");
1055 fileBuffer
.append(entryPointList
[i
]);
1056 fileBuffer
.append("(ImageHandle);\r\n");
1057 fileBuffer
.append(" }\r\n");
1062 fileBuffer
.append(" return Status;\r\n");
1064 fileBuffer
.append("}\r\n\r\n");
1072 This function gets GUIDs from SPD file accrodeing to <PPIs> information and
1073 write those GUIDs to AutoGen.c.
1075 @param fileBuffer String Buffer for Autogen.c file.
1076 @throws BuildException Guid must set value!
1078 void PpiGuidToAutogenC(StringBuffer fileBuffer
) throws BuildException
{
1079 String
[] cNameGuid
= null;
1080 boolean isEqual
= false;
1082 PPIsDocument
.PPIs
.Ppi
[] ppiList
= SurfaceAreaQuery
.getPpiArray(null);
1083 if (ppiList
!= null) {
1084 for (int i
= 0; i
< ppiList
.length
; i
++) {
1086 for (int j
= 0; j
< this.mPpiList
.size(); j
++) {
1087 if (this.mPpiList
.get(j
).equalsIgnoreCase(
1088 ppiList
[i
].getStringValue())) {
1093 this.mPpiList
.add(ppiList
[i
].getStringValue());
1098 PPIsDocument
.PPIs
.PpiNotify
[] ppiNotifyList
= SurfaceAreaQuery
1099 .getPpiNotifyArray(null);
1100 if (ppiNotifyList
!= null) {
1101 for (int i
= 0; i
< ppiNotifyList
.length
; i
++) {
1103 for (int j
= 0; j
< this.mPpiList
.size(); j
++) {
1104 if (this.mPpiList
.get(j
).equalsIgnoreCase(
1105 ppiNotifyList
[i
].getStringValue())) {
1110 this.mPpiList
.add(ppiNotifyList
[i
].getStringValue());
1115 for (int i
= 0; i
< this.mPpiList
.size(); i
++) {
1116 if (this.mPpiList
.get(i
) != null) {
1117 cNameGuid
= GlobalData
.getPpiInfoGuid(this.mPpiList
.get(i
));
1118 if (cNameGuid
!= null) {
1120 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1121 fileBuffer
.append(cNameGuid
[0]);
1122 fileBuffer
.append(" = { ");
1123 fileBuffer
.append(cNameGuid
[1]);
1124 fileBuffer
.append(" } ;");
1127 throw new BuildException("Guid must set value!");
1133 ProtocolGuidToAutogenc
1135 This function gets GUIDs from SPD file accrodeing to <Protocol>
1136 information and write those GUIDs to AutoGen.c.
1138 @param fileBuffer String Buffer for Autogen.c file.
1139 @throws BuildException Protocol name must set.
1141 void ProtocolGuidToAutogenC(StringBuffer fileBuffer
) throws BuildException
{
1142 String
[] cNameGuid
= null;
1143 boolean isEqual
= false;
1145 ProtocolsDocument
.Protocols
.Protocol
[] protocolList
= SurfaceAreaQuery
1146 .getProtocolArray(null);
1147 if (protocolList
!= null) {
1148 for (int i
= 0; i
< protocolList
.length
; i
++) {
1150 for (int j
= 0; j
< this.mProtocolList
.size(); j
++) {
1151 if (this.mProtocolList
.get(j
).equalsIgnoreCase(
1152 protocolList
[i
].getStringValue())) {
1157 this.mProtocolList
.add(protocolList
[i
].getStringValue());
1163 ProtocolsDocument
.Protocols
.ProtocolNotify
[] protocolNotifyList
= SurfaceAreaQuery
1164 .getProtocolNotifyArray(null);
1165 if (protocolNotifyList
!= null) {
1166 for (int i
= 0; i
< protocolNotifyList
.length
; i
++) {
1168 for (int j
= 0; j
< this.mProtocolList
.size(); j
++) {
1169 if (this.mProtocolList
.get(j
).equalsIgnoreCase(
1170 protocolNotifyList
[i
].getStringValue())) {
1175 this.mProtocolList
.add(protocolNotifyList
[i
]
1181 if (this.mProtocolList
.size() > 0) {
1182 for (int i
= 0; i
< this.mProtocolList
.size(); i
++) {
1183 if (this.mProtocolList
.get(i
) != null) {
1184 cNameGuid
= GlobalData
1185 .getProtocolInfoGuid(this.mProtocolList
.get(i
));
1186 if (cNameGuid
!= null) {
1188 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1189 fileBuffer
.append(cNameGuid
[0]);
1190 fileBuffer
.append(" = { ");
1191 fileBuffer
.append(cNameGuid
[1]);
1192 fileBuffer
.append(" } ;");
1195 throw new BuildException("Protocol name must set!");
1204 This function gets GUIDs from SPD file accrodeing to <Guids> information
1205 and write those GUIDs to AutoGen.c.
1207 @param fileBuffer String Buffer for Autogen.c file.
1210 void GuidGuidToAutogenC(StringBuffer fileBuffer
) {
1211 String
[] cNameGuid
= null;
1212 boolean isEqual
= false;
1213 GuidsDocument
.Guids
.GuidEntry
[] guidList
= SurfaceAreaQuery
1214 .getGuidEntryArray(null);
1216 if (guidList
!= null) {
1217 for (int i
= 0; i
< guidList
.length
; i
++) {
1218 for (int j
= 0; j
< this.mGuidList
.size(); j
++) {
1220 if (this.mGuidList
.get(j
).getCName().equalsIgnoreCase(
1221 guidList
[i
].getCName().toString())) {
1227 this.mGuidList
.add(guidList
[i
]);
1234 for (int i
= 0; i
< this.mGuidList
.size(); i
++) {
1235 if (this.mGuidList
.get(i
).getCName() != null) {
1236 cNameGuid
= GlobalData
.getGuidInfoGuid(this.mGuidList
.get(i
)
1238 if (cNameGuid
!= null) {
1240 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1241 fileBuffer
.append(cNameGuid
[0]);
1242 fileBuffer
.append(" = { ");
1243 fileBuffer
.append(cNameGuid
[1]);
1244 fileBuffer
.append("} ;");
1251 LibInstanceToAutogenC
1253 This function adds dependent library instance to autogen.c,which includeing
1254 library's constructor, destructor, and library dependent ppi, protocol, guid,
1257 @param fileBuffer String buffer for AutoGen.c
1258 @throws BuildException
1260 void LibInstanceToAutogenC(StringBuffer fileBuffer
) throws BuildException
{
1262 boolean isEqual
= false;
1264 String moduleType
= SurfaceAreaQuery
.getModuleType();
1265 List
<String
> libConstructList
= new ArrayList
<String
>();
1266 List
<String
> libDestructList
= new ArrayList
<String
>();
1268 String libConstructName
= null;
1269 String libDestructName
= null;
1270 List
<String
> libraryList
= SurfaceAreaQuery
.getLibraryInstance(
1271 this.arch
, CommonDefinition
.AlwaysConsumed
);
1274 if (libraryList
!= null) {
1276 // Reorder library instance sequence.
1278 AutogenLibOrder libOrder
= new AutogenLibOrder(libraryList
);
1279 List orderList
= libOrder
.orderLibInstance();
1281 if (orderList
!= null) {
1283 // Process library instance one by one.
1285 for (int i
= 0; i
< orderList
.size(); i
++) {
1288 // Get library instance basename.
1290 String libInstanceName
= orderList
.get(i
).toString();
1295 Map
<String
, XmlObject
> libDoc
= GlobalData
1296 .getDoc(libInstanceName
);
1297 SurfaceAreaQuery
.push(libDoc
);
1300 // Get <PPis>, <Protocols>, <Guids> list of this library
1303 PPIsDocument
.PPIs
.Ppi
[] ppiList
= SurfaceAreaQuery
1305 PPIsDocument
.PPIs
.PpiNotify
[] ppiNotifyList
= SurfaceAreaQuery
1306 .getPpiNotifyArray(null);
1307 ProtocolsDocument
.Protocols
.Protocol
[] protocolList
= SurfaceAreaQuery
1308 .getProtocolArray(null);
1309 ProtocolsDocument
.Protocols
.ProtocolNotify
[] protocolNotifyList
= SurfaceAreaQuery
1310 .getProtocolNotifyArray(null);
1311 GuidsDocument
.Guids
.GuidEntry
[] guidList
= SurfaceAreaQuery
1312 .getGuidEntryArray(null);
1315 // Add those ppi, protocol, guid in global ppi, protocol, guid
1318 if (ppiList
!= null) {
1319 for (index
= 0; index
< ppiList
.length
; index
++) {
1321 for (int j
= 0; j
< this.mPpiList
.size(); j
++) {
1322 if (this.mPpiList
.get(j
).equalsIgnoreCase(
1323 ppiList
[index
].getStringValue())) {
1328 this.mPpiList
.add(ppiList
[index
]
1333 if (ppiNotifyList
!= null) {
1334 for (index
= 0; index
< ppiNotifyList
.length
; index
++) {
1336 for (int j
= 0; j
< this.mPpiList
.size(); j
++) {
1337 if (this.mPpiList
.get(j
).equalsIgnoreCase(
1338 ppiNotifyList
[index
]
1339 .getStringValue())) {
1344 this.mPpiList
.add(ppiNotifyList
[index
]
1349 if (protocolList
!= null) {
1350 for (index
= 0; index
< protocolList
.length
; index
++) {
1352 for (int j
= 0; j
< this.mProtocolList
.size(); j
++) {
1353 if (this.mProtocolList
.get(j
)
1356 .getStringValue())) {
1361 this.mProtocolList
.add(protocolList
[index
]
1366 if (protocolNotifyList
!= null) {
1367 for (index
= 0; index
< protocolNotifyList
.length
; index
++) {
1369 for (int j
= 0; j
< this.mProtocolList
.size(); j
++) {
1370 if (this.mProtocolList
.get(j
)
1372 protocolNotifyList
[index
]
1373 .getStringValue())) {
1379 .add(protocolNotifyList
[index
]
1384 if (guidList
!= null) {
1385 for (index
= 0; index
< guidList
.length
; index
++) {
1387 for (int j
= 0; j
< this.mGuidList
.size(); j
++) {
1388 if (this.mGuidList
.get(j
).getCName()
1390 guidList
[index
].getCName())) {
1395 this.mGuidList
.add(guidList
[index
]);
1401 // If not yet parse this library instance's constructor
1402 // element,parse it.
1404 if (!GlobalData
.isHaveLibInstance(libInstanceName
)) {
1405 libConstructName
= SurfaceAreaQuery
1406 .getLibConstructorName();
1407 libDestructName
= SurfaceAreaQuery
1408 .getLibDestructorName();
1410 GlobalData
.setLibInstanceInfo(libInstanceName
,
1411 libConstructName
, libDestructName
);
1413 libConstructName
= GlobalData
1414 .getLibInstanceConstructor(libInstanceName
);
1415 libDestructName
= GlobalData
1416 .getLibInstanceDestructor(libInstanceName
);
1418 SurfaceAreaQuery
.pop();
1420 // Add dependent library instance constructor function.
1422 if (libConstructName
!= null) {
1423 libConstructList
.add(libConstructName
);
1426 // Add dependent library instance destructor fuction.
1428 if (libDestructName
!= null) {
1429 libDestructList
.add(libDestructName
);
1436 // Add library constructor to AutoGen.c
1438 LibConstructorToAutogenC(libConstructList
, moduleType
,
1439 fileBuffer
/* autogenC */);
1441 // Add library destructor to AutoGen.c
1443 LibDestructorToAutogenC(libDestructList
, moduleType
,
1444 fileBuffer
/* autogenC */);
1447 } catch (Exception e
) {
1448 throw new BuildException(e
.getMessage());
1454 LibConstructorToAutogenc
1456 This function writes library constructor list to AutoGen.c. The library
1457 constructor's parameter and return value depend on module type.
1459 @param libInstanceList List of library construct name.
1460 @param moduleType Module type.
1461 @param fileBuffer String buffer for AutoGen.c
1464 void LibConstructorToAutogenC(List
<String
> libInstanceList
,
1465 String moduleType
, StringBuffer fileBuffer
) throws Exception
{
1466 boolean isFirst
= true;
1469 // The library constructor's parameter and return value depend on
1472 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1473 switch (CommonDefinition
.getModuleType(moduleType
)) {
1474 case CommonDefinition
.ModuleTypeBase
:
1475 fileBuffer
.append("RETURN_STATUS\r\n");
1476 fileBuffer
.append(libInstanceList
.get(i
));
1477 fileBuffer
.append(" (\r\n");
1478 fileBuffer
.append(" VOID\r\n");
1479 fileBuffer
.append(" );\r\n");
1482 case CommonDefinition
.ModuleTypePeiCore
:
1483 case CommonDefinition
.ModuleTypePeim
:
1484 fileBuffer
.append("EFI_STATUS\r\n");
1485 fileBuffer
.append(libInstanceList
.get(i
));
1486 fileBuffer
.append(" (\r\n");
1488 .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1490 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1491 fileBuffer
.append(" );\r\n");
1494 case CommonDefinition
.ModuleTypeDxeCore
:
1495 case CommonDefinition
.ModuleTypeDxeDriver
:
1496 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1497 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1498 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1499 case CommonDefinition
.ModuleTypeUefiDriver
:
1500 case CommonDefinition
.ModuleTypeUefiApplication
:
1501 fileBuffer
.append("EFI_STATUS\r\n");
1502 fileBuffer
.append(libInstanceList
.get(i
));
1503 fileBuffer
.append(" (\r\n");
1504 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1505 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1506 fileBuffer
.append(" );\r\n");
1512 // Add ProcessLibraryConstructorList in AutoGen.c
1514 fileBuffer
.append("VOID\r\n");
1515 fileBuffer
.append("ProcessLibraryConstructorList (\r\n");
1516 switch (CommonDefinition
.getModuleType(moduleType
)) {
1517 case CommonDefinition
.ModuleTypeBase
:
1518 fileBuffer
.append(" VOID\r\n");
1521 case CommonDefinition
.ModuleTypePeiCore
:
1522 case CommonDefinition
.ModuleTypePeim
:
1523 fileBuffer
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1525 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1528 case CommonDefinition
.ModuleTypeDxeCore
:
1529 case CommonDefinition
.ModuleTypeDxeDriver
:
1530 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1531 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1532 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1533 case CommonDefinition
.ModuleTypeUefiDriver
:
1534 case CommonDefinition
.ModuleTypeUefiApplication
:
1535 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1536 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1540 fileBuffer
.append(" )\r\n");
1541 fileBuffer
.append("{\r\n");
1543 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1545 fileBuffer
.append(" EFI_STATUS Status;\r\n");
1546 fileBuffer
.append("\r\n");
1549 switch (CommonDefinition
.getModuleType(moduleType
)) {
1550 case CommonDefinition
.ModuleTypeBase
:
1551 fileBuffer
.append(" Status = ");
1552 fileBuffer
.append(libInstanceList
.get(i
));
1553 fileBuffer
.append("();\r\n");
1554 fileBuffer
.append(" VOID\r\n");
1556 case CommonDefinition
.ModuleTypePeiCore
:
1557 case CommonDefinition
.ModuleTypePeim
:
1558 fileBuffer
.append(" Status = ");
1559 fileBuffer
.append(libInstanceList
.get(i
));
1560 fileBuffer
.append(" (FfsHeader, PeiServices);\r\n");
1562 case CommonDefinition
.ModuleTypeDxeCore
:
1563 case CommonDefinition
.ModuleTypeDxeDriver
:
1564 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1565 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1566 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1567 case CommonDefinition
.ModuleTypeUefiDriver
:
1568 case CommonDefinition
.ModuleTypeUefiApplication
:
1569 fileBuffer
.append(" Status = ");
1570 fileBuffer
.append(libInstanceList
.get(i
));
1571 fileBuffer
.append(" (ImageHandle, SystemTable);\r\n");
1574 fileBuffer
.append(" ASSERT_EFI_ERROR (Status);\r\n");
1576 fileBuffer
.append("}\r\n");
1580 LibDestructorToAutogenc
1582 This function writes library destructor list to AutoGen.c. The library
1583 destructor's parameter and return value depend on module type.
1585 @param libInstanceList List of library destructor name.
1586 @param moduleType Module type.
1587 @param fileBuffer String buffer for AutoGen.c
1590 void LibDestructorToAutogenC(List
<String
> libInstanceList
,
1591 String moduleType
, StringBuffer fileBuffer
) throws Exception
{
1592 boolean isFirst
= true;
1593 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1594 switch (CommonDefinition
.getModuleType(moduleType
)) {
1595 case CommonDefinition
.ModuleTypeBase
:
1596 fileBuffer
.append("RETURN_STATUS\n");
1597 fileBuffer
.append(libInstanceList
.get(i
));
1598 fileBuffer
.append(" (\r\n");
1599 fileBuffer
.append(" VOID\r\n");
1600 fileBuffer
.append(" );\r\n");
1602 case CommonDefinition
.ModuleTypePeiCore
:
1603 case CommonDefinition
.ModuleTypePeim
:
1604 fileBuffer
.append("EFI_STATUS\r\n");
1605 fileBuffer
.append(libInstanceList
.get(i
));
1606 fileBuffer
.append(" (\r\n");
1608 .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1610 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1611 fileBuffer
.append(" );\r\n");
1613 case CommonDefinition
.ModuleTypeDxeCore
:
1614 case CommonDefinition
.ModuleTypeDxeDriver
:
1615 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1616 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1617 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1618 case CommonDefinition
.ModuleTypeUefiDriver
:
1619 case CommonDefinition
.ModuleTypeUefiApplication
:
1620 fileBuffer
.append("EFI_STATUS\r\n");
1621 fileBuffer
.append(libInstanceList
.get(i
));
1622 fileBuffer
.append(" (\r\n");
1623 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1624 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1625 fileBuffer
.append(" );\r\n");
1631 // Write ProcessLibraryDestructor list to autogen.c
1633 switch (CommonDefinition
.getModuleType(moduleType
)) {
1634 case CommonDefinition
.ModuleTypeBase
:
1635 case CommonDefinition
.ModuleTypePeiCore
:
1636 case CommonDefinition
.ModuleTypePeim
:
1638 case CommonDefinition
.ModuleTypeDxeCore
:
1639 case CommonDefinition
.ModuleTypeDxeDriver
:
1640 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1641 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1642 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1643 case CommonDefinition
.ModuleTypeUefiDriver
:
1644 case CommonDefinition
.ModuleTypeUefiApplication
:
1645 fileBuffer
.append("VOID\r\n");
1646 fileBuffer
.append("ProcessLibraryDestructorList (\r\n");
1647 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1648 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1649 fileBuffer
.append(" )\r\n");
1650 fileBuffer
.append("{\r\n");
1652 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1654 fileBuffer
.append(" EFI_STATUS Status;\r\n");
1655 fileBuffer
.append("\r\n");
1658 fileBuffer
.append(" Status = ");
1659 fileBuffer
.append(libInstanceList
.get(i
));
1660 fileBuffer
.append("(ImageHandle, SystemTable);\r\n");
1661 fileBuffer
.append(" ASSERT_EFI_ERROR (Status);\r\n");
1663 fileBuffer
.append("}\r\n");
1669 ExternsDriverBindingToAutoGenC
1671 This function is to write DRIVER_BINDING, COMPONENT_NAME,
1672 DRIVER_CONFIGURATION, DRIVER_DIAGNOSTIC in AutoGen.c.
1674 @param fileBuffer String buffer for AutoGen.c
1676 void ExternsDriverBindingToAutoGenC(StringBuffer fileBuffer
)
1677 throws BuildException
{
1680 // Check what <extern> contains. And the number of following elements
1681 // under <extern> should be same. 1. DRIVER_BINDING 2. COMPONENT_NAME
1682 // 3.DRIVER_CONFIGURATION 4. DRIVER_DIAGNOSTIC
1685 String
[] drvBindList
= SurfaceAreaQuery
.getDriverBindingArray();
1688 // If component name protocol,component configuration protocol,
1689 // component diagnostic protocol is not null or empty, check
1690 // if every one have the same number of the driver binding protocol.
1692 if (drvBindList
== null || drvBindList
.length
== 0) {
1696 String
[] compNamList
= SurfaceAreaQuery
.getComponentNameArray();
1697 String
[] compConfList
= SurfaceAreaQuery
.getDriverConfigArray();
1698 String
[] compDiagList
= SurfaceAreaQuery
.getDriverDiagArray();
1703 // Write driver binding protocol extern to autogen.c
1705 for (int i
= 0; i
< drvBindList
.length
; i
++) {
1706 fileBuffer
.append("extern EFI_DRIVER_BINDING_PROTOCOL ");
1707 fileBuffer
.append(drvBindList
[i
]);
1708 fileBuffer
.append(";\r\n");
1712 // Write component name protocol extern to autogen.c
1714 if (compNamList
!= null && compNamList
.length
!= 0) {
1715 if (drvBindList
.length
!= compNamList
.length
) {
1716 throw new BuildException(
1717 "Different number of Driver Binding and Component Name protocols!");
1721 for (int i
= 0; i
< compNamList
.length
; i
++) {
1722 fileBuffer
.append("extern EFI_COMPONENT_NAME_PROTOCOL ");
1723 fileBuffer
.append(compNamList
[i
]);
1724 fileBuffer
.append(";\r\n");
1729 // Write driver configration protocol extern to autogen.c
1731 if (compConfList
!= null && compConfList
.length
!= 0) {
1732 if (drvBindList
.length
!= compConfList
.length
) {
1733 throw new BuildException(
1734 "Different number of Driver Binding and Driver Configuration protocols!");
1738 for (int i
= 0; i
< compConfList
.length
; i
++) {
1739 fileBuffer
.append("extern EFI_DRIVER_CONFIGURATION_PROTOCOL ");
1740 fileBuffer
.append(compConfList
[i
]);
1741 fileBuffer
.append(";\r\n");
1746 // Write driver dignastic protocol extern to autogen.c
1748 if (compDiagList
!= null && compDiagList
.length
!= 0) {
1749 if (drvBindList
.length
!= compDiagList
.length
) {
1750 throw new BuildException(
1751 "Different number of Driver Binding and Driver Configuration protocols!");
1755 for (int i
= 0; i
< compDiagList
.length
; i
++) {
1756 fileBuffer
.append("extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL ");
1757 fileBuffer
.append(compDiagList
[i
]);
1758 fileBuffer
.append(";\r\n");
1763 // Write driver module protocol bitmask.
1766 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverModelProtocolBitmask = ");
1767 fileBuffer
.append(Integer
.toString(BitMask
));
1768 fileBuffer
.append(";\r\n");
1771 // Write driver module protocol list entry
1774 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverModelProtocolListEntries = ");
1776 fileBuffer
.append(Integer
.toString(drvBindList
.length
));
1777 fileBuffer
.append(";\r\n");
1780 // Write drive module protocol list to autogen.c
1783 .append("GLOBAL_REMOVE_IF_UNREFERENCED const EFI_DRIVER_MODEL_PROTOCOL_LIST _gDriverModelProtocolList[] = {");
1784 for (int i
= 0; i
< drvBindList
.length
; i
++) {
1786 fileBuffer
.append(",");
1788 fileBuffer
.append("\r\n {\r\n");
1789 fileBuffer
.append(" &");
1790 fileBuffer
.append(drvBindList
[i
]);
1791 fileBuffer
.append(", \r\n");
1793 if (compNamList
!= null) {
1794 fileBuffer
.append(" &");
1795 fileBuffer
.append(compNamList
[i
]);
1796 fileBuffer
.append(", \r\n");
1798 fileBuffer
.append(" NULL, \r\n");
1801 if (compConfList
!= null) {
1802 fileBuffer
.append(" &");
1803 fileBuffer
.append(compConfList
[i
]);
1804 fileBuffer
.append(", \r\n");
1806 fileBuffer
.append(" NULL, \r\n");
1809 if (compDiagList
!= null) {
1810 fileBuffer
.append(" &");
1811 fileBuffer
.append(compDiagList
[i
]);
1812 fileBuffer
.append(", \r\n");
1814 fileBuffer
.append(" NULL, \r\n");
1816 fileBuffer
.append(" }");
1818 fileBuffer
.append("\r\n};\r\n");
1822 ExternCallBackToAutoGenC
1824 This function adds <SetVirtualAddressMapCallBack> and <ExitBootServicesCallBack>
1825 infomation to AutoGen.c
1827 @param fileBuffer String buffer for AutoGen.c
1828 @throws BuildException
1830 void ExternCallBackToAutoGenC(StringBuffer fileBuffer
)
1831 throws BuildException
{
1832 String
[] setVirtualList
= SurfaceAreaQuery
1833 .getSetVirtualAddressMapCallBackArray();
1834 String
[] exitBootList
= SurfaceAreaQuery
1835 .getExitBootServicesCallBackArray();
1836 String moduleType
= SurfaceAreaQuery
.getModuleType();
1837 boolean UefiOrDxeModule
= false;
1841 switch (CommonDefinition
.getModuleType(moduleType
)) {
1842 case CommonDefinition
.ModuleTypeDxeDriver
:
1843 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1844 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1845 case CommonDefinition
.ModuleTypeUefiDriver
:
1846 case CommonDefinition
.ModuleTypeUefiApplication
:
1848 // Entry point lib for these module types needs to know the count
1851 UefiOrDxeModule
= true;
1853 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverSetVirtualAddressMapEventCount = ");
1856 // If the list is not valid or has no entries set count to zero else
1857 // set count to the number of valid entries
1860 if (setVirtualList
!= null) {
1861 for (i
= 0; i
< setVirtualList
.length
; i
++) {
1862 if (setVirtualList
[i
].equalsIgnoreCase("")) {
1869 fileBuffer
.append(Integer
.toString(Count
));
1870 fileBuffer
.append(";\r\n\r\n");
1876 if (setVirtualList
== null) {
1877 if (UefiOrDxeModule
) {
1879 // No data so make a NULL list
1882 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {\r\n");
1883 fileBuffer
.append(" NULL\r\n");
1884 fileBuffer
.append("};\r\n\r\n");
1888 // Write SetVirtualAddressMap function definition.
1890 for (i
= 0; i
< setVirtualList
.length
; i
++) {
1891 if (setVirtualList
[i
].equalsIgnoreCase("")) {
1894 fileBuffer
.append("VOID\r\n");
1895 fileBuffer
.append("EFIAPI\n");
1896 fileBuffer
.append(setVirtualList
[i
]);
1897 fileBuffer
.append(" (\r\n");
1898 fileBuffer
.append(" IN EFI_EVENT Event,\r\n");
1899 fileBuffer
.append(" IN VOID *Context\r\n");
1900 fileBuffer
.append(" );\r\n\r\n");
1904 // Write SetVirtualAddressMap entry point array.
1907 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {");
1908 for (i
= 0; i
< setVirtualList
.length
; i
++) {
1909 if (setVirtualList
[i
].equalsIgnoreCase("")) {
1914 fileBuffer
.append("\r\n ");
1916 fileBuffer
.append(",\r\n ");
1919 fileBuffer
.append(setVirtualList
[i
]);
1922 fileBuffer
.append("\r\n NULL");
1924 fileBuffer
.append("\r\n};\r\n\r\n");
1927 if (UefiOrDxeModule
) {
1929 // Entry point lib for these module types needs to know the count.
1932 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverExitBootServicesEventCount = ");
1935 // If the list is not valid or has no entries set count to zero else
1936 // set count to the number of valid entries.
1939 if (exitBootList
!= null) {
1940 if (setVirtualList
!= null) {
1941 for (i
= 0; i
< exitBootList
.length
; i
++) {
1942 if (exitBootList
[i
].equalsIgnoreCase("")) {
1949 fileBuffer
.append(Integer
.toString(Count
));
1950 fileBuffer
.append(";\r\n\r\n");
1953 if (exitBootList
== null) {
1954 if (UefiOrDxeModule
) {
1956 // No data so make a NULL list.
1959 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {\r\n");
1960 fileBuffer
.append(" NULL\r\n");
1961 fileBuffer
.append("};\r\n\r\n");
1965 // Write DriverExitBootServices function definition.
1967 for (i
= 0; i
< exitBootList
.length
; i
++) {
1968 if (exitBootList
[i
].equalsIgnoreCase("")) {
1972 fileBuffer
.append("VOID\r\n");
1973 fileBuffer
.append("EFIAPI\n");
1974 fileBuffer
.append(exitBootList
[i
]);
1975 fileBuffer
.append(" (\r\n");
1976 fileBuffer
.append(" IN EFI_EVENT Event,\r\n");
1977 fileBuffer
.append(" IN VOID *Context\r\n");
1978 fileBuffer
.append(" );\r\n\r\n");
1982 // Write DriverExitBootServices entry point array.
1985 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {");
1986 for (i
= 0; i
< exitBootList
.length
; i
++) {
1987 if (exitBootList
[i
].equalsIgnoreCase("")) {
1992 fileBuffer
.append("\r\n ");
1994 fileBuffer
.append(",\r\n ");
1996 fileBuffer
.append(exitBootList
[i
]);
1999 fileBuffer
.append("\r\n NULL");
2001 fileBuffer
.append("\r\n};\r\n\r\n");