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
,
418 SurfaceAreaQuery
.getModulePcdEntryNameArray());
419 this.myPcdAutogen
.execute();
420 } catch (Exception e
) {
421 throw new BuildException("PCD Autogen for module failed:" + e
.getMessage());
424 if (this.myPcdAutogen
!= null) {
425 fileBuffer
.append(this.myPcdAutogen
.OutputC());
428 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.c", fileBuffer
)) {
429 throw new BuildException("Failed to generate AutoGen.c !!!");
437 This function generates AutoGen.h for library.
439 @throws BuildException
440 Failed to generate AutoGen.c.
442 void libGenAutogenH() throws BuildException
{
444 List
<String
> libClassIncludeH
;
446 List
<String
> headerFileList
;
447 StringBuffer fileBuffer
= new StringBuffer(10240);
450 // Write Autogen.h header notation
452 fileBuffer
.append(CommonDefinition
.autogenHNotation
);
455 // Add #ifndef ${BaseName}_AUTOGENH
456 // #def ${BseeName}_AUTOGENH
458 fileBuffer
.append("#ifndef " + this.baseName
.toUpperCase() + "_AUTOGENH\r\n");
459 fileBuffer
.append("#define " + this.baseName
.toUpperCase() + "_AUTOGENH\r\n\r\n");
462 // Write EFI_SPECIFICATION_VERSION and EDK_RELEASE_VERSION
463 // to autogen.h file.
464 // Note: the specification version and release version should
465 // be get from module surface area instead of hard code.
467 fileBuffer
.append(CommonDefinition
.autoGenHbegin
);
468 fileBuffer
.append(CommonDefinition
.autoGenHLine1
);
469 fileBuffer
.append(CommonDefinition
.autoGenHLine2
);
472 // Write consumed package's mdouleInfo related *.h file to autogen.h.
474 moduleType
= SurfaceAreaQuery
.getModuleType();
475 List
<String
> cosumedPkglist
= SurfaceAreaQuery
476 .getIncludePackageName(this.arch
);
477 headerFileList
= IncludesToAutogenH(cosumedPkglist
, moduleType
);
478 for (int i
= 0; i
< headerFileList
.size(); i
++) {
479 fileBuffer
.append(headerFileList
.get(i
));
483 // Write library class's related *.h file to autogen.h
485 LibraryClass
[] libClassList
= SurfaceAreaQuery
486 .getLibraryClassArray(CommonDefinition
.AlwaysConsumed
);
487 if (libClassList
!= null) {
488 libClassIncludeH
= LibraryClassToAutogenH(libClassList
);
489 for (int i
= 0; i
< libClassIncludeH
.size(); i
++) {
490 fileBuffer
.append(libClassIncludeH
.get(i
));
494 libClassList
= SurfaceAreaQuery
495 .getLibraryClassArray(CommonDefinition
.AlwaysProduced
);
496 if (libClassList
!= null) {
497 libClassIncludeH
= LibraryClassToAutogenH(libClassList
);
498 for (int i
= 0; i
< libClassIncludeH
.size(); i
++) {
499 fileBuffer
.append(libClassIncludeH
.get(i
));
502 fileBuffer
.append("\r\n");
505 // Write PCD information to library AutoGen.h.
507 if (this.myPcdAutogen
!= null) {
508 fileBuffer
.append(this.myPcdAutogen
.OutputH());
512 // Append the #endif at AutoGen.h
514 fileBuffer
.append("#endif\r\n");
517 // Save content of string buffer to AutoGen.h file.
519 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.h", fileBuffer
)) {
520 throw new BuildException("Failed to generate AutoGen.h !!!");
527 This function generates AutoGen.h for library.
529 @throws BuildException
530 Failed to generate AutoGen.c.
532 void libGenAutogenC() throws BuildException
{
533 StringBuffer fileBuffer
= new StringBuffer(10240);
536 // Write Autogen.c header notation
538 fileBuffer
.append(CommonDefinition
.autogenCNotation
);
540 fileBuffer
.append(CommonDefinition
.autoGenCLine1
);
541 fileBuffer
.append("\r\n");
544 // Call pcd autogen. PCDAutoGenAction tool only need module name and
545 // isPcdEmulatedDriver as parameter. Library inherit PCD and module's
546 // PCD information has been collected in FPDParser task by
548 // Note : when PCD image tool ready,
549 // isPCDEmulatedDriver parameter will be removed.
552 this.myPcdAutogen
= new PCDAutoGenAction(baseName
,
559 SurfaceAreaQuery
.getModulePcdEntryNameArray());
560 this.myPcdAutogen
.execute();
561 } catch (Exception e
) {
562 throw new BuildException("Pcd Autogen for library failed! " + e
.getMessage());
565 if (this.myPcdAutogen
!= null) {
566 fileBuffer
.append(this.myPcdAutogen
.OutputC());
569 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.c", fileBuffer
)) {
570 throw new BuildException("Failed to generate AutoGen.c !!!");
575 LibraryClassToAutogenH
577 This function returns *.h files declared by library classes which are
578 consumed or produced by current build module or library.
580 @param libClassList List of library class which consumed or produce
581 by current build module or library.
582 @return includeStrList List of *.h file.
584 List
<String
> LibraryClassToAutogenH(LibraryClass
[] libClassList
) {
585 List
<String
> includStrList
= new ArrayList
<String
>();
590 // Get include file from GlobalData's SPDTable according to
591 // library class name.
593 for (int i
= 0; i
< libClassList
.length
; i
++) {
594 includerName
= GlobalData
.getLibClassIncluder(getStringValue((XmlObject
)libClassList
[i
]));
595 if (includerName
!= null) {
596 str
= CommonDefinition
.include
+ " " + "<";
597 str
= str
+ includerName
+ ">\r\n";
598 includStrList
.add(str
);
602 return includStrList
;
608 This function add include file in AutoGen.h file.
609 @param packageNameList List of module depended package.
610 @param moduleType Module type.
613 List
<String
> IncludesToAutogenH(List
<String
> packageNameList
,
616 List
<String
> includeStrList
= new ArrayList
<String
>();
617 String packageName
= "";
618 String includeStr
= "";
621 // Get include file from moduleInfo file
623 for (int i
= 0; i
< packageNameList
.size(); i
++) {
624 packageName
= packageNameList
.get(i
);
625 includeStr
= GlobalData
.getModuleInfoByPackageName(packageName
,
627 includeStrList
.add(includeStr
);
629 return includeStrList
;
635 This function convert <ModuleEntryPoint> & <ModuleUnloadImage> information
638 @param entryPointList List of entry point.
639 @param fileBuffer String buffer fo AutoGen.c.
642 void EntryPointToAutoGen(String
[] entryPointList
, StringBuffer fileBuffer
)
643 throws BuildException
{
645 String typeStr
= SurfaceAreaQuery
.getModuleType();
648 // The parameters and return value of entryPoint is difference
649 // for difference module type.
651 switch (CommonDefinition
.getModuleType(typeStr
)) {
653 case CommonDefinition
.ModuleTypePeiCore
:
654 if (entryPointList
.length
!= 1 || entryPointList
[0].equals("")) {
655 throw new BuildException(
656 "Module type = 'PEI_CORE', only have one module entry point!");
658 fileBuffer
.append("EFI_STATUS\r\n");
659 fileBuffer
.append("EFIAPI\r\n");
660 fileBuffer
.append(entryPointList
[0]);
661 fileBuffer
.append(" (\r\n");
663 .append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n");
665 .append(" IN VOID *OldCoreData\r\n");
666 fileBuffer
.append(" );\r\n\r\n");
668 fileBuffer
.append("EFI_STATUS\r\n");
669 fileBuffer
.append("EFIAPI\r\n");
670 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
672 .append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n");
674 .append(" IN VOID *OldCoreData\r\n");
675 fileBuffer
.append(" )\r\n\r\n");
676 fileBuffer
.append("{\r\n");
677 fileBuffer
.append(" return ");
678 fileBuffer
.append(entryPointList
[0]);
679 fileBuffer
.append(" (PeiStartupDescriptor, OldCoreData);\r\n");
680 fileBuffer
.append("}\r\n\r\n");
684 case CommonDefinition
.ModuleTypeDxeCore
:
685 fileBuffer
.append("const UINT32 _gUefiDriverRevision = 0;\r\n");
686 if (entryPointList
.length
!= 1 || entryPointList
[0].equals("")) {
687 throw new BuildException(
688 "Module type = 'DXE_CORE', only have one module entry point!");
691 fileBuffer
.append("VOID\r\n");
692 fileBuffer
.append("EFIAPI\r\n");
693 fileBuffer
.append(entryPointList
[0]);
694 fileBuffer
.append(" (\n");
695 fileBuffer
.append(" IN VOID *HobStart\r\n");
696 fileBuffer
.append(" );\r\n\r\n");
698 fileBuffer
.append("VOID\r\n");
699 fileBuffer
.append("EFIAPI\r\n");
700 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
701 fileBuffer
.append(" IN VOID *HobStart\r\n");
702 fileBuffer
.append(" )\r\n\r\n");
703 fileBuffer
.append("{\r\n");
704 fileBuffer
.append(" ");
705 fileBuffer
.append(entryPointList
[0]);
706 fileBuffer
.append(" (HobStart);\r\n");
707 fileBuffer
.append("}\r\n\r\n");
711 case CommonDefinition
.ModuleTypePeim
:
712 int entryPointCount
= 0;
714 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = 0;\r\n");
715 for (int i
= 0; i
< entryPointList
.length
; i
++) {
716 if (!entryPointList
[i
].equals("")) {
717 fileBuffer
.append("EFI_STATUS\r\n");
718 fileBuffer
.append("EFIAPI\r\n");
719 fileBuffer
.append(entryPointList
[i
]);
720 fileBuffer
.append(" (\r\n");
722 .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
724 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
725 fileBuffer
.append(" );\r\n");
732 fileBuffer
.append("EFI_STATUS\r\n");
733 fileBuffer
.append("EFIAPI\r\n");
734 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
735 fileBuffer
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
736 fileBuffer
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
737 fileBuffer
.append(" )\r\n\r\n");
738 fileBuffer
.append("{\r\n");
740 if (entryPointCount
== 0) {
741 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
742 } else if (entryPointCount
== 1) {
743 fileBuffer
.append(" return ");
744 fileBuffer
.append(entryPointList
[0]);
745 fileBuffer
.append(" (FfsHeader, PeiServices);\r\n");
747 fileBuffer
.append(" EFI_STATUS Status;\r\n");
748 fileBuffer
.append(" EFI_STATUS CombinedStatus;\r\n\r\n");
749 fileBuffer
.append(" CombinedStatus = EFI_LOAD_ERROR;\r\n\r\n");
750 for (int i
= 0; i
< entryPointList
.length
; i
++) {
751 if (!entryPointList
[i
].equals("")) {
752 fileBuffer
.append(" Status = ");
753 fileBuffer
.append(entryPointList
[i
]);
754 fileBuffer
.append(" (FfsHeader, PeiServices);\r\n");
756 .append(" if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {\r\n");
757 fileBuffer
.append(" CombinedStatus = Status;\r\n");
758 fileBuffer
.append(" }\r\n\r\n");
763 fileBuffer
.append(" return CombinedStatus;\r\n");
765 fileBuffer
.append("}\r\n\r\n");
768 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
770 for (int i
= 0; i
< entryPointList
.length
; i
++) {
771 if (!entryPointList
[i
].equals("")) {
772 fileBuffer
.append("EFI_STATUS\r\n");
773 fileBuffer
.append("EFIAPI\r\n");
774 fileBuffer
.append(entryPointList
[i
]);
775 fileBuffer
.append(" (\r\n");
776 fileBuffer
.append(" EFI_HANDLE ImageHandle,\r\n");
777 fileBuffer
.append(" EFI_SYSTEM_TABLE *SystemTable\r\n");
778 fileBuffer
.append(" );\r\n");
785 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
786 fileBuffer
.append(Integer
.toString(entryPointCount
));
787 fileBuffer
.append(";\r\n");
789 .append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");
791 .append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n\r\n");
793 fileBuffer
.append("EFI_STATUS\r\n");
794 fileBuffer
.append("EFIAPI\r\n");
795 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
796 fileBuffer
.append(" EFI_HANDLE ImageHandle,\r\n");
797 fileBuffer
.append(" EFI_SYSTEM_TABLE *SystemTable\r\n");
798 fileBuffer
.append(" )\r\n\r\n");
799 fileBuffer
.append("{\r\n");
801 for (int i
= 0; i
< entryPointList
.length
; i
++) {
802 if (!entryPointList
[i
].equals("")) {
804 .append(" if (SetJump (&mJumpContext) == 0) {\r\n");
805 fileBuffer
.append(" ExitDriver (");
806 fileBuffer
.append(entryPointList
[i
]);
807 fileBuffer
.append(" (ImageHandle, SystemTable));\r\n");
808 fileBuffer
.append(" ASSERT (FALSE);\r\n");
809 fileBuffer
.append(" }\r\n");
814 fileBuffer
.append(" return mDriverEntryPointStatus;\r\n");
815 fileBuffer
.append("}\r\n\r\n");
817 fileBuffer
.append("VOID\r\n");
818 fileBuffer
.append("EFIAPI\r\n");
819 fileBuffer
.append("ExitDriver (\r\n");
820 fileBuffer
.append(" IN EFI_STATUS Status\n");
821 fileBuffer
.append(" )\r\n\r\n");
822 fileBuffer
.append("{\r\n");
824 .append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");
825 fileBuffer
.append(" mDriverEntryPointStatus = Status;\r\n");
826 fileBuffer
.append(" }\r\n");
827 fileBuffer
.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");
828 fileBuffer
.append(" ASSERT (FALSE);\r\n");
829 fileBuffer
.append("}\r\n\r\n");
832 // Add "ModuleUnloadImage" for DxeSmmDriver module type;
834 entryPointList
= SurfaceAreaQuery
.getModuleUnloadImageArray();
836 if (entryPointList
!= null) {
837 for (int i
= 0; i
< entryPointList
.length
; i
++) {
838 if (!entryPointList
[i
].equals("")) {
839 fileBuffer
.append("EFI_STATUS\r\n");
840 fileBuffer
.append("EFIAPI\r\n");
841 fileBuffer
.append(entryPointList
[i
]);
842 fileBuffer
.append(" (\r\n");
844 .append(" EFI_HANDLE ImageHandle\r\n");
845 fileBuffer
.append(" );\r\n");
854 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");
855 fileBuffer
.append(Integer
.toString(entryPointCount
));
856 fileBuffer
.append(";\r\n\r\n");
858 if (entryPointList
!= null) {
859 for (int i
= 0; i
< entryPointList
.length
; i
++) {
860 if (!entryPointList
[i
].equals("")) {
861 fileBuffer
.append("EFI_STATUS\r\n");
862 fileBuffer
.append("EFIAPI\r\n");
863 fileBuffer
.append(entryPointList
[i
]);
864 fileBuffer
.append(" (\r\n");
866 .append(" EFI_HANDLE ImageHandle\r\n");
867 fileBuffer
.append(" );\r\n");
874 fileBuffer
.append("EFI_STATUS\r\n");
875 fileBuffer
.append("EFIAPI\r\n");
876 fileBuffer
.append("ProcessModuleUnloadList (\r\n");
877 fileBuffer
.append(" EFI_HANDLE ImageHandle\r\n");
878 fileBuffer
.append(" )\r\n");
879 fileBuffer
.append("{\r\n");
881 if (entryPointCount
== 0) {
882 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
883 } else if (entryPointCount
== 1) {
884 fileBuffer
.append(" return ");
885 fileBuffer
.append(entryPointList
[0]);
886 fileBuffer
.append("(ImageHandle);\r\n");
888 fileBuffer
.append(" EFI_STATUS Status;\r\n\r\n");
889 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n\r\n");
890 for (int i
= 0; i
< entryPointList
.length
; i
++) {
891 if (!entryPointList
[i
].equals("")) {
892 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
893 fileBuffer
.append(" ");
894 fileBuffer
.append(entryPointList
[i
]);
895 fileBuffer
.append("(ImageHandle);\r\n");
896 fileBuffer
.append(" } else {\r\n");
897 fileBuffer
.append(" Status = ");
898 fileBuffer
.append(entryPointList
[i
]);
899 fileBuffer
.append("(ImageHandle);\r\n");
900 fileBuffer
.append(" }\r\n");
905 fileBuffer
.append(" return Status;\r\n");
907 fileBuffer
.append("}\r\n\r\n");
910 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
911 case CommonDefinition
.ModuleTypeDxeDriver
:
912 case CommonDefinition
.ModuleTypeDxeSalDriver
:
913 case CommonDefinition
.ModuleTypeUefiDriver
:
914 case CommonDefinition
.ModuleTypeUefiApplication
:
916 fileBuffer
.append("const UINT32 _gUefiDriverRevision = 0;\r\n");
917 for (int i
= 0; i
< entryPointList
.length
; i
++) {
918 if (!entryPointList
[i
].equals("")) {
919 fileBuffer
.append("EFI_STATUS\r\n");
920 fileBuffer
.append("EFIAPI\r\n");
921 fileBuffer
.append(entryPointList
[i
]);
922 fileBuffer
.append(" (\r\n");
923 fileBuffer
.append(" EFI_HANDLE ImageHandle,\r\n");
924 fileBuffer
.append(" EFI_SYSTEM_TABLE *SystemTable\r\n");
925 fileBuffer
.append(" );\r\n");
933 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
934 fileBuffer
.append(Integer
.toString(entryPointCount
));
935 fileBuffer
.append(";\r\n");
936 if (entryPointCount
> 1) {
938 .append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");
940 .append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n");
942 fileBuffer
.append("\n");
944 fileBuffer
.append("EFI_STATUS\r\n");
945 fileBuffer
.append("EFIAPI\r\n");
946 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
947 fileBuffer
.append(" EFI_HANDLE ImageHandle,\r\n");
948 fileBuffer
.append(" EFI_SYSTEM_TABLE *SystemTable\r\n");
949 fileBuffer
.append(" )\r\n\r\n");
950 fileBuffer
.append("{\r\n");
952 if (entryPointCount
== 0) {
953 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
954 } else if (entryPointCount
== 1) {
955 fileBuffer
.append(" return (");
956 fileBuffer
.append(entryPointList
[0]);
957 fileBuffer
.append(" (ImageHandle, SystemTable));\r\n");
959 for (int i
= 0; i
< entryPointList
.length
; i
++) {
960 if (!entryPointList
[i
].equals("")) {
962 .append(" if (SetJump (&mJumpContext) == 0) {\r\n");
963 fileBuffer
.append(" ExitDriver (");
964 fileBuffer
.append(entryPointList
[i
]);
965 fileBuffer
.append(" (ImageHandle, SystemTable));\r\n");
966 fileBuffer
.append(" ASSERT (FALSE);\r\n");
967 fileBuffer
.append(" }\r\n");
972 fileBuffer
.append(" return mDriverEntryPointStatus;\r\n");
974 fileBuffer
.append("}\r\n\r\n");
976 fileBuffer
.append("VOID\n");
977 fileBuffer
.append("EFIAPI\n");
978 fileBuffer
.append("ExitDriver (\r\n");
979 fileBuffer
.append(" IN EFI_STATUS Status\n");
980 fileBuffer
.append(" )\r\n\r\n");
981 fileBuffer
.append("{\r\n");
982 if (entryPointCount
<= 1) {
983 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
985 .append(" ProcessLibraryDestructorList (gImageHandle, gST);\r\n");
986 fileBuffer
.append(" }\r\n");
988 .append(" gBS->Exit (gImageHandle, Status, 0, NULL);\r\n");
991 .append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");
992 fileBuffer
.append(" mDriverEntryPointStatus = Status;\r\n");
993 fileBuffer
.append(" }\r\n");
994 fileBuffer
.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");
995 fileBuffer
.append(" ASSERT (FALSE);\r\n");
997 fileBuffer
.append("}\r\n\r\n");
1000 // Add ModuleUnloadImage for DxeDriver and UefiDriver module type.
1002 entryPointList
= SurfaceAreaQuery
.getModuleUnloadImageArray();
1003 entryPointCount
= 0;
1004 if (entryPointList
!= null) {
1005 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1006 if (!entryPointList
[i
].equals("")) {
1007 fileBuffer
.append("EFI_STATUS\r\n");
1008 fileBuffer
.append("EFIAPI\r\n");
1009 fileBuffer
.append(entryPointList
[i
]);
1010 fileBuffer
.append(" (\r\n");
1012 .append(" EFI_HANDLE ImageHandle\r\n");
1013 fileBuffer
.append(" );\r\n");
1022 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");
1023 fileBuffer
.append(Integer
.toString(entryPointCount
));
1024 fileBuffer
.append(";\r\n\r\n");
1026 if (entryPointList
!= null) {
1027 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1028 if (!entryPointList
[i
].equals("")) {
1029 fileBuffer
.append("EFI_STATUS\r\n");
1030 fileBuffer
.append("EFIAPI\r\n");
1031 fileBuffer
.append(entryPointList
[i
]);
1032 fileBuffer
.append(" (\r\n");
1034 .append(" EFI_HANDLE ImageHandle\r\n");
1035 fileBuffer
.append(" );\r\n");
1042 fileBuffer
.append("EFI_STATUS\n");
1043 fileBuffer
.append("EFIAPI\n");
1044 fileBuffer
.append("ProcessModuleUnloadList (\r\n");
1045 fileBuffer
.append(" EFI_HANDLE ImageHandle\r\n");
1046 fileBuffer
.append(" )\r\n");
1047 fileBuffer
.append("{\r\n");
1049 if (entryPointCount
== 0) {
1050 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
1051 } else if (entryPointCount
== 1) {
1052 fileBuffer
.append(" return ");
1053 fileBuffer
.append(entryPointList
[0]);
1054 fileBuffer
.append("(ImageHandle);\r\n");
1056 fileBuffer
.append(" EFI_STATUS Status;\r\n\r\n");
1057 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n\r\n");
1058 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1059 if (!entryPointList
[i
].equals("")) {
1060 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
1061 fileBuffer
.append(" ");
1062 fileBuffer
.append(entryPointList
[i
]);
1063 fileBuffer
.append("(ImageHandle);\r\n");
1064 fileBuffer
.append(" } else {\r\n");
1065 fileBuffer
.append(" Status = ");
1066 fileBuffer
.append(entryPointList
[i
]);
1067 fileBuffer
.append("(ImageHandle);\r\n");
1068 fileBuffer
.append(" }\r\n");
1073 fileBuffer
.append(" return Status;\r\n");
1075 fileBuffer
.append("}\r\n\r\n");
1083 This function gets GUIDs from SPD file accrodeing to <PPIs> information and
1084 write those GUIDs to AutoGen.c.
1086 @param fileBuffer String Buffer for Autogen.c file.
1087 @throws BuildException Guid must set value!
1089 void PpiGuidToAutogenC(StringBuffer fileBuffer
) throws BuildException
{
1090 String
[] cNameGuid
= null;
1091 boolean isEqual
= false;
1093 PPIsDocument
.PPIs
.Ppi
[] ppiList
= SurfaceAreaQuery
.getPpiArray(null);
1094 if (ppiList
!= null) {
1095 for (int i
= 0; i
< ppiList
.length
; i
++) {
1097 String ppiName
= getStringValue((XmlObject
)ppiList
[i
]);
1098 for (int j
= 0; j
< this.mPpiList
.size(); j
++) {
1099 if (this.mPpiList
.get(j
).equalsIgnoreCase(ppiName
)) {
1104 this.mPpiList
.add(ppiName
);
1109 PPIsDocument
.PPIs
.PpiNotify
[] ppiNotifyList
= SurfaceAreaQuery
1110 .getPpiNotifyArray(null);
1111 if (ppiNotifyList
!= null) {
1112 for (int i
= 0; i
< ppiNotifyList
.length
; i
++) {
1114 String ppiNotifyName
= getStringValue((XmlObject
)ppiNotifyList
[i
]);
1115 for (int j
= 0; j
< this.mPpiList
.size(); j
++) {
1116 if (this.mPpiList
.get(j
).equalsIgnoreCase(ppiNotifyName
)) {
1121 this.mPpiList
.add(ppiNotifyName
);
1126 for (int i
= 0; i
< this.mPpiList
.size(); i
++) {
1127 if (this.mPpiList
.get(i
) != null) {
1128 cNameGuid
= GlobalData
.getPpiInfoGuid(this.mPpiList
.get(i
));
1129 if (cNameGuid
!= null) {
1131 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1132 fileBuffer
.append(cNameGuid
[0]);
1133 fileBuffer
.append(" = { ");
1134 fileBuffer
.append(cNameGuid
[1]);
1135 fileBuffer
.append(" } ;");
1138 throw new BuildException("Guid must set value!");
1144 ProtocolGuidToAutogenc
1146 This function gets GUIDs from SPD file accrodeing to <Protocol>
1147 information and write those GUIDs to AutoGen.c.
1149 @param fileBuffer String Buffer for Autogen.c file.
1150 @throws BuildException Protocol name must set.
1152 void ProtocolGuidToAutogenC(StringBuffer fileBuffer
) throws BuildException
{
1153 String
[] cNameGuid
= null;
1154 boolean isEqual
= false;
1156 ProtocolsDocument
.Protocols
.Protocol
[] protocolList
= SurfaceAreaQuery
1157 .getProtocolArray(null);
1158 if (protocolList
!= null) {
1159 for (int i
= 0; i
< protocolList
.length
; i
++) {
1161 String protocolName
= getStringValue((XmlObject
)protocolList
[i
]);
1162 for (int j
= 0; j
< this.mProtocolList
.size(); j
++) {
1163 if (this.mProtocolList
.get(j
).equalsIgnoreCase(protocolName
)) {
1168 this.mProtocolList
.add(protocolName
);
1174 ProtocolsDocument
.Protocols
.ProtocolNotify
[] protocolNotifyList
= SurfaceAreaQuery
1175 .getProtocolNotifyArray(null);
1176 if (protocolNotifyList
!= null) {
1177 for (int i
= 0; i
< protocolNotifyList
.length
; i
++) {
1179 String protocolNotifyName
= getStringValue((XmlObject
)protocolNotifyList
[i
]);
1180 for (int j
= 0; j
< this.mProtocolList
.size(); j
++) {
1181 if (this.mProtocolList
.get(j
).equalsIgnoreCase(protocolNotifyName
)) {
1186 this.mProtocolList
.add(protocolNotifyName
);
1191 if (this.mProtocolList
.size() > 0) {
1192 for (int i
= 0; i
< this.mProtocolList
.size(); i
++) {
1193 if (this.mProtocolList
.get(i
) != null) {
1194 cNameGuid
= GlobalData
1195 .getProtocolInfoGuid(this.mProtocolList
.get(i
));
1196 if (cNameGuid
!= null) {
1198 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1199 fileBuffer
.append(cNameGuid
[0]);
1200 fileBuffer
.append(" = { ");
1201 fileBuffer
.append(cNameGuid
[1]);
1202 fileBuffer
.append(" } ;");
1205 throw new BuildException("Protocol name must set!");
1214 This function gets GUIDs from SPD file accrodeing to <Guids> information
1215 and write those GUIDs to AutoGen.c.
1217 @param fileBuffer String Buffer for Autogen.c file.
1220 void GuidGuidToAutogenC(StringBuffer fileBuffer
) {
1221 String
[] cNameGuid
= null;
1222 boolean isEqual
= false;
1223 GuidsDocument
.Guids
.GuidEntry
[] guidList
= SurfaceAreaQuery
1224 .getGuidEntryArray(null);
1226 if (guidList
!= null) {
1227 for (int i
= 0; i
< guidList
.length
; i
++) {
1228 for (int j
= 0; j
< this.mGuidList
.size(); j
++) {
1230 if (this.mGuidList
.get(j
).getCName().equalsIgnoreCase(
1231 guidList
[i
].getCName().toString())) {
1237 this.mGuidList
.add(guidList
[i
]);
1244 for (int i
= 0; i
< this.mGuidList
.size(); i
++) {
1245 if (this.mGuidList
.get(i
).getCName() != null) {
1246 cNameGuid
= GlobalData
.getGuidInfoGuid(this.mGuidList
.get(i
)
1248 if (cNameGuid
!= null) {
1250 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1251 fileBuffer
.append(cNameGuid
[0]);
1252 fileBuffer
.append(" = { ");
1253 fileBuffer
.append(cNameGuid
[1]);
1254 fileBuffer
.append("} ;");
1261 LibInstanceToAutogenC
1263 This function adds dependent library instance to autogen.c,which includeing
1264 library's constructor, destructor, and library dependent ppi, protocol, guid,
1267 @param fileBuffer String buffer for AutoGen.c
1268 @throws BuildException
1270 void LibInstanceToAutogenC(StringBuffer fileBuffer
) throws BuildException
{
1272 boolean isEqual
= false;
1274 String moduleType
= SurfaceAreaQuery
.getModuleType();
1275 List
<String
> libConstructList
= new ArrayList
<String
>();
1276 List
<String
> libDestructList
= new ArrayList
<String
>();
1278 String libConstructName
= null;
1279 String libDestructName
= null;
1280 List
<String
> libraryList
= SurfaceAreaQuery
.getLibraryInstance(
1281 this.arch
, CommonDefinition
.AlwaysConsumed
);
1284 if (libraryList
!= null) {
1286 // Reorder library instance sequence.
1288 AutogenLibOrder libOrder
= new AutogenLibOrder(libraryList
);
1289 List orderList
= libOrder
.orderLibInstance();
1291 if (orderList
!= null) {
1293 // Process library instance one by one.
1295 for (int i
= 0; i
< orderList
.size(); i
++) {
1298 // Get library instance basename.
1300 String libInstanceName
= orderList
.get(i
).toString();
1305 Map
<String
, XmlObject
> libDoc
= GlobalData
1306 .getDoc(libInstanceName
);
1307 SurfaceAreaQuery
.push(libDoc
);
1310 // Get <PPis>, <Protocols>, <Guids> list of this library
1313 PPIsDocument
.PPIs
.Ppi
[] ppiList
= SurfaceAreaQuery
1315 PPIsDocument
.PPIs
.PpiNotify
[] ppiNotifyList
= SurfaceAreaQuery
1316 .getPpiNotifyArray(null);
1317 ProtocolsDocument
.Protocols
.Protocol
[] protocolList
= SurfaceAreaQuery
1318 .getProtocolArray(null);
1319 ProtocolsDocument
.Protocols
.ProtocolNotify
[] protocolNotifyList
= SurfaceAreaQuery
1320 .getProtocolNotifyArray(null);
1321 GuidsDocument
.Guids
.GuidEntry
[] guidList
= SurfaceAreaQuery
1322 .getGuidEntryArray(null);
1325 // Add those ppi, protocol, guid in global ppi, protocol, guid
1328 if (ppiList
!= null) {
1329 for (index
= 0; index
< ppiList
.length
; index
++) {
1331 String name
= getStringValue((XmlObject
)ppiList
[index
]);
1332 for (int j
= 0; j
< this.mPpiList
.size(); j
++) {
1333 if (this.mPpiList
.get(j
).equalsIgnoreCase(name
)) {
1338 this.mPpiList
.add(name
);
1342 if (ppiNotifyList
!= null) {
1343 for (index
= 0; index
< ppiNotifyList
.length
; index
++) {
1345 String name
= getStringValue((XmlObject
)ppiNotifyList
[index
]);
1346 for (int j
= 0; j
< this.mPpiList
.size(); j
++) {
1347 if (this.mPpiList
.get(j
).equalsIgnoreCase(name
)) {
1352 this.mPpiList
.add(name
);
1356 if (protocolList
!= null) {
1357 for (index
= 0; index
< protocolList
.length
; index
++) {
1359 String name
= getStringValue((XmlObject
)protocolList
[index
]);
1360 for (int j
= 0; j
< this.mProtocolList
.size(); j
++) {
1361 if (this.mProtocolList
.get(j
).equalsIgnoreCase(name
)) {
1366 this.mProtocolList
.add(name
);
1370 if (protocolNotifyList
!= null) {
1371 for (index
= 0; index
< protocolNotifyList
.length
; index
++) {
1373 String name
= getStringValue((XmlObject
)protocolNotifyList
[index
]);
1374 for (int j
= 0; j
< this.mProtocolList
.size(); j
++) {
1375 if (this.mProtocolList
.get(j
).equalsIgnoreCase(name
)) {
1380 this.mProtocolList
.add(name
);
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");
2006 private String
getStringValue(XmlObject xmlDoc
) {
2007 return xmlDoc
.getDomNode().getFirstChild().getNodeValue();