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(libClassList
[i
]
596 if (includerName
!= null) {
597 str
= CommonDefinition
.include
+ " " + "<";
598 str
= str
+ includerName
+ ">\r\n";
599 includStrList
.add(str
);
603 return includStrList
;
609 This function add include file in AutoGen.h file.
610 @param packageNameList List of module depended package.
611 @param moduleType Module type.
614 List
<String
> IncludesToAutogenH(List
<String
> packageNameList
,
617 List
<String
> includeStrList
= new ArrayList
<String
>();
618 String packageName
= "";
619 String includeStr
= "";
622 // Get include file from moduleInfo file
624 for (int i
= 0; i
< packageNameList
.size(); i
++) {
625 packageName
= packageNameList
.get(i
);
626 includeStr
= GlobalData
.getModuleInfoByPackageName(packageName
,
628 includeStrList
.add(includeStr
);
630 return includeStrList
;
636 This function convert <ModuleEntryPoint> & <ModuleUnloadImage> information
639 @param entryPointList List of entry point.
640 @param fileBuffer String buffer fo AutoGen.c.
643 void EntryPointToAutoGen(String
[] entryPointList
, StringBuffer fileBuffer
)
644 throws BuildException
{
646 String typeStr
= SurfaceAreaQuery
.getModuleType();
649 // The parameters and return value of entryPoint is difference
650 // for difference module type.
652 switch (CommonDefinition
.getModuleType(typeStr
)) {
654 case CommonDefinition
.ModuleTypePeiCore
:
655 if (entryPointList
.length
!= 1 || entryPointList
[0].equals("")) {
656 throw new BuildException(
657 "Module type = 'PEI_CORE', only have one module entry point!");
659 fileBuffer
.append("EFI_STATUS\r\n");
660 fileBuffer
.append("EFIAPI\r\n");
661 fileBuffer
.append(entryPointList
[0]);
662 fileBuffer
.append(" (\r\n");
664 .append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n");
666 .append(" IN VOID *OldCoreData\r\n");
667 fileBuffer
.append(" );\r\n\r\n");
669 fileBuffer
.append("EFI_STATUS\r\n");
670 fileBuffer
.append("EFIAPI\r\n");
671 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
673 .append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n");
675 .append(" IN VOID *OldCoreData\r\n");
676 fileBuffer
.append(" )\r\n\r\n");
677 fileBuffer
.append("{\r\n");
678 fileBuffer
.append(" return ");
679 fileBuffer
.append(entryPointList
[0]);
680 fileBuffer
.append(" (PeiStartupDescriptor, OldCoreData);\r\n");
681 fileBuffer
.append("}\r\n\r\n");
685 case CommonDefinition
.ModuleTypeDxeCore
:
686 fileBuffer
.append("const UINT32 _gUefiDriverRevision = 0;\r\n");
687 if (entryPointList
.length
!= 1 || entryPointList
[0].equals("")) {
688 throw new BuildException(
689 "Module type = 'DXE_CORE', only have one module entry point!");
692 fileBuffer
.append("VOID\r\n");
693 fileBuffer
.append("EFIAPI\r\n");
694 fileBuffer
.append(entryPointList
[0]);
695 fileBuffer
.append(" (\n");
696 fileBuffer
.append(" IN VOID *HobStart\r\n");
697 fileBuffer
.append(" );\r\n\r\n");
699 fileBuffer
.append("VOID\r\n");
700 fileBuffer
.append("EFIAPI\r\n");
701 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
702 fileBuffer
.append(" IN VOID *HobStart\r\n");
703 fileBuffer
.append(" )\r\n\r\n");
704 fileBuffer
.append("{\r\n");
705 fileBuffer
.append(" ");
706 fileBuffer
.append(entryPointList
[0]);
707 fileBuffer
.append(" (HobStart);\r\n");
708 fileBuffer
.append("}\r\n\r\n");
712 case CommonDefinition
.ModuleTypePeim
:
713 int entryPointCount
= 0;
715 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = 0;\r\n");
716 for (int i
= 0; i
< entryPointList
.length
; i
++) {
717 if (!entryPointList
[i
].equals("")) {
718 fileBuffer
.append("EFI_STATUS\r\n");
719 fileBuffer
.append("EFIAPI\r\n");
720 fileBuffer
.append(entryPointList
[i
]);
721 fileBuffer
.append(" (\r\n");
723 .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
725 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
726 fileBuffer
.append(" );\r\n");
733 fileBuffer
.append("EFI_STATUS\r\n");
734 fileBuffer
.append("EFIAPI\r\n");
735 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
736 fileBuffer
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
737 fileBuffer
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
738 fileBuffer
.append(" )\r\n\r\n");
739 fileBuffer
.append("{\r\n");
741 if (entryPointCount
== 0) {
742 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
743 } else if (entryPointCount
== 1) {
744 fileBuffer
.append(" return ");
745 fileBuffer
.append(entryPointList
[0]);
746 fileBuffer
.append(" (FfsHeader, PeiServices);\r\n");
748 fileBuffer
.append(" EFI_STATUS Status;\r\n");
749 fileBuffer
.append(" EFI_STATUS CombinedStatus;\r\n\r\n");
750 fileBuffer
.append(" CombinedStatus = EFI_LOAD_ERROR;\r\n\r\n");
751 for (int i
= 0; i
< entryPointList
.length
; i
++) {
752 if (!entryPointList
[i
].equals("")) {
753 fileBuffer
.append(" Status = ");
754 fileBuffer
.append(entryPointList
[i
]);
755 fileBuffer
.append(" (FfsHeader, PeiServices)\r\n");
757 .append(" if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {\r\n");
758 fileBuffer
.append(" CombinedStatus = Status;\r\n");
759 fileBuffer
.append(" }\r\n\r\n");
764 fileBuffer
.append(" return CombinedStatus;\r\n");
766 fileBuffer
.append("}\r\n\r\n");
769 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
771 for (int i
= 0; i
< entryPointList
.length
; i
++) {
772 if (!entryPointList
[i
].equals("")) {
773 fileBuffer
.append("EFI_STATUS\r\n");
774 fileBuffer
.append("EFIAPI\r\n");
775 fileBuffer
.append(entryPointList
[i
]);
776 fileBuffer
.append(" (\r\n");
777 fileBuffer
.append(" EFI_HANDLE ImageHandle,\r\n");
778 fileBuffer
.append(" EFI_SYSTEM_TABLE *SystemTable\r\n");
779 fileBuffer
.append(" );\r\n");
786 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
787 fileBuffer
.append(Integer
.toString(entryPointCount
));
788 fileBuffer
.append(";\r\n");
790 .append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");
792 .append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n\r\n");
794 fileBuffer
.append("EFI_STATUS\r\n");
795 fileBuffer
.append("EFIAPI\r\n");
796 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
797 fileBuffer
.append(" EFI_HANDLE ImageHandle,\r\n");
798 fileBuffer
.append(" EFI_SYSTEM_TABLE *SystemTable\r\n");
799 fileBuffer
.append(" )\r\n\r\n");
800 fileBuffer
.append("{\r\n");
802 for (int i
= 0; i
< entryPointList
.length
; i
++) {
803 if (!entryPointList
[i
].equals("")) {
805 .append(" if (SetJump (&mJumpContext) == 0) {\r\n");
806 fileBuffer
.append(" ExitDriver (");
807 fileBuffer
.append(entryPointList
[i
]);
808 fileBuffer
.append(" (ImageHandle, SystemTable));\r\n");
809 fileBuffer
.append(" ASSERT (FALSE);\r\n");
810 fileBuffer
.append(" }\r\n");
815 fileBuffer
.append(" return mDriverEntryPointStatus;\r\n");
816 fileBuffer
.append("}\r\n\r\n");
818 fileBuffer
.append("VOID\r\n");
819 fileBuffer
.append("EFIAPI\r\n");
820 fileBuffer
.append("ExitDriver (\r\n");
821 fileBuffer
.append(" IN EFI_STATUS Status\n");
822 fileBuffer
.append(" )\r\n\r\n");
823 fileBuffer
.append("{\r\n");
825 .append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");
826 fileBuffer
.append(" mDriverEntryPointStatus = Status;\r\n");
827 fileBuffer
.append(" }\r\n");
828 fileBuffer
.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");
829 fileBuffer
.append(" ASSERT (FALSE);\r\n");
830 fileBuffer
.append("}\r\n\r\n");
833 // Add "ModuleUnloadImage" for DxeSmmDriver module type;
835 entryPointList
= SurfaceAreaQuery
.getModuleUnloadImageArray();
837 if (entryPointList
!= null) {
838 for (int i
= 0; i
< entryPointList
.length
; i
++) {
839 if (!entryPointList
[i
].equals("")) {
840 fileBuffer
.append("EFI_STATUS\r\n");
841 fileBuffer
.append("EFIAPI\r\n");
842 fileBuffer
.append(entryPointList
[i
]);
843 fileBuffer
.append(" (\r\n");
845 .append(" EFI_HANDLE ImageHandle\r\n");
846 fileBuffer
.append(" );\r\n");
855 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");
856 fileBuffer
.append(Integer
.toString(entryPointCount
));
857 fileBuffer
.append(";\r\n\r\n");
859 if (entryPointList
!= null) {
860 for (int i
= 0; i
< entryPointList
.length
; i
++) {
861 if (!entryPointList
[i
].equals("")) {
862 fileBuffer
.append("EFI_STATUS\r\n");
863 fileBuffer
.append("EFIAPI\r\n");
864 fileBuffer
.append(entryPointList
[i
]);
865 fileBuffer
.append(" (\r\n");
867 .append(" EFI_HANDLE ImageHandle\r\n");
868 fileBuffer
.append(" );\r\n");
875 fileBuffer
.append("EFI_STATUS\r\n");
876 fileBuffer
.append("EFIAPI\r\n");
877 fileBuffer
.append("ProcessModuleUnloadList (\r\n");
878 fileBuffer
.append(" EFI_HANDLE ImageHandle\r\n");
879 fileBuffer
.append(" )\r\n");
880 fileBuffer
.append("{\r\n");
882 if (entryPointCount
== 0) {
883 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
884 } else if (entryPointCount
== 1) {
885 fileBuffer
.append(" return ");
886 fileBuffer
.append(entryPointList
[0]);
887 fileBuffer
.append("(ImageHandle);\r\n");
889 fileBuffer
.append(" EFI_STATUS Status;\r\n\r\n");
890 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n\r\n");
891 for (int i
= 0; i
< entryPointList
.length
; i
++) {
892 if (!entryPointList
[i
].equals("")) {
893 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
894 fileBuffer
.append(" ");
895 fileBuffer
.append(entryPointList
[i
]);
896 fileBuffer
.append("(ImageHandle);\r\n");
897 fileBuffer
.append(" } else {\r\n");
898 fileBuffer
.append(" Status = ");
899 fileBuffer
.append(entryPointList
[i
]);
900 fileBuffer
.append("(ImageHandle);\r\n");
901 fileBuffer
.append(" }\r\n");
906 fileBuffer
.append(" return Status;\r\n");
908 fileBuffer
.append("}\r\n\r\n");
911 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
912 case CommonDefinition
.ModuleTypeDxeDriver
:
913 case CommonDefinition
.ModuleTypeDxeSalDriver
:
914 case CommonDefinition
.ModuleTypeUefiDriver
:
915 case CommonDefinition
.ModuleTypeUefiApplication
:
917 fileBuffer
.append("const UINT32 _gUefiDriverRevision = 0;\r\n");
918 for (int i
= 0; i
< entryPointList
.length
; i
++) {
919 if (!entryPointList
[i
].equals("")) {
920 fileBuffer
.append("EFI_STATUS\r\n");
921 fileBuffer
.append("EFIAPI\r\n");
922 fileBuffer
.append(entryPointList
[i
]);
923 fileBuffer
.append(" (\r\n");
924 fileBuffer
.append(" EFI_HANDLE ImageHandle,\r\n");
925 fileBuffer
.append(" EFI_SYSTEM_TABLE *SystemTable\r\n");
926 fileBuffer
.append(" );\r\n");
934 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
935 fileBuffer
.append(Integer
.toString(entryPointCount
));
936 fileBuffer
.append(";\r\n");
937 if (entryPointCount
> 1) {
939 .append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");
941 .append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n");
943 fileBuffer
.append("\n");
945 fileBuffer
.append("EFI_STATUS\r\n");
946 fileBuffer
.append("EFIAPI\r\n");
947 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
948 fileBuffer
.append(" EFI_HANDLE ImageHandle,\r\n");
949 fileBuffer
.append(" EFI_SYSTEM_TABLE *SystemTable\r\n");
950 fileBuffer
.append(" )\r\n\r\n");
951 fileBuffer
.append("{\r\n");
953 if (entryPointCount
== 0) {
954 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
955 } else if (entryPointCount
== 1) {
956 fileBuffer
.append(" return (");
957 fileBuffer
.append(entryPointList
[0]);
958 fileBuffer
.append(" (ImageHandle, SystemTable));\r\n");
960 for (int i
= 0; i
< entryPointList
.length
; i
++) {
961 if (!entryPointList
[i
].equals("")) {
963 .append(" if (SetJump (&mJumpContext) == 0) {\r\n");
964 fileBuffer
.append(" ExitDriver (");
965 fileBuffer
.append(entryPointList
[i
]);
966 fileBuffer
.append(" (ImageHandle, SystemTable));\r\n");
967 fileBuffer
.append(" ASSERT (FALSE);\r\n");
968 fileBuffer
.append(" }\r\n");
973 fileBuffer
.append(" return mDriverEntryPointStatus;\r\n");
975 fileBuffer
.append("}\r\n\r\n");
977 fileBuffer
.append("VOID\n");
978 fileBuffer
.append("EFIAPI\n");
979 fileBuffer
.append("ExitDriver (\r\n");
980 fileBuffer
.append(" IN EFI_STATUS Status\n");
981 fileBuffer
.append(" )\r\n\r\n");
982 fileBuffer
.append("{\r\n");
983 if (entryPointCount
<= 1) {
984 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
986 .append(" ProcessLibraryDestructorList (gImageHandle, gST);\r\n");
987 fileBuffer
.append(" }\r\n");
989 .append(" gBS->Exit (gImageHandle, Status, 0, NULL);\r\n");
992 .append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");
993 fileBuffer
.append(" mDriverEntryPointStatus = Status;\r\n");
994 fileBuffer
.append(" }\r\n");
995 fileBuffer
.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");
996 fileBuffer
.append(" ASSERT (FALSE);\r\n");
998 fileBuffer
.append("}\r\n\r\n");
1001 // Add ModuleUnloadImage for DxeDriver and UefiDriver module type.
1003 entryPointList
= SurfaceAreaQuery
.getModuleUnloadImageArray();
1004 entryPointCount
= 0;
1005 if (entryPointList
!= null) {
1006 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1007 if (!entryPointList
[i
].equals("")) {
1008 fileBuffer
.append("EFI_STATUS\r\n");
1009 fileBuffer
.append("EFIAPI\r\n");
1010 fileBuffer
.append(entryPointList
[i
]);
1011 fileBuffer
.append(" (\r\n");
1013 .append(" EFI_HANDLE ImageHandle\r\n");
1014 fileBuffer
.append(" );\r\n");
1023 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");
1024 fileBuffer
.append(Integer
.toString(entryPointCount
));
1025 fileBuffer
.append(";\r\n\r\n");
1027 if (entryPointList
!= null) {
1028 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1029 if (!entryPointList
[i
].equals("")) {
1030 fileBuffer
.append("EFI_STATUS\r\n");
1031 fileBuffer
.append("EFIAPI\r\n");
1032 fileBuffer
.append(entryPointList
[i
]);
1033 fileBuffer
.append(" (\r\n");
1035 .append(" EFI_HANDLE ImageHandle\r\n");
1036 fileBuffer
.append(" );\r\n");
1043 fileBuffer
.append("EFI_STATUS\n");
1044 fileBuffer
.append("EFIAPI\n");
1045 fileBuffer
.append("ProcessModuleUnloadList (\r\n");
1046 fileBuffer
.append(" EFI_HANDLE ImageHandle\r\n");
1047 fileBuffer
.append(" )\r\n");
1048 fileBuffer
.append("{\r\n");
1050 if (entryPointCount
== 0) {
1051 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
1052 } else if (entryPointCount
== 1) {
1053 fileBuffer
.append(" return ");
1054 fileBuffer
.append(entryPointList
[0]);
1055 fileBuffer
.append("(ImageHandle);\r\n");
1057 fileBuffer
.append(" EFI_STATUS Status;\r\n\r\n");
1058 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n\r\n");
1059 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1060 if (!entryPointList
[i
].equals("")) {
1061 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
1062 fileBuffer
.append(" ");
1063 fileBuffer
.append(entryPointList
[i
]);
1064 fileBuffer
.append("(ImageHandle);\r\n");
1065 fileBuffer
.append(" } else {\r\n");
1066 fileBuffer
.append(" Status = ");
1067 fileBuffer
.append(entryPointList
[i
]);
1068 fileBuffer
.append("(ImageHandle);\r\n");
1069 fileBuffer
.append(" }\r\n");
1074 fileBuffer
.append(" return Status;\r\n");
1076 fileBuffer
.append("}\r\n\r\n");
1084 This function gets GUIDs from SPD file accrodeing to <PPIs> information and
1085 write those GUIDs to AutoGen.c.
1087 @param fileBuffer String Buffer for Autogen.c file.
1088 @throws BuildException Guid must set value!
1090 void PpiGuidToAutogenC(StringBuffer fileBuffer
) throws BuildException
{
1091 String
[] cNameGuid
= null;
1092 boolean isEqual
= false;
1094 PPIsDocument
.PPIs
.Ppi
[] ppiList
= SurfaceAreaQuery
.getPpiArray(null);
1095 if (ppiList
!= null) {
1096 for (int i
= 0; i
< ppiList
.length
; i
++) {
1098 for (int j
= 0; j
< this.mPpiList
.size(); j
++) {
1099 if (this.mPpiList
.get(j
).equalsIgnoreCase(
1100 ppiList
[i
].getStringValue())) {
1105 this.mPpiList
.add(ppiList
[i
].getStringValue());
1110 PPIsDocument
.PPIs
.PpiNotify
[] ppiNotifyList
= SurfaceAreaQuery
1111 .getPpiNotifyArray(null);
1112 if (ppiNotifyList
!= null) {
1113 for (int i
= 0; i
< ppiNotifyList
.length
; i
++) {
1115 for (int j
= 0; j
< this.mPpiList
.size(); j
++) {
1116 if (this.mPpiList
.get(j
).equalsIgnoreCase(
1117 ppiNotifyList
[i
].getStringValue())) {
1122 this.mPpiList
.add(ppiNotifyList
[i
].getStringValue());
1127 for (int i
= 0; i
< this.mPpiList
.size(); i
++) {
1128 if (this.mPpiList
.get(i
) != null) {
1129 cNameGuid
= GlobalData
.getPpiInfoGuid(this.mPpiList
.get(i
));
1130 if (cNameGuid
!= null) {
1132 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1133 fileBuffer
.append(cNameGuid
[0]);
1134 fileBuffer
.append(" = { ");
1135 fileBuffer
.append(cNameGuid
[1]);
1136 fileBuffer
.append(" } ;");
1139 throw new BuildException("Guid must set value!");
1145 ProtocolGuidToAutogenc
1147 This function gets GUIDs from SPD file accrodeing to <Protocol>
1148 information and write those GUIDs to AutoGen.c.
1150 @param fileBuffer String Buffer for Autogen.c file.
1151 @throws BuildException Protocol name must set.
1153 void ProtocolGuidToAutogenC(StringBuffer fileBuffer
) throws BuildException
{
1154 String
[] cNameGuid
= null;
1155 boolean isEqual
= false;
1157 ProtocolsDocument
.Protocols
.Protocol
[] protocolList
= SurfaceAreaQuery
1158 .getProtocolArray(null);
1159 if (protocolList
!= null) {
1160 for (int i
= 0; i
< protocolList
.length
; i
++) {
1162 for (int j
= 0; j
< this.mProtocolList
.size(); j
++) {
1163 if (this.mProtocolList
.get(j
).equalsIgnoreCase(
1164 protocolList
[i
].getStringValue())) {
1169 this.mProtocolList
.add(protocolList
[i
].getStringValue());
1175 ProtocolsDocument
.Protocols
.ProtocolNotify
[] protocolNotifyList
= SurfaceAreaQuery
1176 .getProtocolNotifyArray(null);
1177 if (protocolNotifyList
!= null) {
1178 for (int i
= 0; i
< protocolNotifyList
.length
; i
++) {
1180 for (int j
= 0; j
< this.mProtocolList
.size(); j
++) {
1181 if (this.mProtocolList
.get(j
).equalsIgnoreCase(
1182 protocolNotifyList
[i
].getStringValue())) {
1187 this.mProtocolList
.add(protocolNotifyList
[i
]
1193 if (this.mProtocolList
.size() > 0) {
1194 for (int i
= 0; i
< this.mProtocolList
.size(); i
++) {
1195 if (this.mProtocolList
.get(i
) != null) {
1196 cNameGuid
= GlobalData
1197 .getProtocolInfoGuid(this.mProtocolList
.get(i
));
1198 if (cNameGuid
!= null) {
1200 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1201 fileBuffer
.append(cNameGuid
[0]);
1202 fileBuffer
.append(" = { ");
1203 fileBuffer
.append(cNameGuid
[1]);
1204 fileBuffer
.append(" } ;");
1207 throw new BuildException("Protocol name must set!");
1216 This function gets GUIDs from SPD file accrodeing to <Guids> information
1217 and write those GUIDs to AutoGen.c.
1219 @param fileBuffer String Buffer for Autogen.c file.
1222 void GuidGuidToAutogenC(StringBuffer fileBuffer
) {
1223 String
[] cNameGuid
= null;
1224 boolean isEqual
= false;
1225 GuidsDocument
.Guids
.GuidEntry
[] guidList
= SurfaceAreaQuery
1226 .getGuidEntryArray(null);
1228 if (guidList
!= null) {
1229 for (int i
= 0; i
< guidList
.length
; i
++) {
1230 for (int j
= 0; j
< this.mGuidList
.size(); j
++) {
1232 if (this.mGuidList
.get(j
).getCName().equalsIgnoreCase(
1233 guidList
[i
].getCName().toString())) {
1239 this.mGuidList
.add(guidList
[i
]);
1246 for (int i
= 0; i
< this.mGuidList
.size(); i
++) {
1247 if (this.mGuidList
.get(i
).getCName() != null) {
1248 cNameGuid
= GlobalData
.getGuidInfoGuid(this.mGuidList
.get(i
)
1250 if (cNameGuid
!= null) {
1252 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1253 fileBuffer
.append(cNameGuid
[0]);
1254 fileBuffer
.append(" = { ");
1255 fileBuffer
.append(cNameGuid
[1]);
1256 fileBuffer
.append("} ;");
1263 LibInstanceToAutogenC
1265 This function adds dependent library instance to autogen.c,which includeing
1266 library's constructor, destructor, and library dependent ppi, protocol, guid,
1269 @param fileBuffer String buffer for AutoGen.c
1270 @throws BuildException
1272 void LibInstanceToAutogenC(StringBuffer fileBuffer
) throws BuildException
{
1274 boolean isEqual
= false;
1276 String moduleType
= SurfaceAreaQuery
.getModuleType();
1277 List
<String
> libConstructList
= new ArrayList
<String
>();
1278 List
<String
> libDestructList
= new ArrayList
<String
>();
1280 String libConstructName
= null;
1281 String libDestructName
= null;
1282 List
<String
> libraryList
= SurfaceAreaQuery
.getLibraryInstance(
1283 this.arch
, CommonDefinition
.AlwaysConsumed
);
1286 if (libraryList
!= null) {
1288 // Reorder library instance sequence.
1290 AutogenLibOrder libOrder
= new AutogenLibOrder(libraryList
);
1291 List orderList
= libOrder
.orderLibInstance();
1293 if (orderList
!= null) {
1295 // Process library instance one by one.
1297 for (int i
= 0; i
< orderList
.size(); i
++) {
1300 // Get library instance basename.
1302 String libInstanceName
= orderList
.get(i
).toString();
1307 Map
<String
, XmlObject
> libDoc
= GlobalData
1308 .getDoc(libInstanceName
);
1309 SurfaceAreaQuery
.push(libDoc
);
1312 // Get <PPis>, <Protocols>, <Guids> list of this library
1315 PPIsDocument
.PPIs
.Ppi
[] ppiList
= SurfaceAreaQuery
1317 PPIsDocument
.PPIs
.PpiNotify
[] ppiNotifyList
= SurfaceAreaQuery
1318 .getPpiNotifyArray(null);
1319 ProtocolsDocument
.Protocols
.Protocol
[] protocolList
= SurfaceAreaQuery
1320 .getProtocolArray(null);
1321 ProtocolsDocument
.Protocols
.ProtocolNotify
[] protocolNotifyList
= SurfaceAreaQuery
1322 .getProtocolNotifyArray(null);
1323 GuidsDocument
.Guids
.GuidEntry
[] guidList
= SurfaceAreaQuery
1324 .getGuidEntryArray(null);
1327 // Add those ppi, protocol, guid in global ppi, protocol, guid
1330 if (ppiList
!= null) {
1331 for (index
= 0; index
< ppiList
.length
; index
++) {
1333 for (int j
= 0; j
< this.mPpiList
.size(); j
++) {
1334 if (this.mPpiList
.get(j
).equalsIgnoreCase(
1335 ppiList
[index
].getStringValue())) {
1340 this.mPpiList
.add(ppiList
[index
]
1345 if (ppiNotifyList
!= null) {
1346 for (index
= 0; index
< ppiNotifyList
.length
; index
++) {
1348 for (int j
= 0; j
< this.mPpiList
.size(); j
++) {
1349 if (this.mPpiList
.get(j
).equalsIgnoreCase(
1350 ppiNotifyList
[index
]
1351 .getStringValue())) {
1356 this.mPpiList
.add(ppiNotifyList
[index
]
1361 if (protocolList
!= null) {
1362 for (index
= 0; index
< protocolList
.length
; index
++) {
1364 for (int j
= 0; j
< this.mProtocolList
.size(); j
++) {
1365 if (this.mProtocolList
.get(j
)
1368 .getStringValue())) {
1373 this.mProtocolList
.add(protocolList
[index
]
1378 if (protocolNotifyList
!= null) {
1379 for (index
= 0; index
< protocolNotifyList
.length
; index
++) {
1381 for (int j
= 0; j
< this.mProtocolList
.size(); j
++) {
1382 if (this.mProtocolList
.get(j
)
1384 protocolNotifyList
[index
]
1385 .getStringValue())) {
1391 .add(protocolNotifyList
[index
]
1396 if (guidList
!= null) {
1397 for (index
= 0; index
< guidList
.length
; index
++) {
1399 for (int j
= 0; j
< this.mGuidList
.size(); j
++) {
1400 if (this.mGuidList
.get(j
).getCName()
1402 guidList
[index
].getCName())) {
1407 this.mGuidList
.add(guidList
[index
]);
1413 // If not yet parse this library instance's constructor
1414 // element,parse it.
1416 if (!GlobalData
.isHaveLibInstance(libInstanceName
)) {
1417 libConstructName
= SurfaceAreaQuery
1418 .getLibConstructorName();
1419 libDestructName
= SurfaceAreaQuery
1420 .getLibDestructorName();
1422 GlobalData
.setLibInstanceInfo(libInstanceName
,
1423 libConstructName
, libDestructName
);
1425 libConstructName
= GlobalData
1426 .getLibInstanceConstructor(libInstanceName
);
1427 libDestructName
= GlobalData
1428 .getLibInstanceDestructor(libInstanceName
);
1430 SurfaceAreaQuery
.pop();
1432 // Add dependent library instance constructor function.
1434 if (libConstructName
!= null) {
1435 libConstructList
.add(libConstructName
);
1438 // Add dependent library instance destructor fuction.
1440 if (libDestructName
!= null) {
1441 libDestructList
.add(libDestructName
);
1448 // Add library constructor to AutoGen.c
1450 LibConstructorToAutogenC(libConstructList
, moduleType
,
1451 fileBuffer
/* autogenC */);
1453 // Add library destructor to AutoGen.c
1455 LibDestructorToAutogenC(libDestructList
, moduleType
,
1456 fileBuffer
/* autogenC */);
1459 } catch (Exception e
) {
1460 throw new BuildException(e
.getMessage());
1466 LibConstructorToAutogenc
1468 This function writes library constructor list to AutoGen.c. The library
1469 constructor's parameter and return value depend on module type.
1471 @param libInstanceList List of library construct name.
1472 @param moduleType Module type.
1473 @param fileBuffer String buffer for AutoGen.c
1476 void LibConstructorToAutogenC(List
<String
> libInstanceList
,
1477 String moduleType
, StringBuffer fileBuffer
) throws Exception
{
1478 boolean isFirst
= true;
1481 // The library constructor's parameter and return value depend on
1484 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1485 switch (CommonDefinition
.getModuleType(moduleType
)) {
1486 case CommonDefinition
.ModuleTypeBase
:
1487 fileBuffer
.append("RETURN_STATUS\r\n");
1488 fileBuffer
.append(libInstanceList
.get(i
));
1489 fileBuffer
.append(" (\r\n");
1490 fileBuffer
.append(" VOID\r\n");
1491 fileBuffer
.append(" );\r\n");
1494 case CommonDefinition
.ModuleTypePeiCore
:
1495 case CommonDefinition
.ModuleTypePeim
:
1496 fileBuffer
.append("EFI_STATUS\r\n");
1497 fileBuffer
.append(libInstanceList
.get(i
));
1498 fileBuffer
.append(" (\r\n");
1500 .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1502 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1503 fileBuffer
.append(" );\r\n");
1506 case CommonDefinition
.ModuleTypeDxeCore
:
1507 case CommonDefinition
.ModuleTypeDxeDriver
:
1508 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1509 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1510 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1511 case CommonDefinition
.ModuleTypeUefiDriver
:
1512 case CommonDefinition
.ModuleTypeUefiApplication
:
1513 fileBuffer
.append("EFI_STATUS\r\n");
1514 fileBuffer
.append(libInstanceList
.get(i
));
1515 fileBuffer
.append(" (\r\n");
1516 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1517 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1518 fileBuffer
.append(" );\r\n");
1524 // Add ProcessLibraryConstructorList in AutoGen.c
1526 fileBuffer
.append("VOID\r\n");
1527 fileBuffer
.append("ProcessLibraryConstructorList (\r\n");
1528 switch (CommonDefinition
.getModuleType(moduleType
)) {
1529 case CommonDefinition
.ModuleTypeBase
:
1530 fileBuffer
.append(" VOID\r\n");
1533 case CommonDefinition
.ModuleTypePeiCore
:
1534 case CommonDefinition
.ModuleTypePeim
:
1535 fileBuffer
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1537 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1540 case CommonDefinition
.ModuleTypeDxeCore
:
1541 case CommonDefinition
.ModuleTypeDxeDriver
:
1542 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1543 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1544 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1545 case CommonDefinition
.ModuleTypeUefiDriver
:
1546 case CommonDefinition
.ModuleTypeUefiApplication
:
1547 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1548 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1552 fileBuffer
.append(" )\r\n");
1553 fileBuffer
.append("{\r\n");
1555 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1557 fileBuffer
.append(" EFI_STATUS Status;\r\n");
1558 fileBuffer
.append("\r\n");
1561 switch (CommonDefinition
.getModuleType(moduleType
)) {
1562 case CommonDefinition
.ModuleTypeBase
:
1563 fileBuffer
.append(" Status = ");
1564 fileBuffer
.append(libInstanceList
.get(i
));
1565 fileBuffer
.append("();\r\n");
1566 fileBuffer
.append(" VOID\r\n");
1568 case CommonDefinition
.ModuleTypePeiCore
:
1569 case CommonDefinition
.ModuleTypePeim
:
1570 fileBuffer
.append(" Status = ");
1571 fileBuffer
.append(libInstanceList
.get(i
));
1572 fileBuffer
.append(" (FfsHeader, PeiServices);\r\n");
1574 case CommonDefinition
.ModuleTypeDxeCore
:
1575 case CommonDefinition
.ModuleTypeDxeDriver
:
1576 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1577 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1578 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1579 case CommonDefinition
.ModuleTypeUefiDriver
:
1580 case CommonDefinition
.ModuleTypeUefiApplication
:
1581 fileBuffer
.append(" Status = ");
1582 fileBuffer
.append(libInstanceList
.get(i
));
1583 fileBuffer
.append(" (ImageHandle, SystemTable);\r\n");
1586 fileBuffer
.append(" ASSERT_EFI_ERROR (Status);\r\n");
1588 fileBuffer
.append("}\r\n");
1592 LibDestructorToAutogenc
1594 This function writes library destructor list to AutoGen.c. The library
1595 destructor's parameter and return value depend on module type.
1597 @param libInstanceList List of library destructor name.
1598 @param moduleType Module type.
1599 @param fileBuffer String buffer for AutoGen.c
1602 void LibDestructorToAutogenC(List
<String
> libInstanceList
,
1603 String moduleType
, StringBuffer fileBuffer
) throws Exception
{
1604 boolean isFirst
= true;
1605 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1606 switch (CommonDefinition
.getModuleType(moduleType
)) {
1607 case CommonDefinition
.ModuleTypeBase
:
1608 fileBuffer
.append("RETURN_STATUS\n");
1609 fileBuffer
.append(libInstanceList
.get(i
));
1610 fileBuffer
.append(" (\r\n");
1611 fileBuffer
.append(" VOID\r\n");
1612 fileBuffer
.append(" );\r\n");
1614 case CommonDefinition
.ModuleTypePeiCore
:
1615 case CommonDefinition
.ModuleTypePeim
:
1616 fileBuffer
.append("EFI_STATUS\r\n");
1617 fileBuffer
.append(libInstanceList
.get(i
));
1618 fileBuffer
.append(" (\r\n");
1620 .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1622 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1623 fileBuffer
.append(" );\r\n");
1625 case CommonDefinition
.ModuleTypeDxeCore
:
1626 case CommonDefinition
.ModuleTypeDxeDriver
:
1627 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1628 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1629 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1630 case CommonDefinition
.ModuleTypeUefiDriver
:
1631 case CommonDefinition
.ModuleTypeUefiApplication
:
1632 fileBuffer
.append("EFI_STATUS\r\n");
1633 fileBuffer
.append(libInstanceList
.get(i
));
1634 fileBuffer
.append(" (\r\n");
1635 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1636 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1637 fileBuffer
.append(" );\r\n");
1643 // Write ProcessLibraryDestructor list to autogen.c
1645 switch (CommonDefinition
.getModuleType(moduleType
)) {
1646 case CommonDefinition
.ModuleTypeBase
:
1647 case CommonDefinition
.ModuleTypePeiCore
:
1648 case CommonDefinition
.ModuleTypePeim
:
1650 case CommonDefinition
.ModuleTypeDxeCore
:
1651 case CommonDefinition
.ModuleTypeDxeDriver
:
1652 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1653 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1654 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1655 case CommonDefinition
.ModuleTypeUefiDriver
:
1656 case CommonDefinition
.ModuleTypeUefiApplication
:
1657 fileBuffer
.append("VOID\r\n");
1658 fileBuffer
.append("ProcessLibraryDestructorList (\r\n");
1659 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1660 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1661 fileBuffer
.append(" )\r\n");
1662 fileBuffer
.append("{\r\n");
1664 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1666 fileBuffer
.append(" EFI_STATUS Status;\r\n");
1667 fileBuffer
.append("\r\n");
1670 fileBuffer
.append(" Status = ");
1671 fileBuffer
.append(libInstanceList
.get(i
));
1672 fileBuffer
.append("(ImageHandle, SystemTable);\r\n");
1673 fileBuffer
.append(" ASSERT_EFI_ERROR (Status);\r\n");
1675 fileBuffer
.append("}\r\n");
1681 ExternsDriverBindingToAutoGenC
1683 This function is to write DRIVER_BINDING, COMPONENT_NAME,
1684 DRIVER_CONFIGURATION, DRIVER_DIAGNOSTIC in AutoGen.c.
1686 @param fileBuffer String buffer for AutoGen.c
1688 void ExternsDriverBindingToAutoGenC(StringBuffer fileBuffer
)
1689 throws BuildException
{
1692 // Check what <extern> contains. And the number of following elements
1693 // under <extern> should be same. 1. DRIVER_BINDING 2. COMPONENT_NAME
1694 // 3.DRIVER_CONFIGURATION 4. DRIVER_DIAGNOSTIC
1697 String
[] drvBindList
= SurfaceAreaQuery
.getDriverBindingArray();
1700 // If component name protocol,component configuration protocol,
1701 // component diagnostic protocol is not null or empty, check
1702 // if every one have the same number of the driver binding protocol.
1704 if (drvBindList
== null || drvBindList
.length
== 0) {
1708 String
[] compNamList
= SurfaceAreaQuery
.getComponentNameArray();
1709 String
[] compConfList
= SurfaceAreaQuery
.getDriverConfigArray();
1710 String
[] compDiagList
= SurfaceAreaQuery
.getDriverDiagArray();
1715 // Write driver binding protocol extern to autogen.c
1717 for (int i
= 0; i
< drvBindList
.length
; i
++) {
1718 fileBuffer
.append("extern EFI_DRIVER_BINDING_PROTOCOL ");
1719 fileBuffer
.append(drvBindList
[i
]);
1720 fileBuffer
.append(";\r\n");
1724 // Write component name protocol extern to autogen.c
1726 if (compNamList
!= null && compNamList
.length
!= 0) {
1727 if (drvBindList
.length
!= compNamList
.length
) {
1728 throw new BuildException(
1729 "Different number of Driver Binding and Component Name protocols!");
1733 for (int i
= 0; i
< compNamList
.length
; i
++) {
1734 fileBuffer
.append("extern EFI_COMPONENT_NAME_PROTOCOL ");
1735 fileBuffer
.append(compNamList
[i
]);
1736 fileBuffer
.append(";\r\n");
1741 // Write driver configration protocol extern to autogen.c
1743 if (compConfList
!= null && compConfList
.length
!= 0) {
1744 if (drvBindList
.length
!= compConfList
.length
) {
1745 throw new BuildException(
1746 "Different number of Driver Binding and Driver Configuration protocols!");
1750 for (int i
= 0; i
< compConfList
.length
; i
++) {
1751 fileBuffer
.append("extern EFI_DRIVER_CONFIGURATION_PROTOCOL ");
1752 fileBuffer
.append(compConfList
[i
]);
1753 fileBuffer
.append(";\r\n");
1758 // Write driver dignastic protocol extern to autogen.c
1760 if (compDiagList
!= null && compDiagList
.length
!= 0) {
1761 if (drvBindList
.length
!= compDiagList
.length
) {
1762 throw new BuildException(
1763 "Different number of Driver Binding and Driver Configuration protocols!");
1767 for (int i
= 0; i
< compDiagList
.length
; i
++) {
1768 fileBuffer
.append("extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL ");
1769 fileBuffer
.append(compDiagList
[i
]);
1770 fileBuffer
.append(";\r\n");
1775 // Write driver module protocol bitmask.
1778 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverModelProtocolBitmask = ");
1779 fileBuffer
.append(Integer
.toString(BitMask
));
1780 fileBuffer
.append(";\r\n");
1783 // Write driver module protocol list entry
1786 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverModelProtocolListEntries = ");
1788 fileBuffer
.append(Integer
.toString(drvBindList
.length
));
1789 fileBuffer
.append(";\r\n");
1792 // Write drive module protocol list to autogen.c
1795 .append("GLOBAL_REMOVE_IF_UNREFERENCED const EFI_DRIVER_MODEL_PROTOCOL_LIST _gDriverModelProtocolList[] = {");
1796 for (int i
= 0; i
< drvBindList
.length
; i
++) {
1798 fileBuffer
.append(",");
1800 fileBuffer
.append("\r\n {\r\n");
1801 fileBuffer
.append(" &");
1802 fileBuffer
.append(drvBindList
[i
]);
1803 fileBuffer
.append(", \r\n");
1805 if (compNamList
!= null) {
1806 fileBuffer
.append(" &");
1807 fileBuffer
.append(compNamList
[i
]);
1808 fileBuffer
.append(", \r\n");
1810 fileBuffer
.append(" NULL, \r\n");
1813 if (compConfList
!= null) {
1814 fileBuffer
.append(" &");
1815 fileBuffer
.append(compConfList
[i
]);
1816 fileBuffer
.append(", \r\n");
1818 fileBuffer
.append(" NULL, \r\n");
1821 if (compDiagList
!= null) {
1822 fileBuffer
.append(" &");
1823 fileBuffer
.append(compDiagList
[i
]);
1824 fileBuffer
.append(", \r\n");
1826 fileBuffer
.append(" NULL, \r\n");
1828 fileBuffer
.append(" }");
1830 fileBuffer
.append("\r\n};\r\n");
1834 ExternCallBackToAutoGenC
1836 This function adds <SetVirtualAddressMapCallBack> and <ExitBootServicesCallBack>
1837 infomation to AutoGen.c
1839 @param fileBuffer String buffer for AutoGen.c
1840 @throws BuildException
1842 void ExternCallBackToAutoGenC(StringBuffer fileBuffer
)
1843 throws BuildException
{
1844 String
[] setVirtualList
= SurfaceAreaQuery
1845 .getSetVirtualAddressMapCallBackArray();
1846 String
[] exitBootList
= SurfaceAreaQuery
1847 .getExitBootServicesCallBackArray();
1848 String moduleType
= SurfaceAreaQuery
.getModuleType();
1849 boolean UefiOrDxeModule
= false;
1853 switch (CommonDefinition
.getModuleType(moduleType
)) {
1854 case CommonDefinition
.ModuleTypeDxeDriver
:
1855 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1856 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1857 case CommonDefinition
.ModuleTypeUefiDriver
:
1858 case CommonDefinition
.ModuleTypeUefiApplication
:
1860 // Entry point lib for these module types needs to know the count
1863 UefiOrDxeModule
= true;
1865 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverSetVirtualAddressMapEventCount = ");
1868 // If the list is not valid or has no entries set count to zero else
1869 // set count to the number of valid entries
1872 if (setVirtualList
!= null) {
1873 for (i
= 0; i
< setVirtualList
.length
; i
++) {
1874 if (setVirtualList
[i
].equalsIgnoreCase("")) {
1881 fileBuffer
.append(Integer
.toString(Count
));
1882 fileBuffer
.append(";\r\n\r\n");
1888 if (setVirtualList
== null) {
1889 if (UefiOrDxeModule
) {
1891 // No data so make a NULL list
1894 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {\r\n");
1895 fileBuffer
.append(" NULL\r\n");
1896 fileBuffer
.append("};\r\n\r\n");
1900 // Write SetVirtualAddressMap function definition.
1902 for (i
= 0; i
< setVirtualList
.length
; i
++) {
1903 if (setVirtualList
[i
].equalsIgnoreCase("")) {
1906 fileBuffer
.append("VOID\r\n");
1907 fileBuffer
.append("EFIAPI\n");
1908 fileBuffer
.append(setVirtualList
[i
]);
1909 fileBuffer
.append(" (\r\n");
1910 fileBuffer
.append(" IN EFI_EVENT Event,\r\n");
1911 fileBuffer
.append(" IN VOID *Context\r\n");
1912 fileBuffer
.append(" );\r\n\r\n");
1916 // Write SetVirtualAddressMap entry point array.
1919 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {");
1920 for (i
= 0; i
< setVirtualList
.length
; i
++) {
1921 if (setVirtualList
[i
].equalsIgnoreCase("")) {
1926 fileBuffer
.append("\r\n ");
1928 fileBuffer
.append(",\r\n ");
1931 fileBuffer
.append(setVirtualList
[i
]);
1934 fileBuffer
.append("\r\n NULL");
1936 fileBuffer
.append("\r\n};\r\n\r\n");
1939 if (UefiOrDxeModule
) {
1941 // Entry point lib for these module types needs to know the count.
1944 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverExitBootServicesEventCount = ");
1947 // If the list is not valid or has no entries set count to zero else
1948 // set count to the number of valid entries.
1951 if (exitBootList
!= null) {
1952 if (setVirtualList
!= null) {
1953 for (i
= 0; i
< exitBootList
.length
; i
++) {
1954 if (exitBootList
[i
].equalsIgnoreCase("")) {
1961 fileBuffer
.append(Integer
.toString(Count
));
1962 fileBuffer
.append(";\r\n\r\n");
1965 if (exitBootList
== null) {
1966 if (UefiOrDxeModule
) {
1968 // No data so make a NULL list.
1971 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {\r\n");
1972 fileBuffer
.append(" NULL\r\n");
1973 fileBuffer
.append("};\r\n\r\n");
1977 // Write DriverExitBootServices function definition.
1979 for (i
= 0; i
< exitBootList
.length
; i
++) {
1980 if (exitBootList
[i
].equalsIgnoreCase("")) {
1984 fileBuffer
.append("VOID\r\n");
1985 fileBuffer
.append("EFIAPI\n");
1986 fileBuffer
.append(exitBootList
[i
]);
1987 fileBuffer
.append(" (\r\n");
1988 fileBuffer
.append(" IN EFI_EVENT Event,\r\n");
1989 fileBuffer
.append(" IN VOID *Context\r\n");
1990 fileBuffer
.append(" );\r\n\r\n");
1994 // Write DriverExitBootServices entry point array.
1997 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {");
1998 for (i
= 0; i
< exitBootList
.length
; i
++) {
1999 if (exitBootList
[i
].equalsIgnoreCase("")) {
2004 fileBuffer
.append("\r\n ");
2006 fileBuffer
.append(",\r\n ");
2008 fileBuffer
.append(exitBootList
[i
]);
2011 fileBuffer
.append("\r\n NULL");
2013 fileBuffer
.append("\r\n};\r\n\r\n");