4 This class is to generate Autogen.h and Autogen.c according to module surface area
5 or library surface area.
7 Copyright (c) 2006, Intel Corporation
8 All rights reserved. This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 package org
.tianocore
.build
.autogen
;
20 import org
.tianocore
.build
.global
.GlobalData
;
21 import org
.tianocore
.build
.global
.Spd
;
22 import org
.tianocore
.build
.global
.SurfaceAreaQuery
;
23 import org
.tianocore
.build
.id
.ModuleIdentification
;
24 import org
.tianocore
.build
.id
.PackageIdentification
;
25 import org
.tianocore
.GuidsDocument
;
26 import org
.tianocore
.LibraryClassDocument
.LibraryClass
;
27 import org
.tianocore
.PPIsDocument
;
28 import org
.tianocore
.ProtocolsDocument
;
29 //import org.tianocore.build.pcd.action.PCDAutoGenAction;
30 import org
.tianocore
.build
.exception
.*;
31 import org
.apache
.tools
.ant
.BuildException
;
32 import org
.apache
.xmlbeans
.XmlObject
;
35 import java
.io
.FileReader
;
36 import java
.io
.FileWriter
;
37 import java
.util
.ArrayList
;
38 import java
.util
.HashSet
;
39 import java
.util
.Iterator
;
40 import java
.util
.List
;
45 * This class is to generate Autogen.h and Autogen.c according to module surface
46 * area or library surface area.
48 public class AutoGen
{
50 // / The output path of Autogen.h and Autogen.c
52 private String outputPath
;
55 // / The base name of module or library.
57 private ModuleIdentification moduleId
;
60 // / The build architecture
65 // / PcdAutogen instance which is used to manage how to generate the PCD
68 // private PCDAutoGenAction myPcdAutogen;
71 // / The protocl list which records in module or library surface area and
72 // / it's dependence on library instance surface area.
74 private Set
<String
> mProtocolList
= new HashSet
<String
>();
77 // / The Ppi list which recorded in module or library surface area and its
78 // / dependency on library instance surface area.
80 private Set
<String
> mPpiList
= new HashSet
<String
>();
83 // / The Guid list which recoreded in module or library surface are and it's
84 // / dependence on library instance surface area.
86 private Set
<String
> mGuidList
= new HashSet
<String
>();
91 * This function mainly initialize some member variable.
94 * Output path of AutoGen file.
98 * Target architecture.
100 public AutoGen(String outputPath
, ModuleIdentification moduleId
, String arch
) {
101 this.outputPath
= outputPath
;
102 this.moduleId
= moduleId
;
110 * This function save the content in stringBuffer to file.
115 * The content of AutoGen file in buffer.
116 * @return "true" successful, "false" failed.
118 private boolean saveFile(String fileName
, StringBuffer fileBuffer
) {
120 File autoGenH
= new File(fileName
);
123 // if the file exists, compare their content
125 if (autoGenH
.exists()) {
126 FileReader fIn
= new FileReader(autoGenH
);
127 char[] oldFileBuffer
= new char[(int) autoGenH
.length()];
128 fIn
.read(oldFileBuffer
, 0, (int) autoGenH
.length());
132 // if we got the same file, don't re-generate it to prevent
133 // sources depending on it from re-building
135 if (fileBuffer
.toString().compareTo(new String(oldFileBuffer
)) == 0) {
139 FileWriter fOut
= new FileWriter(autoGenH
);
140 fOut
.write(fileBuffer
.toString());
142 } catch (Exception e
) {
149 * genAutogen function
151 * This function call libGenAutoGen or moduleGenAutogen function, which
152 * dependence on generate library autogen or module autogen.
154 * @throws BuildException
155 * Failed to creat AutoGen.c & AutoGen.h.
157 public void genAutogen() throws BuildException
{
160 // If outputPath do not exist, create it.
162 File path
= new File(outputPath
);
166 // Check current is library or not, then call the corresponding
169 if (this.moduleId
.isLibrary()) {
175 } catch (Exception e
) {
176 throw new BuildException(
177 "Failed to create AutoGen.c & AutoGen.h!\n"
183 * moduleGenAutogen function
185 * This function generates AutoGen.c & AutoGen.h for module.
187 * @throws BuildException
188 * Faile to create module AutoGen.c & AutoGen.h.
190 void moduleGenAutogen() throws BuildException
{
195 } catch (Exception e
) {
196 throw new BuildException(
197 "Faile to create module AutoGen.c & AutoGen.h!\n"
203 * libGenAutogen function
205 * This function generates AutoGen.c & AutoGen.h for library.
207 * @throws BuildException
208 * Faile to create library AutoGen.c & AutoGen.h
210 void libGenAutogen() throws BuildException
{
214 } catch (Exception e
) {
215 throw new BuildException(
216 "Faile to create library AutoGen.c & AutoGen.h!\n"
224 * This function generates AutoGen.h for module.
226 * @throws BuildException
227 * Failed to generate AutoGen.h.
229 void moduleGenAutogenH() throws AutoGenException
{
231 Set
<String
> libClassIncludeH
;
233 // List<String> headerFileList;
234 Set
<String
> headerFileList
;
236 StringBuffer fileBuffer
= new StringBuffer(8192);
239 // Write Autogen.h header notation
241 fileBuffer
.append(CommonDefinition
.autogenHNotation
);
244 // Add #ifndef ${BaseName}_AUTOGENH
245 // #def ${BseeName}_AUTOGENH
247 fileBuffer
.append("#ifndef " + this.moduleId
.getName().toUpperCase()
249 fileBuffer
.append("#define " + this.moduleId
.getName().toUpperCase()
250 + "_AUTOGENH\r\n\r\n");
253 // Write the specification version and release version at the begine
254 // of autogen.h file.
255 // Note: the specification version and release version should
256 // be got from module surface area instead of hard code by it's
259 moduleType
= SurfaceAreaQuery
.getModuleType();
260 switch (CommonDefinition
.getModuleType(moduleType
)) {
261 case CommonDefinition
.ModuleTypeDxeCore
:
262 case CommonDefinition
.ModuleTypeDxeDriver
:
263 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
264 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
265 case CommonDefinition
.ModuleTypeDxeSalDriver
:
266 case CommonDefinition
.ModuleTypeUefiDriver
:
267 case CommonDefinition
.ModuleTypeUefiApplication
:
268 fileBuffer
.append(CommonDefinition
.autoGenHLine1
);
271 fileBuffer
.append(CommonDefinition
.autoGenHVersionDefault
);
274 switch (CommonDefinition
.getModuleType(moduleType
)) {
275 case CommonDefinition
.ModuleTypeUefiDriver
:
276 case CommonDefinition
.ModuleTypeUefiApplication
:
277 fileBuffer
.append(CommonDefinition
.autoGenHReleaseDefault
);
280 fileBuffer
.append(CommonDefinition
.autoGenHLine2
);
285 // Add "extern int __make_me_compile_correctly;" at begin of
288 fileBuffer
.append(CommonDefinition
.autoGenHbegin
);
291 // Write consumed package's mdouleInfo related .h file to autogen.h
293 // PackageIdentification[] consumedPkgIdList = SurfaceAreaQuery
294 // .getDependencePkg(this.arch);
295 PackageIdentification
[] consumedPkgIdList
= SurfaceAreaQuery
.getDependencePkg(null);
296 if (consumedPkgIdList
!= null) {
297 headerFileList
= depPkgToAutogenH(consumedPkgIdList
, moduleType
);
298 item
= headerFileList
.iterator();
299 while (item
.hasNext()){
300 fileBuffer
.append(item
.next().toString());
305 // Write library class's related *.h file to autogen.h.
307 String
[] libClassList
= SurfaceAreaQuery
308 .getLibraryClasses(CommonDefinition
.AlwaysConsumed
);
309 if (libClassList
!= null) {
310 libClassIncludeH
= LibraryClassToAutogenH(libClassList
);
311 item
= libClassIncludeH
.iterator();
312 while (item
.hasNext()){
313 fileBuffer
.append(item
.next().toString());
317 libClassList
= SurfaceAreaQuery
318 .getLibraryClasses(CommonDefinition
.AlwaysProduced
);
319 if (libClassList
!= null) {
320 libClassIncludeH
= LibraryClassToAutogenH(libClassList
);
321 item
= libClassIncludeH
.iterator();
322 while (item
.hasNext()){
323 fileBuffer
.append(item
.next().toString());
326 fileBuffer
.append("\r\n");
329 // Write PCD autogen information to AutoGen.h.
331 // if (this.myPcdAutogen != null) {
332 // fileBuffer.append(this.myPcdAutogen.OutputH());
336 // Append the #endif at AutoGen.h
338 fileBuffer
.append("#endif\r\n");
341 // Save string buffer content in AutoGen.h.
343 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.h", fileBuffer
)) {
344 throw new BuildException("Failed to generate AutoGen.h !!!");
351 * This function generates AutoGen.c for module.
353 * @throws BuildException
354 * Failed to generate AutoGen.c.
356 void moduleGenAutogenC() throws AutoGenException
{
358 StringBuffer fileBuffer
= new StringBuffer(8192);
360 // Write Autogen.c header notation
362 fileBuffer
.append(CommonDefinition
.autogenCNotation
);
365 // Write #include <AutoGen.h> at beginning of AutoGen.c
367 fileBuffer
.append(CommonDefinition
.includeAutogenH
);
370 // Get the native MSA file infomation. Since before call autogen,
371 // the MSA native <Externs> information were overrided. So before
372 // process <Externs> it should be set the DOC as the Native MSA info.
374 Map
<String
, XmlObject
> doc
= GlobalData
.getNativeMsa(this.moduleId
);
375 SurfaceAreaQuery
.push(doc
);
377 // Write <Extern> DriverBinding/ComponentName/DriverConfiguration/DriverDialog
381 ExternsDriverBindingToAutoGenC(fileBuffer
);
384 // Write DriverExitBootServicesEvent/DriverSetVirtualAddressMapEvent
387 ExternCallBackToAutoGenC(fileBuffer
);
390 // Write EntryPoint to autgoGen.c
392 String
[] entryPointList
= SurfaceAreaQuery
.getModuleEntryPointArray();
393 if (entryPointList
!= null) {
394 EntryPointToAutoGen(entryPointList
, fileBuffer
);
398 // Restore the DOC which include the FPD module info.
400 SurfaceAreaQuery
.pop();
403 // Write Guid to autogen.c
405 String guid
= CommonDefinition
.formatGuidName(SurfaceAreaQuery
.getModuleGuid());
408 .append("GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiCallerIdGuid = {");
410 throw new AutoGenException("Guid value must set!\n");
414 // Formate Guid as ANSI c form.Example:
415 // {0xd2b2b828, 0x826, 0x48a7,{0xb3, 0xdf, 0x98, 0x3c, 0x0, 0x60, 0x24,
419 fileBuffer
.append(guid
);
420 fileBuffer
.append("};\r\n");
423 // Generate library instance consumed protocol, guid, ppi, pcd list.
424 // Save those to this.protocolList, this.ppiList, this.pcdList,
425 // this.guidList. Write Consumed library constructor and desconstuct to
428 LibInstanceToAutogenC(fileBuffer
);
431 // Write consumed ppi, guid, protocol to autogen.c
433 ProtocolGuidToAutogenC(fileBuffer
);
434 PpiGuidToAutogenC(fileBuffer
);
435 GuidGuidToAutogenC(fileBuffer
);
438 // Call pcd autogen. PCDAutoGenAction tool only need module name and
439 // isPcdEmulatedDriver as parameter. Library inherits PCD and module's
440 // PCD information has been collected in FPDParser task by
442 // Note : when PCD image tool ready,
443 // isPCDEmulatedDriver parameter will be removed.
446 // this.myPcdAutogen = new PCDAutoGenAction(moduleId.getName(),
447 // moduleId.getName().equalsIgnoreCase("PcdEmulatorPeim"));
448 // this.myPcdAutogen.execute();
449 // } catch (Exception e) {
450 // throw new BuildException("PCD Autogen failed:" + e.getMessage());
453 // if (this.myPcdAutogen != null) {
454 // fileBuffer.append(this.myPcdAutogen.OutputC());
457 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.c", fileBuffer
)) {
458 throw new BuildException("Failed to generate AutoGen.c !!!");
466 * This function generates AutoGen.h for library.
468 * @throws BuildException
469 * Failed to generate AutoGen.c.
471 void libGenAutogenH() throws AutoGenException
{
473 Set
<String
> libClassIncludeH
;
475 Set
<String
> headerFileList
;
477 StringBuffer fileBuffer
= new StringBuffer(10240);
480 // Write Autogen.h header notation
482 fileBuffer
.append(CommonDefinition
.autogenHNotation
);
485 // Add #ifndef ${BaseName}_AUTOGENH
486 // #def ${BseeName}_AUTOGENH
488 fileBuffer
.append("#ifndef " + this.moduleId
.getName().toUpperCase()
490 fileBuffer
.append("#define " + this.moduleId
.getName().toUpperCase()
491 + "_AUTOGENH\r\n\r\n");
494 // Write EFI_SPECIFICATION_VERSION and EDK_RELEASE_VERSION
495 // to autogen.h file.
496 // Note: the specification version and release version should
497 // be get from module surface area instead of hard code.
499 fileBuffer
.append(CommonDefinition
.autoGenHbegin
);
500 String
[] specList
= SurfaceAreaQuery
.getExternSpecificaiton();
501 for (int i
= 0; i
< specList
.length
; i
++){
502 fileBuffer
.append(CommonDefinition
.marcDefineStr
+ specList
[i
] + "\r\n");
504 // fileBuffer.append(CommonDefinition.autoGenHLine1);
505 // fileBuffer.append(CommonDefinition.autoGenHLine2);
508 // Write consumed package's mdouleInfo related *.h file to autogen.h.
510 moduleType
= SurfaceAreaQuery
.getModuleType();
511 PackageIdentification
[] cosumedPkglist
= SurfaceAreaQuery
512 .getDependencePkg(this.arch
);
513 headerFileList
= depPkgToAutogenH(cosumedPkglist
, moduleType
);
514 item
= headerFileList
.iterator();
515 while (item
.hasNext()){
516 fileBuffer
.append(item
.next().toString());
519 // Write library class's related *.h file to autogen.h
521 String
[] libClassList
= SurfaceAreaQuery
522 .getLibraryClasses(CommonDefinition
.AlwaysConsumed
);
523 if (libClassList
!= null) {
524 libClassIncludeH
= LibraryClassToAutogenH(libClassList
);
525 item
= libClassIncludeH
.iterator();
526 while (item
.hasNext()){
527 fileBuffer
.append(item
.next().toString());
531 libClassList
= SurfaceAreaQuery
532 .getLibraryClasses(CommonDefinition
.AlwaysProduced
);
533 if (libClassList
!= null) {
534 libClassIncludeH
= LibraryClassToAutogenH(libClassList
);
535 item
= libClassIncludeH
.iterator();
536 while (item
.hasNext()){
537 fileBuffer
.append(item
.next().toString());
540 fileBuffer
.append("\r\n");
543 // Write PCD information to library AutoGen.h.
545 // if (this.myPcdAutogen != null) {
546 // fileBuffer.append(this.myPcdAutogen.OutputH());
550 // Append the #endif at AutoGen.h
552 fileBuffer
.append("#endif\r\n");
555 // Save content of string buffer to AutoGen.h file.
557 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.h", fileBuffer
)) {
558 throw new BuildException("Failed to generate AutoGen.h !!!");
565 * This function generates AutoGen.h for library.
567 * @throws BuildException
568 * Failed to generate AutoGen.c.
570 void libGenAutogenC() throws BuildException
{
571 StringBuffer fileBuffer
= new StringBuffer(10240);
574 // Write Autogen.c header notation
576 fileBuffer
.append(CommonDefinition
.autogenCNotation
);
578 fileBuffer
.append(CommonDefinition
.autoGenCLine1
);
579 fileBuffer
.append("\r\n");
582 // Call pcd autogen. PCDAutoGenAction tool only need module name and
583 // isPcdEmulatedDriver as parameter. Library inherit PCD and module's
584 // PCD information has been collected in FPDParser task by
586 // Note : when PCD image tool ready,
587 // isPCDEmulatedDriver parameter will be removed.
590 // this.myPcdAutogen = new PCDAutoGenAction(this.moduleId.getName(),
591 // this.moduleId.getName().equalsIgnoreCase("PcdEmulatorPeim"));
592 // this.myPcdAutogen.execute();
593 // this.myPcdAutogen = new PCDAutoGenAction(this.moduleId,);
594 } catch (Exception e
) {
595 throw new BuildException(e
.getMessage());
598 // if (this.myPcdAutogen != null) {
599 // fileBuffer.append(this.myPcdAutogen.OutputC());
602 if (!saveFile(outputPath
+ File
.separatorChar
+ "AutoGen.c", fileBuffer
)) {
603 throw new BuildException("Failed to generate AutoGen.c !!!");
608 * LibraryClassToAutogenH
610 * This function returns *.h files declared by library classes which are
611 * consumed or produced by current build module or library.
613 * @param libClassList
614 * List of library class which consumed or produce by current
615 * build module or library.
616 * @return includeStrList List of *.h file.
618 Set
<String
> LibraryClassToAutogenH(String
[] libClassList
) throws AutoGenException
{
619 Set
<String
> includStrList
= new HashSet
<String
>();
620 String includerName
[];
624 // Get include file from GlobalData's SPDTable according to
625 // library class name.
628 for (int i
= 0; i
< libClassList
.length
; i
++) {
629 includerName
= GlobalData
.getLibraryClassHeaderFiles(
630 SurfaceAreaQuery
.getDependencePkg(this.arch
),
632 if (includerName
== null){
633 throw new AutoGenException("Can not find library class [" + libClassList
[i
] + "] declaration in every packages. ");
635 for (int j
= 0; j
< includerName
.length
; j
++) {
636 String includeNameStr
= includerName
[j
];
637 if (includeNameStr
!= null) {
638 str
= CommonDefinition
.include
+ " " + "<";
639 str
= str
+ includeNameStr
+ ">\r\n";
640 includStrList
.add(str
);
641 includeNameStr
= null;
645 return includStrList
;
651 * This function add include file in AutoGen.h file.
653 * @param packageNameList
654 * List of module depended package.
659 Set
<String
> depPkgToAutogenH(PackageIdentification
[] packageNameList
,
660 String moduleType
) throws AutoGenException
{
662 Set
<String
> includeStrList
= new HashSet
<String
>();
664 String includeStr
= "";
667 // Get include file from moduleInfo file
669 for (int i
= 0; i
< packageNameList
.length
; i
++){
670 // pkgHeader = GlobalData.getPackageHeaderFiles(packageNameList[i], moduleType);
671 // if (pkgHeader == null){
672 // throw new AutoGenException("Can not find package [" + packageNameList[i] + "] declaration in every packages. ");
673 // }else if (!pkgHeader.equalsIgnoreCase("")){
674 // includeStr = CommonDefinition.include + "<" + pkgHeader + ">\r\n";
675 // includeStrList.add(includeStr);
679 return includeStrList
;
683 * EntryPointToAutoGen
685 * This function convert <ModuleEntryPoint> & <ModuleUnloadImage>
686 * information in mas to AutoGen.c
688 * @param entryPointList
689 * List of entry point.
691 * String buffer fo AutoGen.c.
694 void EntryPointToAutoGen(String
[] entryPointList
, StringBuffer fileBuffer
)
695 throws BuildException
{
697 String typeStr
= SurfaceAreaQuery
.getModuleType();
700 // The parameters and return value of entryPoint is difference
701 // for difference module type.
703 switch (CommonDefinition
.getModuleType(typeStr
)) {
705 case CommonDefinition
.ModuleTypePeiCore
:
706 if (entryPointList
.length
!= 1 || entryPointList
[0].equals("")) {
707 throw new BuildException(
708 "Module type = 'PEI_CORE', only have one module entry point!");
710 fileBuffer
.append("EFI_STATUS\r\n");
711 fileBuffer
.append("EFIAPI\r\n");
712 fileBuffer
.append(entryPointList
[0]);
713 fileBuffer
.append(" (\r\n");
715 .append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n");
717 .append(" IN VOID *OldCoreData\r\n");
718 fileBuffer
.append(" );\r\n\r\n");
720 fileBuffer
.append("EFI_STATUS\r\n");
721 fileBuffer
.append("EFIAPI\r\n");
722 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
724 .append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n");
726 .append(" IN VOID *OldCoreData\r\n");
727 fileBuffer
.append(" )\r\n\r\n");
728 fileBuffer
.append("{\r\n");
729 fileBuffer
.append(" return ");
730 fileBuffer
.append(entryPointList
[0]);
731 fileBuffer
.append(" (PeiStartupDescriptor, OldCoreData);\r\n");
732 fileBuffer
.append("}\r\n\r\n");
736 case CommonDefinition
.ModuleTypeDxeCore
:
737 fileBuffer
.append("const UINT32 _gUefiDriverRevision = 0;\r\n");
738 if (entryPointList
.length
!= 1 || entryPointList
[0].equals("")) {
739 throw new BuildException(
740 "Module type = 'DXE_CORE', only have one module entry point!");
743 fileBuffer
.append("VOID\r\n");
744 fileBuffer
.append("EFIAPI\r\n");
745 fileBuffer
.append(entryPointList
[0]);
746 fileBuffer
.append(" (\n");
747 fileBuffer
.append(" IN VOID *HobStart\r\n");
748 fileBuffer
.append(" );\r\n\r\n");
750 fileBuffer
.append("VOID\r\n");
751 fileBuffer
.append("EFIAPI\r\n");
752 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
753 fileBuffer
.append(" IN VOID *HobStart\r\n");
754 fileBuffer
.append(" )\r\n\r\n");
755 fileBuffer
.append("{\r\n");
756 fileBuffer
.append(" ");
757 fileBuffer
.append(entryPointList
[0]);
758 fileBuffer
.append(" (HobStart);\r\n");
759 fileBuffer
.append("}\r\n\r\n");
763 case CommonDefinition
.ModuleTypePeim
:
764 int entryPointCount
= 0;
766 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = 0;\r\n");
767 for (int i
= 0; i
< entryPointList
.length
; i
++) {
768 if (!entryPointList
[i
].equals("")) {
769 fileBuffer
.append("EFI_STATUS\r\n");
770 fileBuffer
.append("EFIAPI\r\n");
771 fileBuffer
.append(entryPointList
[i
]);
772 fileBuffer
.append(" (\r\n");
774 .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
776 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
777 fileBuffer
.append(" );\r\n");
784 fileBuffer
.append("EFI_STATUS\r\n");
785 fileBuffer
.append("EFIAPI\r\n");
786 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
787 fileBuffer
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
788 fileBuffer
.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
789 fileBuffer
.append(" )\r\n\r\n");
790 fileBuffer
.append("{\r\n");
792 if (entryPointCount
== 0) {
793 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
794 } else if (entryPointCount
== 1) {
795 fileBuffer
.append(" return ");
796 fileBuffer
.append(entryPointList
[0]);
797 fileBuffer
.append(" (FfsHeader, PeiServices);\r\n");
799 fileBuffer
.append(" EFI_STATUS Status;\r\n");
800 fileBuffer
.append(" EFI_STATUS CombinedStatus;\r\n\r\n");
801 fileBuffer
.append(" CombinedStatus = EFI_LOAD_ERROR;\r\n\r\n");
802 for (int i
= 0; i
< entryPointList
.length
; i
++) {
803 if (!entryPointList
[i
].equals("")) {
804 fileBuffer
.append(" Status = ");
805 fileBuffer
.append(entryPointList
[i
]);
806 fileBuffer
.append(" (FfsHeader, PeiServices);\r\n");
808 .append(" if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {\r\n");
809 fileBuffer
.append(" CombinedStatus = Status;\r\n");
810 fileBuffer
.append(" }\r\n\r\n");
815 fileBuffer
.append(" return CombinedStatus;\r\n");
817 fileBuffer
.append("}\r\n\r\n");
820 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
822 for (int i
= 0; i
< entryPointList
.length
; i
++) {
823 if (!entryPointList
[i
].equals("")) {
824 fileBuffer
.append("EFI_STATUS\r\n");
825 fileBuffer
.append("EFIAPI\r\n");
826 fileBuffer
.append(entryPointList
[i
]);
827 fileBuffer
.append(" (\r\n");
828 fileBuffer
.append(" EFI_HANDLE ImageHandle,\r\n");
829 fileBuffer
.append(" EFI_SYSTEM_TABLE *SystemTable\r\n");
830 fileBuffer
.append(" );\r\n");
837 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
838 fileBuffer
.append(Integer
.toString(entryPointCount
));
839 fileBuffer
.append(";\r\n");
841 .append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");
843 .append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n\r\n");
845 fileBuffer
.append("EFI_STATUS\r\n");
846 fileBuffer
.append("EFIAPI\r\n");
847 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
848 fileBuffer
.append(" EFI_HANDLE ImageHandle,\r\n");
849 fileBuffer
.append(" EFI_SYSTEM_TABLE *SystemTable\r\n");
850 fileBuffer
.append(" )\r\n\r\n");
851 fileBuffer
.append("{\r\n");
853 for (int i
= 0; i
< entryPointList
.length
; i
++) {
854 if (!entryPointList
[i
].equals("")) {
856 .append(" if (SetJump (&mJumpContext) == 0) {\r\n");
857 fileBuffer
.append(" ExitDriver (");
858 fileBuffer
.append(entryPointList
[i
]);
859 fileBuffer
.append(" (ImageHandle, SystemTable));\r\n");
860 fileBuffer
.append(" ASSERT (FALSE);\r\n");
861 fileBuffer
.append(" }\r\n");
866 fileBuffer
.append(" return mDriverEntryPointStatus;\r\n");
867 fileBuffer
.append("}\r\n\r\n");
869 fileBuffer
.append("VOID\r\n");
870 fileBuffer
.append("EFIAPI\r\n");
871 fileBuffer
.append("ExitDriver (\r\n");
872 fileBuffer
.append(" IN EFI_STATUS Status\n");
873 fileBuffer
.append(" )\r\n\r\n");
874 fileBuffer
.append("{\r\n");
876 .append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");
877 fileBuffer
.append(" mDriverEntryPointStatus = Status;\r\n");
878 fileBuffer
.append(" }\r\n");
879 fileBuffer
.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");
880 fileBuffer
.append(" ASSERT (FALSE);\r\n");
881 fileBuffer
.append("}\r\n\r\n");
884 // Add "ModuleUnloadImage" for DxeSmmDriver module type;
886 entryPointList
= SurfaceAreaQuery
.getModuleUnloadImageArray();
890 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");
891 fileBuffer
.append(Integer
.toString(entryPointCount
));
892 fileBuffer
.append(";\r\n\r\n");
894 if (entryPointList
!= null) {
895 for (int i
= 0; i
< entryPointList
.length
; i
++) {
896 if (!entryPointList
[i
].equals("")) {
897 fileBuffer
.append("EFI_STATUS\r\n");
898 fileBuffer
.append("EFIAPI\r\n");
899 fileBuffer
.append(entryPointList
[i
]);
900 fileBuffer
.append(" (\r\n");
902 .append(" EFI_HANDLE ImageHandle\r\n");
903 fileBuffer
.append(" );\r\n");
910 fileBuffer
.append("EFI_STATUS\r\n");
911 fileBuffer
.append("EFIAPI\r\n");
912 fileBuffer
.append("ProcessModuleUnloadList (\r\n");
913 fileBuffer
.append(" EFI_HANDLE ImageHandle\r\n");
914 fileBuffer
.append(" )\r\n");
915 fileBuffer
.append("{\r\n");
917 if (entryPointCount
== 0) {
918 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
919 } else if (entryPointCount
== 1) {
920 fileBuffer
.append(" return ");
921 fileBuffer
.append(entryPointList
[0]);
922 fileBuffer
.append("(ImageHandle);\r\n");
924 fileBuffer
.append(" EFI_STATUS Status;\r\n\r\n");
925 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n\r\n");
926 for (int i
= 0; i
< entryPointList
.length
; i
++) {
927 if (!entryPointList
[i
].equals("")) {
928 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
929 fileBuffer
.append(" ");
930 fileBuffer
.append(entryPointList
[i
]);
931 fileBuffer
.append("(ImageHandle);\r\n");
932 fileBuffer
.append(" } else {\r\n");
933 fileBuffer
.append(" Status = ");
934 fileBuffer
.append(entryPointList
[i
]);
935 fileBuffer
.append("(ImageHandle);\r\n");
936 fileBuffer
.append(" }\r\n");
941 fileBuffer
.append(" return Status;\r\n");
943 fileBuffer
.append("}\r\n\r\n");
946 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
947 case CommonDefinition
.ModuleTypeDxeDriver
:
948 case CommonDefinition
.ModuleTypeDxeSalDriver
:
949 case CommonDefinition
.ModuleTypeUefiDriver
:
950 case CommonDefinition
.ModuleTypeUefiApplication
:
952 fileBuffer
.append("const UINT32 _gUefiDriverRevision = 0;\r\n");
953 for (int i
= 0; i
< entryPointList
.length
; i
++) {
954 if (!entryPointList
[i
].equals("")) {
955 fileBuffer
.append("EFI_STATUS\r\n");
956 fileBuffer
.append("EFIAPI\r\n");
957 fileBuffer
.append(entryPointList
[i
]);
958 fileBuffer
.append(" (\r\n");
959 fileBuffer
.append(" EFI_HANDLE ImageHandle,\r\n");
960 fileBuffer
.append(" EFI_SYSTEM_TABLE *SystemTable\r\n");
961 fileBuffer
.append(" );\r\n");
969 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
970 fileBuffer
.append(Integer
.toString(entryPointCount
));
971 fileBuffer
.append(";\r\n");
972 if (entryPointCount
> 1) {
974 .append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");
976 .append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n");
978 fileBuffer
.append("\n");
980 fileBuffer
.append("EFI_STATUS\r\n");
981 fileBuffer
.append("EFIAPI\r\n");
982 fileBuffer
.append("ProcessModuleEntryPointList (\r\n");
983 fileBuffer
.append(" EFI_HANDLE ImageHandle,\r\n");
984 fileBuffer
.append(" EFI_SYSTEM_TABLE *SystemTable\r\n");
985 fileBuffer
.append(" )\r\n\r\n");
986 fileBuffer
.append("{\r\n");
988 if (entryPointCount
== 0) {
989 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
990 } else if (entryPointCount
== 1) {
991 fileBuffer
.append(" return (");
992 fileBuffer
.append(entryPointList
[0]);
993 fileBuffer
.append(" (ImageHandle, SystemTable));\r\n");
995 for (int i
= 0; i
< entryPointList
.length
; i
++) {
996 if (!entryPointList
[i
].equals("")) {
998 .append(" if (SetJump (&mJumpContext) == 0) {\r\n");
999 fileBuffer
.append(" ExitDriver (");
1000 fileBuffer
.append(entryPointList
[i
]);
1001 fileBuffer
.append(" (ImageHandle, SystemTable));\r\n");
1002 fileBuffer
.append(" ASSERT (FALSE);\r\n");
1003 fileBuffer
.append(" }\r\n");
1008 fileBuffer
.append(" return mDriverEntryPointStatus;\r\n");
1010 fileBuffer
.append("}\r\n\r\n");
1012 fileBuffer
.append("VOID\n");
1013 fileBuffer
.append("EFIAPI\n");
1014 fileBuffer
.append("ExitDriver (\r\n");
1015 fileBuffer
.append(" IN EFI_STATUS Status\n");
1016 fileBuffer
.append(" )\r\n\r\n");
1017 fileBuffer
.append("{\r\n");
1018 if (entryPointCount
<= 1) {
1019 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
1021 .append(" ProcessLibraryDestructorList (gImageHandle, gST);\r\n");
1022 fileBuffer
.append(" }\r\n");
1024 .append(" gBS->Exit (gImageHandle, Status, 0, NULL);\r\n");
1027 .append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");
1028 fileBuffer
.append(" mDriverEntryPointStatus = Status;\r\n");
1029 fileBuffer
.append(" }\r\n");
1030 fileBuffer
.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");
1031 fileBuffer
.append(" ASSERT (FALSE);\r\n");
1033 fileBuffer
.append("}\r\n\r\n");
1036 // Add ModuleUnloadImage for DxeDriver and UefiDriver module type.
1038 entryPointList
= SurfaceAreaQuery
.getModuleUnloadImageArray();
1039 entryPointCount
= 0;
1040 if (entryPointList
!= null) {
1041 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1042 if (!entryPointList
[i
].equals("")) {
1043 fileBuffer
.append("EFI_STATUS\r\n");
1044 fileBuffer
.append("EFIAPI\r\n");
1045 fileBuffer
.append(entryPointList
[i
]);
1046 fileBuffer
.append(" (\r\n");
1048 .append(" EFI_HANDLE ImageHandle\r\n");
1049 fileBuffer
.append(" );\r\n");
1058 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");
1059 fileBuffer
.append(Integer
.toString(entryPointCount
));
1060 fileBuffer
.append(";\r\n\r\n");
1062 if (entryPointList
!= null) {
1063 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1064 if (!entryPointList
[i
].equals("")) {
1065 fileBuffer
.append("EFI_STATUS\r\n");
1066 fileBuffer
.append("EFIAPI\r\n");
1067 fileBuffer
.append(entryPointList
[i
]);
1068 fileBuffer
.append(" (\r\n");
1070 .append(" EFI_HANDLE ImageHandle\r\n");
1071 fileBuffer
.append(" );\r\n");
1078 fileBuffer
.append("EFI_STATUS\n");
1079 fileBuffer
.append("EFIAPI\n");
1080 fileBuffer
.append("ProcessModuleUnloadList (\r\n");
1081 fileBuffer
.append(" EFI_HANDLE ImageHandle\r\n");
1082 fileBuffer
.append(" )\r\n");
1083 fileBuffer
.append("{\r\n");
1085 if (entryPointCount
== 0) {
1086 fileBuffer
.append(" return EFI_SUCCESS;\r\n");
1087 } else if (entryPointCount
== 1) {
1088 fileBuffer
.append(" return ");
1089 fileBuffer
.append(entryPointList
[0]);
1090 fileBuffer
.append("(ImageHandle);\r\n");
1092 fileBuffer
.append(" EFI_STATUS Status;\r\n\r\n");
1093 fileBuffer
.append(" Status = EFI_SUCCESS;\r\n\r\n");
1094 for (int i
= 0; i
< entryPointList
.length
; i
++) {
1095 if (!entryPointList
[i
].equals("")) {
1096 fileBuffer
.append(" if (EFI_ERROR (Status)) {\r\n");
1097 fileBuffer
.append(" ");
1098 fileBuffer
.append(entryPointList
[i
]);
1099 fileBuffer
.append("(ImageHandle);\r\n");
1100 fileBuffer
.append(" } else {\r\n");
1101 fileBuffer
.append(" Status = ");
1102 fileBuffer
.append(entryPointList
[i
]);
1103 fileBuffer
.append("(ImageHandle);\r\n");
1104 fileBuffer
.append(" }\r\n");
1109 fileBuffer
.append(" return Status;\r\n");
1111 fileBuffer
.append("}\r\n\r\n");
1119 * This function gets GUIDs from SPD file accrodeing to <PPIs> information
1120 * and write those GUIDs to AutoGen.c.
1123 * String Buffer for Autogen.c file.
1124 * @throws BuildException
1125 * Guid must set value!
1127 void PpiGuidToAutogenC(StringBuffer fileBuffer
) throws AutoGenException
{
1128 String
[] cNameGuid
= null;
1131 // Get the all PPI adn PPI Notify from MSA file,
1132 // then add those PPI ,and PPI Notify name to list.
1134 String
[] ppiList
= SurfaceAreaQuery
.getPpiArray(null);
1135 for (int i
= 0; i
< ppiList
.length
; i
++) {
1136 this.mPpiList
.add(ppiList
[i
]);
1139 String
[] ppiNotifyList
= SurfaceAreaQuery
.getPpiNotifyArray(null);
1140 for (int i
= 0; i
< ppiNotifyList
.length
; i
++) {
1141 this.mPpiList
.add(ppiNotifyList
[i
]);
1145 // Find CNAME and GUID from dependence SPD file and write to Autogen.c
1147 Iterator ppiIterator
= this.mPpiList
.iterator();
1148 String ppiKeyWord
= null;
1149 while (ppiIterator
.hasNext()) {
1150 ppiKeyWord
= ppiIterator
.next().toString();
1151 cNameGuid
= GlobalData
1152 .getPpiGuid(SurfaceAreaQuery
.getDependencePkg(this.arch
),
1154 if (cNameGuid
!= null) {
1156 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1157 fileBuffer
.append(cNameGuid
[0]);
1158 fileBuffer
.append(" = { ");
1159 fileBuffer
.append(cNameGuid
[1]);
1160 fileBuffer
.append(" } ;");
1163 // If can't find Ppi GUID declaration in every package
1165 throw new AutoGenException("Can not find Ppi GUID [" + ppiKeyWord
+ "] declaration in every packages. ");
1171 * ProtocolGuidToAutogenc
1173 * This function gets GUIDs from SPD file accrodeing to <Protocol>
1174 * information and write those GUIDs to AutoGen.c.
1177 * String Buffer for Autogen.c file.
1178 * @throws BuildException
1179 * Protocol name must set.
1181 void ProtocolGuidToAutogenC(StringBuffer fileBuffer
) throws BuildException
{
1182 String
[] cNameGuid
= null;
1184 String
[] protocolList
= SurfaceAreaQuery
.getProtocolArray(this.arch
);
1187 // Add result to Autogen global list.
1189 for (int i
= 0; i
< protocolList
.length
; i
++) {
1190 this.mProtocolList
.add(protocolList
[i
]);
1193 String
[] protocolNotifyList
= SurfaceAreaQuery
1194 .getProtocolNotifyArray(this.arch
);
1196 for (int i
= 0; i
< protocolNotifyList
.length
; i
++) {
1197 this.mProtocolList
.add(protocolNotifyList
[i
]);
1201 // Get the NAME and GUID from dependence SPD and write to Autogen.c
1203 Iterator protocolIterator
= this.mPpiList
.iterator();
1204 String protocolKeyWord
= null;
1205 while (protocolIterator
.hasNext()) {
1206 protocolKeyWord
= protocolIterator
.next().toString();
1207 cNameGuid
= GlobalData
.getProtocolGuid(SurfaceAreaQuery
1208 .getDependencePkg(this.arch
), protocolKeyWord
);
1209 if (cNameGuid
!= null) {
1211 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1212 fileBuffer
.append(cNameGuid
[0]);
1213 fileBuffer
.append(" = { ");
1214 fileBuffer
.append(cNameGuid
[1]);
1215 fileBuffer
.append(" } ;");
1218 // If can't find protocol GUID declaration in every package
1220 throw new BuildException("Can not find protocol Guid [" + cNameGuid
+ "] declaration in every packages. ");
1226 * GuidGuidToAutogenc
1228 * This function gets GUIDs from SPD file accrodeing to <Guids> information
1229 * and write those GUIDs to AutoGen.c.
1232 * String Buffer for Autogen.c file.
1235 void GuidGuidToAutogenC(StringBuffer fileBuffer
) throws AutoGenException
{
1236 String
[] cNameGuid
= null;
1237 String guidKeyWord
= null;
1239 String
[] guidList
= SurfaceAreaQuery
.getGuidEntryArray(this.arch
);
1241 for (int i
= 0; i
< guidList
.length
; i
++) {
1242 this.mGuidList
.add(guidList
[i
]);
1245 Iterator guidIterator
= this.mGuidList
.iterator();
1246 while (guidIterator
.hasNext()) {
1247 guidKeyWord
= guidIterator
.next().toString();
1248 cNameGuid
= GlobalData
.getGuid(SurfaceAreaQuery
1249 .getDependencePkg(this.arch
), guidKeyWord
);
1251 if (cNameGuid
!= null) {
1253 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1254 fileBuffer
.append(cNameGuid
[0]);
1255 fileBuffer
.append(" = { ");
1256 fileBuffer
.append(cNameGuid
[1]);
1257 fileBuffer
.append("} ;");
1260 // If can't find GUID declaration in every package
1262 throw new AutoGenException("Can not find Guid [" + guidKeyWord
+ "] declaration in every packages. ");
1269 * LibInstanceToAutogenC
1271 * This function adds dependent library instance to autogen.c,which
1272 * includeing library's constructor, destructor, and library dependent ppi,
1273 * protocol, guid, pcd information.
1276 * String buffer for AutoGen.c
1277 * @throws BuildException
1279 void LibInstanceToAutogenC(StringBuffer fileBuffer
) throws BuildException
{
1282 String moduleType
= SurfaceAreaQuery
.getModuleType();
1283 List
<String
> libConstructList
= new ArrayList
<String
>();
1284 List
<String
> libDestructList
= new ArrayList
<String
>();
1286 String libConstructName
= null;
1287 String libDestructName
= null;
1288 ModuleIdentification
[] libraryIdList
= SurfaceAreaQuery
.getLibraryInstance(this.arch
);
1291 if (libraryIdList
!= null) {
1293 // Reorder library instance sequence.
1295 AutogenLibOrder libOrder
= new AutogenLibOrder(libraryIdList
, this.arch
);
1296 List
<ModuleIdentification
> orderList
= libOrder
.orderLibInstance();
1298 if (orderList
!= null) {
1300 // Process library instance one by one.
1302 for (int i
= 0; i
< orderList
.size(); i
++) {
1305 // Get library instance basename.
1307 ModuleIdentification libInstanceId
= orderList
.get(i
);
1312 Map
<String
, XmlObject
> libDoc
= GlobalData
1313 .getDoc(libInstanceId
, this.arch
);
1314 SurfaceAreaQuery
.push(libDoc
);
1317 // Get <PPis>, <Protocols>, <Guids> list of this library
1320 String
[] ppiList
= SurfaceAreaQuery
1322 String
[] ppiNotifyList
= SurfaceAreaQuery
1323 .getPpiNotifyArray(null);
1324 String
[] protocolList
= SurfaceAreaQuery
1325 .getProtocolArray(null);
1326 String
[] protocolNotifyList
= SurfaceAreaQuery
1327 .getProtocolNotifyArray(null);
1328 String
[] guidList
= SurfaceAreaQuery
1329 .getGuidEntryArray(null);
1332 // Add those ppi, protocol, guid in global ppi,
1336 for (index
= 0; index
< ppiList
.length
; index
++) {
1337 this.mPpiList
.add(ppiList
[index
]);
1340 for (index
= 0; index
< ppiNotifyList
.length
; index
++) {
1341 this.mPpiList
.add(ppiNotifyList
[index
]);
1344 for (index
= 0; index
< protocolList
.length
; index
++) {
1345 this.mProtocolList
.add(protocolList
[index
]);
1348 for (index
= 0; index
< protocolNotifyList
.length
; index
++) {
1349 this.mProtocolList
.add(protocolNotifyList
[index
]);
1352 for (index
= 0; index
< guidList
.length
; index
++) {
1353 this.mGuidList
.add(guidList
[index
]);
1357 // If not yet parse this library instance's constructor
1358 // element,parse it.
1360 libConstructName
= SurfaceAreaQuery
1361 .getLibConstructorName();
1362 libDestructName
= SurfaceAreaQuery
1363 .getLibDestructorName();
1365 SurfaceAreaQuery
.pop();
1367 // Add dependent library instance constructor function.
1369 if (libConstructName
!= null) {
1370 libConstructList
.add(libConstructName
);
1373 // Add dependent library instance destructor fuction.
1375 if (libDestructName
!= null) {
1376 libDestructList
.add(libDestructName
);
1383 // Add library constructor to AutoGen.c
1385 LibConstructorToAutogenC(libConstructList
, moduleType
,
1386 fileBuffer
/* autogenC */);
1388 // Add library destructor to AutoGen.c
1390 LibDestructorToAutogenC(libDestructList
, moduleType
, fileBuffer
/* autogenC */);
1393 } catch (Exception e
) {
1394 throw new BuildException(e
.getMessage());
1399 * LibConstructorToAutogenc
1401 * This function writes library constructor list to AutoGen.c. The library
1402 * constructor's parameter and return value depend on module type.
1404 * @param libInstanceList
1405 * List of library construct name.
1409 * String buffer for AutoGen.c
1412 void LibConstructorToAutogenC(List
<String
> libInstanceList
,
1413 String moduleType
, StringBuffer fileBuffer
) throws Exception
{
1414 boolean isFirst
= true;
1417 // The library constructor's parameter and return value depend on
1420 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1421 switch (CommonDefinition
.getModuleType(moduleType
)) {
1422 case CommonDefinition
.ModuleTypeBase
:
1423 fileBuffer
.append("RETURN_STATUS\r\n");
1424 fileBuffer
.append(libInstanceList
.get(i
));
1425 fileBuffer
.append(" (\r\n");
1426 fileBuffer
.append(" VOID\r\n");
1427 fileBuffer
.append(" );\r\n");
1430 case CommonDefinition
.ModuleTypePeiCore
:
1431 case CommonDefinition
.ModuleTypePeim
:
1432 fileBuffer
.append("EFI_STATUS\r\n");
1433 fileBuffer
.append(libInstanceList
.get(i
));
1434 fileBuffer
.append(" (\r\n");
1436 .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1438 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1439 fileBuffer
.append(" );\r\n");
1442 case CommonDefinition
.ModuleTypeDxeCore
:
1443 case CommonDefinition
.ModuleTypeDxeDriver
:
1444 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1445 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1446 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1447 case CommonDefinition
.ModuleTypeUefiDriver
:
1448 case CommonDefinition
.ModuleTypeUefiApplication
:
1449 fileBuffer
.append("EFI_STATUS\r\n");
1450 fileBuffer
.append(libInstanceList
.get(i
));
1451 fileBuffer
.append(" (\r\n");
1452 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1453 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1454 fileBuffer
.append(" );\r\n");
1460 // Add ProcessLibraryConstructorList in AutoGen.c
1462 fileBuffer
.append("VOID\r\n");
1463 fileBuffer
.append("ProcessLibraryConstructorList (\r\n");
1464 switch (CommonDefinition
.getModuleType(moduleType
)) {
1465 case CommonDefinition
.ModuleTypeBase
:
1466 fileBuffer
.append(" VOID\r\n");
1469 case CommonDefinition
.ModuleTypePeiCore
:
1470 case CommonDefinition
.ModuleTypePeim
:
1471 fileBuffer
.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1473 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1476 case CommonDefinition
.ModuleTypeDxeCore
:
1477 case CommonDefinition
.ModuleTypeDxeDriver
:
1478 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1479 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1480 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1481 case CommonDefinition
.ModuleTypeUefiDriver
:
1482 case CommonDefinition
.ModuleTypeUefiApplication
:
1483 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1484 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1488 fileBuffer
.append(" )\r\n");
1489 fileBuffer
.append("{\r\n");
1491 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1493 fileBuffer
.append(" EFI_STATUS Status;\r\n");
1494 fileBuffer
.append("\r\n");
1497 switch (CommonDefinition
.getModuleType(moduleType
)) {
1498 case CommonDefinition
.ModuleTypeBase
:
1499 fileBuffer
.append(" Status = ");
1500 fileBuffer
.append(libInstanceList
.get(i
));
1501 fileBuffer
.append("();\r\n");
1502 fileBuffer
.append(" VOID\r\n");
1504 case CommonDefinition
.ModuleTypePeiCore
:
1505 case CommonDefinition
.ModuleTypePeim
:
1506 fileBuffer
.append(" Status = ");
1507 fileBuffer
.append(libInstanceList
.get(i
));
1508 fileBuffer
.append(" (FfsHeader, PeiServices);\r\n");
1510 case CommonDefinition
.ModuleTypeDxeCore
:
1511 case CommonDefinition
.ModuleTypeDxeDriver
:
1512 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1513 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1514 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1515 case CommonDefinition
.ModuleTypeUefiDriver
:
1516 case CommonDefinition
.ModuleTypeUefiApplication
:
1517 fileBuffer
.append(" Status = ");
1518 fileBuffer
.append(libInstanceList
.get(i
));
1519 fileBuffer
.append(" (ImageHandle, SystemTable);\r\n");
1522 fileBuffer
.append(" ASSERT_EFI_ERROR (Status);\r\n");
1524 fileBuffer
.append("}\r\n");
1528 * LibDestructorToAutogenc
1530 * This function writes library destructor list to AutoGen.c. The library
1531 * destructor's parameter and return value depend on module type.
1533 * @param libInstanceList
1534 * List of library destructor name.
1538 * String buffer for AutoGen.c
1541 void LibDestructorToAutogenC(List
<String
> libInstanceList
,
1542 String moduleType
, StringBuffer fileBuffer
) throws Exception
{
1543 boolean isFirst
= true;
1544 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1545 switch (CommonDefinition
.getModuleType(moduleType
)) {
1546 case CommonDefinition
.ModuleTypeBase
:
1547 fileBuffer
.append("RETURN_STATUS\n");
1548 fileBuffer
.append(libInstanceList
.get(i
));
1549 fileBuffer
.append(" (\r\n");
1550 fileBuffer
.append(" VOID\r\n");
1551 fileBuffer
.append(" );\r\n");
1553 case CommonDefinition
.ModuleTypePeiCore
:
1554 case CommonDefinition
.ModuleTypePeim
:
1555 fileBuffer
.append("EFI_STATUS\r\n");
1556 fileBuffer
.append(libInstanceList
.get(i
));
1557 fileBuffer
.append(" (\r\n");
1559 .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1561 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1562 fileBuffer
.append(" );\r\n");
1564 case CommonDefinition
.ModuleTypeDxeCore
:
1565 case CommonDefinition
.ModuleTypeDxeDriver
:
1566 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1567 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1568 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1569 case CommonDefinition
.ModuleTypeUefiDriver
:
1570 case CommonDefinition
.ModuleTypeUefiApplication
:
1571 fileBuffer
.append("EFI_STATUS\r\n");
1572 fileBuffer
.append(libInstanceList
.get(i
));
1573 fileBuffer
.append(" (\r\n");
1574 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1575 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1576 fileBuffer
.append(" );\r\n");
1582 // Write ProcessLibraryDestructor list to autogen.c
1584 switch (CommonDefinition
.getModuleType(moduleType
)) {
1585 case CommonDefinition
.ModuleTypeBase
:
1586 case CommonDefinition
.ModuleTypePeiCore
:
1587 case CommonDefinition
.ModuleTypePeim
:
1589 case CommonDefinition
.ModuleTypeDxeCore
:
1590 case CommonDefinition
.ModuleTypeDxeDriver
:
1591 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1592 case CommonDefinition
.ModuleTypeDxeSmmDriver
:
1593 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1594 case CommonDefinition
.ModuleTypeUefiDriver
:
1595 case CommonDefinition
.ModuleTypeUefiApplication
:
1596 fileBuffer
.append("VOID\r\n");
1597 fileBuffer
.append("ProcessLibraryDestructorList (\r\n");
1598 fileBuffer
.append(" IN EFI_HANDLE ImageHandle,\r\n");
1599 fileBuffer
.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1600 fileBuffer
.append(" )\r\n");
1601 fileBuffer
.append("{\r\n");
1603 for (int i
= 0; i
< libInstanceList
.size(); i
++) {
1605 fileBuffer
.append(" EFI_STATUS Status;\r\n");
1606 fileBuffer
.append("\r\n");
1609 fileBuffer
.append(" Status = ");
1610 fileBuffer
.append(libInstanceList
.get(i
));
1611 fileBuffer
.append("(ImageHandle, SystemTable);\r\n");
1612 fileBuffer
.append(" ASSERT_EFI_ERROR (Status);\r\n");
1614 fileBuffer
.append("}\r\n");
1620 * ExternsDriverBindingToAutoGenC
1622 * This function is to write DRIVER_BINDING, COMPONENT_NAME,
1623 * DRIVER_CONFIGURATION, DRIVER_DIAGNOSTIC in AutoGen.c.
1626 * String buffer for AutoGen.c
1628 void ExternsDriverBindingToAutoGenC(StringBuffer fileBuffer
)
1629 throws BuildException
{
1632 // Check what <extern> contains. And the number of following elements
1633 // under <extern> should be same. 1. DRIVER_BINDING 2. COMPONENT_NAME
1634 // 3.DRIVER_CONFIGURATION 4. DRIVER_DIAGNOSTIC
1637 String
[] drvBindList
= SurfaceAreaQuery
.getDriverBindingArray();
1640 // If component name protocol,component configuration protocol,
1641 // component diagnostic protocol is not null or empty, check
1642 // if every one have the same number of the driver binding protocol.
1644 if (drvBindList
== null || drvBindList
.length
== 0) {
1648 String
[] compNamList
= SurfaceAreaQuery
.getComponentNameArray();
1649 String
[] compConfList
= SurfaceAreaQuery
.getDriverConfigArray();
1650 String
[] compDiagList
= SurfaceAreaQuery
.getDriverDiagArray();
1655 // Write driver binding protocol extern to autogen.c
1657 for (int i
= 0; i
< drvBindList
.length
; i
++) {
1658 fileBuffer
.append("extern EFI_DRIVER_BINDING_PROTOCOL ");
1659 fileBuffer
.append(drvBindList
[i
]);
1660 fileBuffer
.append(";\r\n");
1664 // Write component name protocol extern to autogen.c
1666 if (compNamList
!= null && compNamList
.length
!= 0) {
1667 if (drvBindList
.length
!= compNamList
.length
) {
1668 throw new BuildException(
1669 "Different number of Driver Binding and Component Name protocols!");
1673 for (int i
= 0; i
< compNamList
.length
; i
++) {
1674 fileBuffer
.append("extern EFI_COMPONENT_NAME_PROTOCOL ");
1675 fileBuffer
.append(compNamList
[i
]);
1676 fileBuffer
.append(";\r\n");
1681 // Write driver configration protocol extern to autogen.c
1683 if (compConfList
!= null && compConfList
.length
!= 0) {
1684 if (drvBindList
.length
!= compConfList
.length
) {
1685 throw new BuildException(
1686 "Different number of Driver Binding and Driver Configuration protocols!");
1690 for (int i
= 0; i
< compConfList
.length
; i
++) {
1691 fileBuffer
.append("extern EFI_DRIVER_CONFIGURATION_PROTOCOL ");
1692 fileBuffer
.append(compConfList
[i
]);
1693 fileBuffer
.append(";\r\n");
1698 // Write driver dignastic protocol extern to autogen.c
1700 if (compDiagList
!= null && compDiagList
.length
!= 0) {
1701 if (drvBindList
.length
!= compDiagList
.length
) {
1702 throw new BuildException(
1703 "Different number of Driver Binding and Driver Configuration protocols!");
1707 for (int i
= 0; i
< compDiagList
.length
; i
++) {
1708 fileBuffer
.append("extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL ");
1709 fileBuffer
.append(compDiagList
[i
]);
1710 fileBuffer
.append(";\r\n");
1715 // Write driver module protocol bitmask.
1718 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverModelProtocolBitmask = ");
1719 fileBuffer
.append(Integer
.toString(BitMask
));
1720 fileBuffer
.append(";\r\n");
1723 // Write driver module protocol list entry
1726 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverModelProtocolListEntries = ");
1728 fileBuffer
.append(Integer
.toString(drvBindList
.length
));
1729 fileBuffer
.append(";\r\n");
1732 // Write drive module protocol list to autogen.c
1735 .append("GLOBAL_REMOVE_IF_UNREFERENCED const EFI_DRIVER_MODEL_PROTOCOL_LIST _gDriverModelProtocolList[] = {");
1736 for (int i
= 0; i
< drvBindList
.length
; i
++) {
1738 fileBuffer
.append(",");
1740 fileBuffer
.append("\r\n {\r\n");
1741 fileBuffer
.append(" &");
1742 fileBuffer
.append(drvBindList
[i
]);
1743 fileBuffer
.append(", \r\n");
1745 if (compNamList
!= null) {
1746 fileBuffer
.append(" &");
1747 fileBuffer
.append(compNamList
[i
]);
1748 fileBuffer
.append(", \r\n");
1750 fileBuffer
.append(" NULL, \r\n");
1753 if (compConfList
!= null) {
1754 fileBuffer
.append(" &");
1755 fileBuffer
.append(compConfList
[i
]);
1756 fileBuffer
.append(", \r\n");
1758 fileBuffer
.append(" NULL, \r\n");
1761 if (compDiagList
!= null) {
1762 fileBuffer
.append(" &");
1763 fileBuffer
.append(compDiagList
[i
]);
1764 fileBuffer
.append(", \r\n");
1766 fileBuffer
.append(" NULL, \r\n");
1768 fileBuffer
.append(" }");
1770 fileBuffer
.append("\r\n};\r\n");
1774 * ExternCallBackToAutoGenC
1776 * This function adds <SetVirtualAddressMapCallBack> and
1777 * <ExitBootServicesCallBack> infomation to AutoGen.c
1780 * String buffer for AutoGen.c
1781 * @throws BuildException
1783 void ExternCallBackToAutoGenC(StringBuffer fileBuffer
)
1784 throws BuildException
{
1785 String
[] setVirtualList
= SurfaceAreaQuery
1786 .getSetVirtualAddressMapCallBackArray();
1787 String
[] exitBootList
= SurfaceAreaQuery
1788 .getExitBootServicesCallBackArray();
1789 String moduleType
= SurfaceAreaQuery
.getModuleType();
1790 boolean UefiOrDxeModule
= false;
1794 switch (CommonDefinition
.getModuleType(moduleType
)) {
1795 case CommonDefinition
.ModuleTypeDxeDriver
:
1796 case CommonDefinition
.ModuleTypeDxeRuntimeDriver
:
1797 case CommonDefinition
.ModuleTypeDxeSalDriver
:
1798 case CommonDefinition
.ModuleTypeUefiDriver
:
1799 case CommonDefinition
.ModuleTypeUefiApplication
:
1801 // Entry point lib for these module types needs to know the count
1804 UefiOrDxeModule
= true;
1806 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverSetVirtualAddressMapEventCount = ");
1809 // If the list is not valid or has no entries set count to zero else
1810 // set count to the number of valid entries
1813 if (setVirtualList
!= null) {
1814 for (i
= 0; i
< setVirtualList
.length
; i
++) {
1815 if (setVirtualList
[i
].equalsIgnoreCase("")) {
1822 fileBuffer
.append(Integer
.toString(Count
));
1823 fileBuffer
.append(";\r\n\r\n");
1829 if (setVirtualList
== null) {
1830 if (UefiOrDxeModule
) {
1832 // No data so make a NULL list
1835 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {\r\n");
1836 fileBuffer
.append(" NULL\r\n");
1837 fileBuffer
.append("};\r\n\r\n");
1841 // Write SetVirtualAddressMap function definition.
1843 for (i
= 0; i
< setVirtualList
.length
; i
++) {
1844 if (setVirtualList
[i
].equalsIgnoreCase("")) {
1847 fileBuffer
.append("VOID\r\n");
1848 fileBuffer
.append("EFIAPI\n");
1849 fileBuffer
.append(setVirtualList
[i
]);
1850 fileBuffer
.append(" (\r\n");
1851 fileBuffer
.append(" IN EFI_EVENT Event,\r\n");
1852 fileBuffer
.append(" IN VOID *Context\r\n");
1853 fileBuffer
.append(" );\r\n\r\n");
1857 // Write SetVirtualAddressMap entry point array.
1860 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {");
1861 for (i
= 0; i
< setVirtualList
.length
; i
++) {
1862 if (setVirtualList
[i
].equalsIgnoreCase("")) {
1867 fileBuffer
.append("\r\n ");
1869 fileBuffer
.append(",\r\n ");
1872 fileBuffer
.append(setVirtualList
[i
]);
1875 fileBuffer
.append("\r\n NULL");
1877 fileBuffer
.append("\r\n};\r\n\r\n");
1880 if (UefiOrDxeModule
) {
1882 // Entry point lib for these module types needs to know the count.
1885 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverExitBootServicesEventCount = ");
1888 // If the list is not valid or has no entries set count to zero else
1889 // set count to the number of valid entries.
1892 if (exitBootList
!= null) {
1893 if (setVirtualList
!= null) {
1894 for (i
= 0; i
< exitBootList
.length
; i
++) {
1895 if (exitBootList
[i
].equalsIgnoreCase("")) {
1902 fileBuffer
.append(Integer
.toString(Count
));
1903 fileBuffer
.append(";\r\n\r\n");
1906 if (exitBootList
== null) {
1907 if (UefiOrDxeModule
) {
1909 // No data so make a NULL list.
1912 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {\r\n");
1913 fileBuffer
.append(" NULL\r\n");
1914 fileBuffer
.append("};\r\n\r\n");
1918 // Write DriverExitBootServices function definition.
1920 for (i
= 0; i
< exitBootList
.length
; i
++) {
1921 if (exitBootList
[i
].equalsIgnoreCase("")) {
1925 fileBuffer
.append("VOID\r\n");
1926 fileBuffer
.append("EFIAPI\n");
1927 fileBuffer
.append(exitBootList
[i
]);
1928 fileBuffer
.append(" (\r\n");
1929 fileBuffer
.append(" IN EFI_EVENT Event,\r\n");
1930 fileBuffer
.append(" IN VOID *Context\r\n");
1931 fileBuffer
.append(" );\r\n\r\n");
1935 // Write DriverExitBootServices entry point array.
1938 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {");
1939 for (i
= 0; i
< exitBootList
.length
; i
++) {
1940 if (exitBootList
[i
].equalsIgnoreCase("")) {
1945 fileBuffer
.append("\r\n ");
1947 fileBuffer
.append(",\r\n ");
1949 fileBuffer
.append(exitBootList
[i
]);
1952 fileBuffer
.append("\r\n NULL");
1954 fileBuffer
.append("\r\n};\r\n\r\n");