]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/autogen/AutoGen.java
Remove build warning.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / autogen / AutoGen.java
1 /** @file
2 AutoGen class.
3
4 This class is to generate Autogen.h and Autogen.c according to module surface area
5 or library surface area.
6
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
12
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.
15
16 **/
17
18 package org.tianocore.build.autogen;
19
20 import org.tianocore.build.global.GlobalData;
21 import org.tianocore.build.global.Spd;
22 import org.tianocore.build.global.SurfaceAreaQuery;
23 import org.tianocore.build.id.ModuleIdentification;
24 import org.tianocore.build.id.PackageIdentification;
25 import org.tianocore.GuidsDocument;
26 import org.tianocore.LibraryClassDocument.LibraryClass;
27 import org.tianocore.PPIsDocument;
28 import org.tianocore.ProtocolsDocument;
29 import org.tianocore.build.pcd.action.PCDAutoGenAction;
30 import org.tianocore.build.exception.*;
31 import org.tianocore.logger.EdkLog;
32 import org.apache.tools.ant.BuildException;
33 import org.apache.xmlbeans.XmlObject;
34
35 import java.io.File;
36 import java.io.FileReader;
37 import java.io.FileWriter;
38 import java.util.ArrayList;
39 import java.util.HashSet;
40 import java.util.Iterator;
41 import java.util.LinkedList;
42 import java.util.List;
43 import java.util.Map;
44 import java.util.Set;
45
46 /**
47 * This class is to generate Autogen.h and Autogen.c according to module surface
48 * area or library surface area.
49 */
50 public class AutoGen {
51 // /
52 // / The output path of Autogen.h and Autogen.c
53 // /
54 private String outputPath;
55
56 // /
57 // / The base name of module or library.
58 // /
59 private ModuleIdentification moduleId;
60
61 // /
62 // / The build architecture
63 // /
64 private String arch;
65
66 // /
67 // / PcdAutogen instance which is used to manage how to generate the PCD
68 // / information.
69 // /
70 private PCDAutoGenAction myPcdAutogen;
71
72 // /
73 // / The protocl list which records in module or library surface area and
74 // / it's dependence on library instance surface area.
75 // /
76 private Set<String> mProtocolList = new HashSet<String>();
77
78 // /
79 // / The Ppi list which recorded in module or library surface area and its
80 // / dependency on library instance surface area.
81 // /
82 private Set<String> mPpiList = new HashSet<String>();
83
84 // /
85 // / The Guid list which recoreded in module or library surface area and it's
86 // / dependence on library instance surface area.
87 // /
88 private Set<String> mGuidList = new HashSet<String>();
89
90 //
91 // The dependence package list which recoreded in module or library surface
92 // area and it's dependence on library instance surface are.
93 //
94 private List<PackageIdentification> mDepPkgList = new LinkedList<PackageIdentification>();
95 /**
96 * Construct function
97 *
98 * This function mainly initialize some member variable.
99 *
100 * @param outputPath
101 * Output path of AutoGen file.
102 * @param baseName
103 * Module base name.
104 * @param arch
105 * Target architecture.
106 */
107 public AutoGen(String outputPath, ModuleIdentification moduleId, String arch) {
108 this.outputPath = outputPath;
109 this.moduleId = moduleId;
110 this.arch = arch;
111
112 }
113
114 /**
115 * saveFile function
116 *
117 * This function save the content in stringBuffer to file.
118 *
119 * @param fileName
120 * The name of file.
121 * @param fileBuffer
122 * The content of AutoGen file in buffer.
123 * @return "true" successful, "false" failed.
124 */
125 private boolean saveFile(String fileName, StringBuffer fileBuffer) {
126 try {
127 File autoGenH = new File(fileName);
128
129 //
130 // if the file exists, compare their content
131 //
132 if (autoGenH.exists()) {
133 FileReader fIn = new FileReader(autoGenH);
134 char[] oldFileBuffer = new char[(int) autoGenH.length()];
135 fIn.read(oldFileBuffer, 0, (int) autoGenH.length());
136 fIn.close();
137
138 //
139 // if we got the same file, don't re-generate it to prevent
140 // sources depending on it from re-building
141 //
142 if (fileBuffer.toString().compareTo(new String(oldFileBuffer)) == 0) {
143 return true;
144 }
145 }
146 FileWriter fOut = new FileWriter(autoGenH);
147 fOut.write(fileBuffer.toString());
148 fOut.close();
149 } catch (Exception e) {
150 return false;
151 }
152 return true;
153 }
154
155 /**
156 * genAutogen function
157 *
158 * This function call libGenAutoGen or moduleGenAutogen function, which
159 * dependence on generate library autogen or module autogen.
160 *
161 * @throws BuildException
162 * Failed to creat AutoGen.c & AutoGen.h.
163 */
164 public void genAutogen() throws BuildException {
165 try {
166 //
167 // If outputPath do not exist, create it.
168 //
169 File path = new File(outputPath);
170 path.mkdirs();
171
172 //
173 // Check current is library or not, then call the corresponding
174 // function.
175 //
176 if (this.moduleId.isLibrary()) {
177 libGenAutogen();
178 } else {
179 moduleGenAutogen();
180 }
181
182 } catch (Exception e) {
183 throw new BuildException(
184 "Failed to create AutoGen.c & AutoGen.h!\n"
185 + e.getMessage());
186 }
187 }
188
189 /**
190 * moduleGenAutogen function
191 *
192 * This function generates AutoGen.c & AutoGen.h for module.
193 *
194 * @throws BuildException
195 * Faile to create module AutoGen.c & AutoGen.h.
196 */
197 void moduleGenAutogen() throws BuildException {
198
199 try {
200 moduleGenAutogenC();
201 moduleGenAutogenH();
202 } catch (Exception e) {
203 throw new BuildException(
204 "Faile to create module AutoGen.c & AutoGen.h!\n"
205 + e.getMessage());
206 }
207 }
208
209 /**
210 * libGenAutogen function
211 *
212 * This function generates AutoGen.c & AutoGen.h for library.
213 *
214 * @throws BuildException
215 * Faile to create library AutoGen.c & AutoGen.h
216 */
217 void libGenAutogen() throws BuildException {
218 try {
219 libGenAutogenC();
220 libGenAutogenH();
221 } catch (Exception e) {
222 throw new BuildException(
223 "Faile to create library AutoGen.c & AutoGen.h!\n"
224 + e.getMessage());
225 }
226 }
227
228 /**
229 * moduleGenAutogenH
230 *
231 * This function generates AutoGen.h for module.
232 *
233 * @throws BuildException
234 * Failed to generate AutoGen.h.
235 */
236 void moduleGenAutogenH() throws AutoGenException {
237
238 Set<String> libClassIncludeH;
239 String moduleType;
240 // List<String> headerFileList;
241 List<String> headerFileList;
242 Iterator item;
243 StringBuffer fileBuffer = new StringBuffer(8192);
244
245 //
246 // Write Autogen.h header notation
247 //
248 fileBuffer.append(CommonDefinition.autogenHNotation);
249
250 //
251 // Add #ifndef ${BaseName}_AUTOGENH
252 // #def ${BseeName}_AUTOGENH
253 //
254 fileBuffer.append("#ifndef " + this.moduleId.getName().toUpperCase()
255 + "_AUTOGENH\r\n");
256 fileBuffer.append("#define " + this.moduleId.getName().toUpperCase()
257 + "_AUTOGENH\r\n\r\n");
258
259 //
260 // Write the specification version and release version at the begine
261 // of autogen.h file.
262 // Note: the specification version and release version should
263 // be got from module surface area instead of hard code by it's
264 // moduleType.
265 //
266 moduleType = SurfaceAreaQuery.getModuleType();
267
268 //
269 // Add "extern int __make_me_compile_correctly;" at begin of
270 // AutoGen.h.
271 //
272 fileBuffer.append(CommonDefinition.autoGenHbegin);
273
274 //
275 // Put EFI_SPECIFICATION_VERSION, and EDK_RELEASE_VERSION.
276 //
277 String[] specList = SurfaceAreaQuery.getExternSpecificaiton();
278 for (int i = 0; i < specList.length; i++) {
279 fileBuffer.append(CommonDefinition.marcDefineStr + specList[i]
280 + "\r\n");
281 }
282 //
283 // Write consumed package's mdouleInfo related .h file to autogen.h
284 //
285 // PackageIdentification[] consumedPkgIdList = SurfaceAreaQuery
286 // .getDependencePkg(this.arch);
287 PackageIdentification[] consumedPkgIdList = SurfaceAreaQuery
288 .getDependencePkg(this.arch);
289 if (consumedPkgIdList != null) {
290 headerFileList = depPkgToAutogenH(consumedPkgIdList, moduleType);
291 item = headerFileList.iterator();
292 while (item.hasNext()) {
293 fileBuffer.append(item.next().toString());
294 }
295 }
296
297 //
298 // Write library class's related *.h file to autogen.h.
299 //
300 String[] libClassList = SurfaceAreaQuery
301 .getLibraryClasses(CommonDefinition.AlwaysConsumed);
302 if (libClassList != null) {
303 libClassIncludeH = LibraryClassToAutogenH(libClassList);
304 item = libClassIncludeH.iterator();
305 while (item.hasNext()) {
306 fileBuffer.append(item.next().toString());
307 }
308 }
309
310 libClassList = SurfaceAreaQuery
311 .getLibraryClasses(CommonDefinition.AlwaysProduced);
312 if (libClassList != null) {
313 libClassIncludeH = LibraryClassToAutogenH(libClassList);
314 item = libClassIncludeH.iterator();
315 while (item.hasNext()) {
316 fileBuffer.append(item.next().toString());
317 }
318 }
319 fileBuffer.append("\r\n");
320
321 //
322 // Write PCD autogen information to AutoGen.h.
323 //
324 if (this.myPcdAutogen != null) {
325 fileBuffer.append("\r\n");
326 fileBuffer.append(this.myPcdAutogen.OutputH());
327 }
328
329 //
330 // Append the #endif at AutoGen.h
331 //
332 fileBuffer.append("#endif\r\n");
333
334 //
335 // Save string buffer content in AutoGen.h.
336 //
337 if (!saveFile(outputPath + File.separatorChar + "AutoGen.h", fileBuffer)) {
338 throw new BuildException("Failed to generate AutoGen.h !!!");
339 }
340 }
341
342 /**
343 * moduleGenAutogenC
344 *
345 * This function generates AutoGen.c for module.
346 *
347 * @throws BuildException
348 * Failed to generate AutoGen.c.
349 */
350 void moduleGenAutogenC() throws AutoGenException {
351
352 StringBuffer fileBuffer = new StringBuffer(8192);
353 //
354 // Write Autogen.c header notation
355 //
356 fileBuffer.append(CommonDefinition.autogenCNotation);
357
358 //
359 // Write #include <AutoGen.h> at beginning of AutoGen.c
360 //
361 fileBuffer.append(CommonDefinition.includeAutogenH);
362
363 //
364 // Get the native MSA file infomation. Since before call autogen,
365 // the MSA native <Externs> information were overrided. So before
366 // process <Externs> it should be set the DOC as the Native MSA info.
367 //
368 Map<String, XmlObject> doc = GlobalData.getNativeMsa(this.moduleId);
369 SurfaceAreaQuery.push(doc);
370 //
371 // Write <Extern>
372 // DriverBinding/ComponentName/DriverConfiguration/DriverDialog
373 // to AutoGen.c
374 //
375
376 ExternsDriverBindingToAutoGenC(fileBuffer);
377
378 //
379 // Write DriverExitBootServicesEvent/DriverSetVirtualAddressMapEvent
380 // to Autogen.c
381 //
382 ExternCallBackToAutoGenC(fileBuffer);
383
384 //
385 // Write EntryPoint to autgoGen.c
386 //
387 String[] entryPointList = SurfaceAreaQuery.getModuleEntryPointArray();
388 EntryPointToAutoGen(CommonDefinition.remDupString(entryPointList), fileBuffer);
389
390
391 //
392 // Restore the DOC which include the FPD module info.
393 //
394 SurfaceAreaQuery.pop();
395
396 //
397 // Write Guid to autogen.c
398 //
399 String guid = CommonDefinition.formatGuidName(SurfaceAreaQuery
400 .getModuleGuid());
401
402 fileBuffer
403 .append("GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiCallerIdGuid = {");
404 if (guid == null) {
405 throw new AutoGenException("Guid value must set!\n");
406 }
407
408 //
409 // Formate Guid as ANSI c form.Example:
410 // {0xd2b2b828, 0x826, 0x48a7,{0xb3, 0xdf, 0x98, 0x3c, 0x0, 0x60, 0x24,
411 // 0xf0}}
412 //
413
414 fileBuffer.append(guid);
415 fileBuffer.append("};\r\n");
416
417 //
418 // Generate library instance consumed protocol, guid, ppi, pcd list.
419 // Save those to this.protocolList, this.ppiList, this.pcdList,
420 // this.guidList. Write Consumed library constructor and desconstuct to
421 // autogen.c
422 //
423 LibInstanceToAutogenC(fileBuffer);
424
425 //
426 // Get module dependent Package identification.
427 //
428 PackageIdentification[] packages = SurfaceAreaQuery.getDependencePkg(this.arch);
429 for (int i = 0; i < packages.length; i++){
430 if (!this.mDepPkgList.contains(packages[i])){
431 this.mDepPkgList.add(packages[i]);
432 }
433
434 }
435
436 //
437 // Write consumed ppi, guid, protocol to autogen.c
438 //
439 ProtocolGuidToAutogenC(fileBuffer);
440 PpiGuidToAutogenC(fileBuffer);
441 GuidGuidToAutogenC(fileBuffer);
442
443 //
444 // Call pcd autogen. PCDAutoGenAction tool only need module name and
445 // isPcdEmulatedDriver as parameter. Library inherits PCD and module's
446 // PCD information has been collected in FPDParser task by
447 // CollectPCDAction.
448 // Note : when PCD image tool ready,
449 // isPCDEmulatedDriver parameter will be removed.
450 //
451 try {
452 // this.myPcdAutogen = new PCDAutoGenAction(moduleId.getName(),
453 // moduleId.getGuid(), moduleId.getPackage().getName(), moduleId.getPackage().getGuid(),this.arch,moduleId.getVersion(),false, null);
454 this.myPcdAutogen = new PCDAutoGenAction(moduleId.getName(),null,null,null, this.arch,null,false, null);
455 this.myPcdAutogen.execute();
456 } catch (Exception e) {
457 throw new BuildException("PCD Autogen failed:" + e.getMessage());
458 }
459
460 if (this.myPcdAutogen != null) {
461 fileBuffer.append("\r\n");
462 fileBuffer.append(this.myPcdAutogen.OutputC());
463 }
464
465 if (!saveFile(outputPath + File.separatorChar + "AutoGen.c", fileBuffer)) {
466 throw new BuildException("Failed to generate AutoGen.c !!!");
467 }
468
469 }
470
471 /**
472 * libGenAutogenH
473 *
474 * This function generates AutoGen.h for library.
475 *
476 * @throws BuildException
477 * Failed to generate AutoGen.c.
478 */
479 void libGenAutogenH() throws AutoGenException {
480
481 Set<String> libClassIncludeH;
482 String moduleType;
483 List<String> headerFileList;
484 Iterator item;
485 StringBuffer fileBuffer = new StringBuffer(10240);
486
487 //
488 // Write Autogen.h header notation
489 //
490 fileBuffer.append(CommonDefinition.autogenHNotation);
491
492 //
493 // Add #ifndef ${BaseName}_AUTOGENH
494 // #def ${BseeName}_AUTOGENH
495 //
496 fileBuffer.append("#ifndef " + this.moduleId.getName().toUpperCase()
497 + "_AUTOGENH\r\n");
498 fileBuffer.append("#define " + this.moduleId.getName().toUpperCase()
499 + "_AUTOGENH\r\n\r\n");
500
501 //
502 // Write EFI_SPECIFICATION_VERSION and EDK_RELEASE_VERSION
503 // to autogen.h file.
504 // Note: the specification version and release version should
505 // be get from module surface area instead of hard code.
506 //
507 fileBuffer.append(CommonDefinition.autoGenHbegin);
508 String[] specList = SurfaceAreaQuery.getExternSpecificaiton();
509 for (int i = 0; i < specList.length; i++) {
510 fileBuffer.append(CommonDefinition.marcDefineStr + specList[i]
511 + "\r\n");
512 }
513 // fileBuffer.append(CommonDefinition.autoGenHLine1);
514 // fileBuffer.append(CommonDefinition.autoGenHLine2);
515
516 //
517 // Write consumed package's mdouleInfo related *.h file to autogen.h.
518 //
519 moduleType = SurfaceAreaQuery.getModuleType();
520 PackageIdentification[] cosumedPkglist = SurfaceAreaQuery
521 .getDependencePkg(this.arch);
522 headerFileList = depPkgToAutogenH(cosumedPkglist, moduleType);
523 item = headerFileList.iterator();
524 while (item.hasNext()) {
525 fileBuffer.append(item.next().toString());
526 }
527 //
528 // Write library class's related *.h file to autogen.h
529 //
530 String[] libClassList = SurfaceAreaQuery
531 .getLibraryClasses(CommonDefinition.AlwaysConsumed);
532 if (libClassList != null) {
533 libClassIncludeH = LibraryClassToAutogenH(libClassList);
534 item = libClassIncludeH.iterator();
535 while (item.hasNext()) {
536 fileBuffer.append(item.next().toString());
537 }
538 }
539
540 libClassList = SurfaceAreaQuery
541 .getLibraryClasses(CommonDefinition.AlwaysProduced);
542 if (libClassList != null) {
543 libClassIncludeH = LibraryClassToAutogenH(libClassList);
544 item = libClassIncludeH.iterator();
545 while (item.hasNext()) {
546 fileBuffer.append(item.next().toString());
547 }
548 }
549 fileBuffer.append("\r\n");
550
551 //
552 // Write PCD information to library AutoGen.h.
553 //
554 if (this.myPcdAutogen != null) {
555 fileBuffer.append("\r\n");
556 fileBuffer.append(this.myPcdAutogen.OutputH());
557 }
558
559 //
560 // Append the #endif at AutoGen.h
561 //
562 fileBuffer.append("#endif\r\n");
563
564 //
565 // Save content of string buffer to AutoGen.h file.
566 //
567 if (!saveFile(outputPath + File.separatorChar + "AutoGen.h", fileBuffer)) {
568 throw new BuildException("Failed to generate AutoGen.h !!!");
569 }
570 }
571
572 /**
573 * libGenAutogenC
574 *
575 * This function generates AutoGen.h for library.
576 *
577 * @throws BuildException
578 * Failed to generate AutoGen.c.
579 */
580 void libGenAutogenC() throws BuildException {
581 StringBuffer fileBuffer = new StringBuffer(10240);
582
583 //
584 // Write Autogen.c header notation
585 //
586 fileBuffer.append(CommonDefinition.autogenCNotation);
587
588 fileBuffer.append(CommonDefinition.autoGenCLine1);
589 fileBuffer.append("\r\n");
590
591 //
592 // Call pcd autogen. PCDAutoGenAction tool only need module name and
593 // isPcdEmulatedDriver as parameter. Library inherit PCD and module's
594 // PCD information has been collected in FPDParser task by
595 // CollectPCDAction.
596 // Note : when PCD image tool ready,
597 // isPCDEmulatedDriver parameter will be removed.
598 //
599 try {
600 // this.myPcdAutogen = new PCDAutoGenAction(this.moduleId.getName(),
601 // this.moduleId.getGuid(),moduleId.getPackage().getName(),moduleId.getPackage().getGuid(), this.arch, moduleId.getVersion(),true, SurfaceAreaQuery.getModulePcdEntryNameArray());
602 this.myPcdAutogen = new PCDAutoGenAction(this.moduleId.getName(),
603 null,
604 null,
605 null,
606 this.arch,
607 null,
608 true,
609 SurfaceAreaQuery.getModulePcdEntryNameArray());
610
611 this.myPcdAutogen.execute();
612 } catch (Exception e) {
613 throw new BuildException(e.getMessage());
614 }
615
616 if (this.myPcdAutogen != null) {
617 fileBuffer.append("\r\n");
618 fileBuffer.append(this.myPcdAutogen.OutputC());
619 }
620
621 if (!saveFile(outputPath + File.separatorChar + "AutoGen.c", fileBuffer)) {
622 throw new BuildException("Failed to generate AutoGen.c !!!");
623 }
624 }
625
626 /**
627 * LibraryClassToAutogenH
628 *
629 * This function returns *.h files declared by library classes which are
630 * consumed or produced by current build module or library.
631 *
632 * @param libClassList
633 * List of library class which consumed or produce by current
634 * build module or library.
635 * @return includeStrList List of *.h file.
636 */
637 Set<String> LibraryClassToAutogenH(String[] libClassList)
638 throws AutoGenException {
639 Set<String> includStrList = new HashSet<String>();
640 String includerName[];
641 String str = "";
642
643 //
644 // Get include file from GlobalData's SPDTable according to
645 // library class name.
646 //
647
648 for (int i = 0; i < libClassList.length; i++) {
649 includerName = GlobalData.getLibraryClassHeaderFiles(
650 SurfaceAreaQuery.getDependencePkg(this.arch),
651 libClassList[i]);
652 if (includerName == null) {
653 throw new AutoGenException("Can not find library class ["
654 + libClassList[i] + "] declaration in every packages. ");
655 }
656 for (int j = 0; j < includerName.length; j++) {
657 String includeNameStr = includerName[j];
658 if (includeNameStr != null) {
659 str = CommonDefinition.include + " " + "<";
660 str = str + includeNameStr + ">\r\n";
661 includStrList.add(str);
662 includeNameStr = null;
663 }
664 }
665 }
666 return includStrList;
667 }
668
669 /**
670 * IncludesToAutogenH
671 *
672 * This function add include file in AutoGen.h file.
673 *
674 * @param packageNameList
675 * List of module depended package.
676 * @param moduleType
677 * Module type.
678 * @return
679 */
680 List<String> depPkgToAutogenH(PackageIdentification[] packageNameList,
681 String moduleType) throws AutoGenException {
682
683 List<String> includeStrList = new LinkedList<String>();
684 String pkgHeader;
685 String includeStr = "";
686
687 //
688 // Get include file from moduleInfo file
689 //
690 for (int i = 0; i < packageNameList.length; i++) {
691 pkgHeader = GlobalData.getPackageHeaderFiles(packageNameList[i],
692 moduleType);
693 if (pkgHeader == null) {
694 throw new AutoGenException("Can not find package ["
695 + packageNameList[i]
696 + "] declaration in every packages. ");
697 } else if (!pkgHeader.equalsIgnoreCase("")) {
698 includeStr = CommonDefinition.include + " <" + pkgHeader
699 + ">\r\n";
700 includeStrList.add(includeStr);
701 }
702 }
703
704 return includeStrList;
705 }
706
707 /**
708 * EntryPointToAutoGen
709 *
710 * This function convert <ModuleEntryPoint> & <ModuleUnloadImage>
711 * information in mas to AutoGen.c
712 *
713 * @param entryPointList
714 * List of entry point.
715 * @param fileBuffer
716 * String buffer fo AutoGen.c.
717 * @throws Exception
718 */
719 void EntryPointToAutoGen(String[] entryPointList, StringBuffer fileBuffer)
720 throws BuildException {
721
722 String typeStr = SurfaceAreaQuery.getModuleType();
723
724 //
725 // The parameters and return value of entryPoint is difference
726 // for difference module type.
727 //
728 switch (CommonDefinition.getModuleType(typeStr)) {
729
730 case CommonDefinition.ModuleTypePeiCore:
731 if (entryPointList == null ||entryPointList.length != 1 ) {
732 throw new BuildException(
733 "Module type = 'PEI_CORE', only have one module entry point!");
734 } else {
735 fileBuffer.append("EFI_STATUS\r\n");
736 fileBuffer.append("EFIAPI\r\n");
737 fileBuffer.append(entryPointList[0]);
738 fileBuffer.append(" (\r\n");
739 fileBuffer
740 .append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n");
741 fileBuffer
742 .append(" IN VOID *OldCoreData\r\n");
743 fileBuffer.append(" );\r\n\r\n");
744
745 fileBuffer.append("EFI_STATUS\r\n");
746 fileBuffer.append("EFIAPI\r\n");
747 fileBuffer.append("ProcessModuleEntryPointList (\r\n");
748 fileBuffer
749 .append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n");
750 fileBuffer
751 .append(" IN VOID *OldCoreData\r\n");
752 fileBuffer.append(" )\r\n\r\n");
753 fileBuffer.append("{\r\n");
754 fileBuffer.append(" return ");
755 fileBuffer.append(entryPointList[0]);
756 fileBuffer.append(" (PeiStartupDescriptor, OldCoreData);\r\n");
757 fileBuffer.append("}\r\n\r\n");
758 }
759 break;
760
761 case CommonDefinition.ModuleTypeDxeCore:
762 fileBuffer.append("const UINT32 _gUefiDriverRevision = 0;\r\n");
763 if (entryPointList == null || entryPointList.length != 1) {
764 throw new BuildException(
765 "Module type = 'DXE_CORE', only have one module entry point!");
766 } else {
767
768 fileBuffer.append("VOID\r\n");
769 fileBuffer.append("EFIAPI\r\n");
770 fileBuffer.append(entryPointList[0]);
771 fileBuffer.append(" (\n");
772 fileBuffer.append(" IN VOID *HobStart\r\n");
773 fileBuffer.append(" );\r\n\r\n");
774
775 fileBuffer.append("VOID\r\n");
776 fileBuffer.append("EFIAPI\r\n");
777 fileBuffer.append("ProcessModuleEntryPointList (\r\n");
778 fileBuffer.append(" IN VOID *HobStart\r\n");
779 fileBuffer.append(" )\r\n\r\n");
780 fileBuffer.append("{\r\n");
781 fileBuffer.append(" ");
782 fileBuffer.append(entryPointList[0]);
783 fileBuffer.append(" (HobStart);\r\n");
784 fileBuffer.append("}\r\n\r\n");
785 }
786 break;
787
788 case CommonDefinition.ModuleTypePeim:
789 int entryPointCount = 0;
790 fileBuffer
791 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = 0;\r\n");
792 if (entryPointList == null || entryPointList.length == 0) {
793 fileBuffer.append("EFI_STATUS\r\n");
794 fileBuffer.append("EFIAPI\r\n");
795 fileBuffer.append("ProcessModuleEntryPointList (\r\n");
796 fileBuffer.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
797 fileBuffer.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
798 fileBuffer.append(" )\r\n\r\n");
799 fileBuffer.append("{\r\n");
800 fileBuffer.append(" return EFI_SUCCESS;\r\n");
801 fileBuffer.append("}\r\n\r\n");
802 break;
803 }
804 for (int i = 0; i < entryPointList.length; i++) {
805 fileBuffer.append("EFI_STATUS\r\n");
806 fileBuffer.append("EFIAPI\r\n");
807 fileBuffer.append(entryPointList[i]);
808 fileBuffer.append(" (\r\n");
809 fileBuffer
810 .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
811 fileBuffer
812 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
813 fileBuffer.append(" );\r\n");
814 entryPointCount++;
815
816 }
817
818 fileBuffer.append("EFI_STATUS\r\n");
819 fileBuffer.append("EFIAPI\r\n");
820 fileBuffer.append("ProcessModuleEntryPointList (\r\n");
821 fileBuffer.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
822 fileBuffer.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
823 fileBuffer.append(" )\r\n\r\n");
824 fileBuffer.append("{\r\n");
825 if (entryPointCount == 1) {
826 fileBuffer.append(" return ");
827 fileBuffer.append(entryPointList[0]);
828 fileBuffer.append(" (FfsHeader, PeiServices);\r\n");
829 } else {
830 fileBuffer.append(" EFI_STATUS Status;\r\n");
831 fileBuffer.append(" EFI_STATUS CombinedStatus;\r\n\r\n");
832 fileBuffer.append(" CombinedStatus = EFI_LOAD_ERROR;\r\n\r\n");
833 for (int i = 0; i < entryPointList.length; i++) {
834 if (!entryPointList[i].equals("")) {
835 fileBuffer.append(" Status = ");
836 fileBuffer.append(entryPointList[i]);
837 fileBuffer.append(" (FfsHeader, PeiServices);\r\n");
838 fileBuffer
839 .append(" if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {\r\n");
840 fileBuffer.append(" CombinedStatus = Status;\r\n");
841 fileBuffer.append(" }\r\n\r\n");
842 } else {
843 break;
844 }
845 }
846 fileBuffer.append(" return CombinedStatus;\r\n");
847 }
848 fileBuffer.append("}\r\n\r\n");
849 break;
850
851 case CommonDefinition.ModuleTypeDxeSmmDriver:
852 entryPointCount = 0;
853 //
854 // If entryPoint is null, create an empty ProcessModuleEntryPointList
855 // function.
856 //
857 if (entryPointList == null || entryPointList.length == 0){
858 fileBuffer
859 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
860 fileBuffer.append(Integer.toString(entryPointCount));
861 fileBuffer.append(";\r\n");
862 fileBuffer.append("EFI_STATUS\r\n");
863 fileBuffer.append("EFIAPI\r\n");
864 fileBuffer.append("ProcessModuleEntryPointList (\r\n");
865 fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");
866 fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
867 fileBuffer.append(" )\r\n\r\n");
868 fileBuffer.append("{\r\n");
869 fileBuffer.append(" return EFI_SUCCESS;\r\n");
870 fileBuffer.append("}\r\n\r\n");
871
872 } else {
873 for (int i = 0; i < entryPointList.length; i++) {
874 fileBuffer.append("EFI_STATUS\r\n");
875 fileBuffer.append("EFIAPI\r\n");
876 fileBuffer.append(entryPointList[i]);
877 fileBuffer.append(" (\r\n");
878 fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");
879 fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
880 fileBuffer.append(" );\r\n");
881 entryPointCount++;
882 }
883 fileBuffer
884 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
885 fileBuffer.append(Integer.toString(entryPointCount));
886 fileBuffer.append(";\r\n");
887 fileBuffer
888 .append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");
889 fileBuffer
890 .append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n\r\n");
891
892 fileBuffer.append("EFI_STATUS\r\n");
893 fileBuffer.append("EFIAPI\r\n");
894 fileBuffer.append("ProcessModuleEntryPointList (\r\n");
895 fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");
896 fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
897 fileBuffer.append(" )\r\n\r\n");
898 fileBuffer.append("{\r\n");
899
900
901 for (int i = 0; i < entryPointList.length; i++) {
902 fileBuffer
903 .append(" if (SetJump (&mJumpContext) == 0) {\r\n");
904 fileBuffer.append(" ExitDriver (");
905 fileBuffer.append(entryPointList[i]);
906 fileBuffer.append(" (ImageHandle, SystemTable));\r\n");
907 fileBuffer.append(" ASSERT (FALSE);\r\n");
908 fileBuffer.append(" }\r\n");
909
910 }
911 fileBuffer.append(" return mDriverEntryPointStatus;\r\n");
912 fileBuffer.append("}\r\n\r\n");
913
914 fileBuffer.append("VOID\r\n");
915 fileBuffer.append("EFIAPI\r\n");
916 fileBuffer.append("ExitDriver (\r\n");
917 fileBuffer.append(" IN EFI_STATUS Status\n");
918 fileBuffer.append(" )\r\n\r\n");
919 fileBuffer.append("{\r\n");
920 fileBuffer
921 .append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");
922 fileBuffer.append(" mDriverEntryPointStatus = Status;\r\n");
923 fileBuffer.append(" }\r\n");
924 fileBuffer.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");
925 fileBuffer.append(" ASSERT (FALSE);\r\n");
926 fileBuffer.append("}\r\n\r\n");
927
928 }
929
930
931 //
932 // Add "ModuleUnloadImage" for DxeSmmDriver module type;
933 //
934 entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();
935 entryPointList = CommonDefinition.remDupString(entryPointList);
936 entryPointCount = 0;
937
938 if (entryPointList != null) {
939 for (int i = 0; i < entryPointList.length; i++) {
940 fileBuffer.append("EFI_STATUS\r\n");
941 fileBuffer.append("EFIAPI\r\n");
942 fileBuffer.append(entryPointList[i]);
943 fileBuffer.append(" (\r\n");
944 fileBuffer
945 .append(" IN EFI_HANDLE ImageHandle\r\n");
946 fileBuffer.append(" );\r\n");
947 entryPointCount++;
948 }
949 }
950
951 fileBuffer
952 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");
953 fileBuffer.append(Integer.toString(entryPointCount));
954 fileBuffer.append(";\r\n\r\n");
955
956 fileBuffer.append("EFI_STATUS\r\n");
957 fileBuffer.append("EFIAPI\r\n");
958 fileBuffer.append("ProcessModuleUnloadList (\r\n");
959 fileBuffer.append(" IN EFI_HANDLE ImageHandle\r\n");
960 fileBuffer.append(" )\r\n");
961 fileBuffer.append("{\r\n");
962
963 if (entryPointCount == 0) {
964 fileBuffer.append(" return EFI_SUCCESS;\r\n");
965 } else if (entryPointCount == 1) {
966 fileBuffer.append(" return ");
967 fileBuffer.append(entryPointList[0]);
968 fileBuffer.append("(ImageHandle);\r\n");
969 } else {
970 fileBuffer.append(" EFI_STATUS Status;\r\n\r\n");
971 fileBuffer.append(" Status = EFI_SUCCESS;\r\n\r\n");
972 for (int i = 0; i < entryPointList.length; i++) {
973 if (i == 0){
974 fileBuffer.append(" Status = ");
975 fileBuffer.append(entryPointList[i]);
976 fileBuffer.append("(ImageHandle);\r\n");
977 }else{
978 fileBuffer.append(" if (EFI_ERROR (Status)) {\r\n");
979 fileBuffer.append(" ");
980 fileBuffer.append(entryPointList[i]);
981 fileBuffer.append("(ImageHandle);\r\n");
982 fileBuffer.append(" } else {\r\n");
983 fileBuffer.append(" Status = ");
984 fileBuffer.append(entryPointList[i]);
985 fileBuffer.append("(ImageHandle);\r\n");
986 fileBuffer.append(" }\r\n");
987 }
988 }
989 fileBuffer.append(" return Status;\r\n");
990 }
991 fileBuffer.append("}\r\n\r\n");
992 break;
993
994 case CommonDefinition.ModuleTypeDxeRuntimeDriver:
995 case CommonDefinition.ModuleTypeDxeDriver:
996 case CommonDefinition.ModuleTypeDxeSalDriver:
997 case CommonDefinition.ModuleTypeUefiDriver:
998 case CommonDefinition.ModuleTypeUefiApplication:
999 entryPointCount = 0;
1000 fileBuffer.append("const UINT32 _gUefiDriverRevision = 0;\r\n");
1001 //
1002 // If entry point is null, create a empty ProcessModuleEntryPointList function.
1003 //
1004 if (entryPointList == null || entryPointList.length == 0){
1005 fileBuffer
1006 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = 0;\r\n");
1007 fileBuffer.append("EFI_STATUS\r\n");
1008 fileBuffer.append("EFIAPI\r\n");
1009 fileBuffer.append("ProcessModuleEntryPointList (\r\n");
1010 fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");
1011 fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1012 fileBuffer.append(" )\r\n\r\n");
1013 fileBuffer.append("{\r\n");
1014 fileBuffer.append(" return EFI_SUCCESS;\r\n");
1015 fileBuffer.append("}\r\n");
1016
1017 }else {
1018 for (int i = 0; i < entryPointList.length; i++) {
1019
1020 fileBuffer.append("EFI_STATUS\r\n");
1021 fileBuffer.append("EFIAPI\r\n");
1022 fileBuffer.append(entryPointList[i]);
1023 fileBuffer.append(" (\r\n");
1024 fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");
1025 fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1026 fileBuffer.append(" );\r\n");
1027 entryPointCount++;
1028 }
1029
1030 fileBuffer
1031 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
1032 fileBuffer.append(Integer.toString(entryPointCount));
1033 fileBuffer.append(";\r\n");
1034 if (entryPointCount > 1) {
1035 fileBuffer
1036 .append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");
1037 fileBuffer
1038 .append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n");
1039 }
1040 fileBuffer.append("\n");
1041
1042 fileBuffer.append("EFI_STATUS\r\n");
1043 fileBuffer.append("EFIAPI\r\n");
1044 fileBuffer.append("ProcessModuleEntryPointList (\r\n");
1045 fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");
1046 fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1047 fileBuffer.append(" )\r\n\r\n");
1048 fileBuffer.append("{\r\n");
1049
1050 if (entryPointCount == 1) {
1051 fileBuffer.append(" return (");
1052 fileBuffer.append(entryPointList[0]);
1053 fileBuffer.append(" (ImageHandle, SystemTable));\r\n");
1054 } else {
1055 for (int i = 0; i < entryPointList.length; i++) {
1056 if (!entryPointList[i].equals("")) {
1057 fileBuffer
1058 .append(" if (SetJump (&mJumpContext) == 0) {\r\n");
1059 fileBuffer.append(" ExitDriver (");
1060 fileBuffer.append(entryPointList[i]);
1061 fileBuffer.append(" (ImageHandle, SystemTable));\r\n");
1062 fileBuffer.append(" ASSERT (FALSE);\r\n");
1063 fileBuffer.append(" }\r\n");
1064 } else {
1065 break;
1066 }
1067 }
1068 fileBuffer.append(" return mDriverEntryPointStatus;\r\n");
1069 }
1070 fileBuffer.append("}\r\n\r\n");
1071
1072 fileBuffer.append("VOID\n");
1073 fileBuffer.append("EFIAPI\n");
1074 fileBuffer.append("ExitDriver (\r\n");
1075 fileBuffer.append(" IN EFI_STATUS Status\n");
1076 fileBuffer.append(" )\r\n\r\n");
1077 fileBuffer.append("{\r\n");
1078 if (entryPointCount <= 1) {
1079 fileBuffer.append(" if (EFI_ERROR (Status)) {\r\n");
1080 fileBuffer
1081 .append(" ProcessLibraryDestructorList (gImageHandle, gST);\r\n");
1082 fileBuffer.append(" }\r\n");
1083 fileBuffer
1084 .append(" gBS->Exit (gImageHandle, Status, 0, NULL);\r\n");
1085 } else {
1086 fileBuffer
1087 .append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");
1088 fileBuffer.append(" mDriverEntryPointStatus = Status;\r\n");
1089 fileBuffer.append(" }\r\n");
1090 fileBuffer.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");
1091 fileBuffer.append(" ASSERT (FALSE);\r\n");
1092 }
1093 fileBuffer.append("}\r\n\r\n");
1094
1095 }
1096
1097 //
1098 // Add ModuleUnloadImage for DxeDriver and UefiDriver module type.
1099 //
1100 entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();
1101 //
1102 // Remover duplicate unload entry point.
1103 //
1104 entryPointList = CommonDefinition.remDupString(entryPointList);
1105 entryPointCount = 0;
1106 if (entryPointList != null) {
1107 for (int i = 0; i < entryPointList.length; i++) {
1108 fileBuffer.append("EFI_STATUS\r\n");
1109 fileBuffer.append("EFIAPI\r\n");
1110 fileBuffer.append(entryPointList[i]);
1111 fileBuffer.append(" (\r\n");
1112 fileBuffer
1113 .append(" IN EFI_HANDLE ImageHandle\r\n");
1114 fileBuffer.append(" );\r\n");
1115 entryPointCount++;
1116 }
1117 }
1118
1119 fileBuffer
1120 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");
1121 fileBuffer.append(Integer.toString(entryPointCount));
1122 fileBuffer.append(";\r\n\r\n");
1123
1124 fileBuffer.append("EFI_STATUS\n");
1125 fileBuffer.append("EFIAPI\r\n");
1126 fileBuffer.append("ProcessModuleUnloadList (\r\n");
1127 fileBuffer.append(" IN EFI_HANDLE ImageHandle\r\n");
1128 fileBuffer.append(" )\r\n");
1129 fileBuffer.append("{\r\n");
1130
1131 if (entryPointCount == 0) {
1132 fileBuffer.append(" return EFI_SUCCESS;\r\n");
1133 } else if (entryPointCount == 1) {
1134 fileBuffer.append(" return ");
1135 fileBuffer.append(entryPointList[0]);
1136 fileBuffer.append("(ImageHandle);\r\n");
1137 } else {
1138 fileBuffer.append(" EFI_STATUS Status;\r\n\r\n");
1139 fileBuffer.append(" Status = EFI_SUCCESS;\r\n\r\n");
1140 for (int i = 0; i < entryPointList.length; i++) {
1141 if (i == 0) {
1142 fileBuffer.append(" Status = ");
1143 fileBuffer.append(entryPointList[i]);
1144 fileBuffer.append("(ImageHandle);\r\n");
1145 }else{
1146 fileBuffer.append(" if (EFI_ERROR (Status)) {\r\n");
1147 fileBuffer.append(" ");
1148 fileBuffer.append(entryPointList[i]);
1149 fileBuffer.append("(ImageHandle);\r\n");
1150 fileBuffer.append(" } else {\r\n");
1151 fileBuffer.append(" Status = ");
1152 fileBuffer.append(entryPointList[i]);
1153 fileBuffer.append("(ImageHandle);\r\n");
1154 fileBuffer.append(" }\r\n");
1155 }
1156 }
1157 fileBuffer.append(" return Status;\r\n");
1158 }
1159 fileBuffer.append("}\r\n\r\n");
1160 break;
1161 }
1162 }
1163
1164 /**
1165 * PpiGuidToAutogenc
1166 *
1167 * This function gets GUIDs from SPD file accrodeing to <PPIs> information
1168 * and write those GUIDs to AutoGen.c.
1169 *
1170 * @param fileBuffer
1171 * String Buffer for Autogen.c file.
1172 * @throws BuildException
1173 * Guid must set value!
1174 */
1175 void PpiGuidToAutogenC(StringBuffer fileBuffer) throws AutoGenException {
1176 String[] cNameGuid = null;
1177
1178 //
1179 // Get the all PPI adn PPI Notify from MSA file,
1180 // then add those PPI ,and PPI Notify name to list.
1181 //
1182
1183 String[] ppiList = SurfaceAreaQuery.getPpiArray(this.arch);
1184 for (int i = 0; i < ppiList.length; i++) {
1185 this.mPpiList.add(ppiList[i]);
1186 }
1187
1188 String[] ppiNotifyList = SurfaceAreaQuery.getPpiNotifyArray(this.arch);
1189 for (int i = 0; i < ppiNotifyList.length; i++) {
1190 this.mPpiList.add(ppiNotifyList[i]);
1191 }
1192
1193 //
1194 // Find CNAME and GUID from dependence SPD file and write to Autogen.c
1195 //
1196 Iterator ppiIterator = this.mPpiList.iterator();
1197 String ppiKeyWord = null;
1198 while (ppiIterator.hasNext()) {
1199 ppiKeyWord = ppiIterator.next().toString();
1200 cNameGuid = GlobalData.getPpiGuid(this.mDepPkgList, ppiKeyWord);
1201 if (cNameGuid != null) {
1202 fileBuffer
1203 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1204 fileBuffer.append(cNameGuid[0]);
1205 fileBuffer.append(" = { ");
1206 fileBuffer.append(CommonDefinition.formatGuidName(cNameGuid[1]));
1207 fileBuffer.append(" } ;");
1208 } else {
1209 //
1210 // If can't find Ppi GUID declaration in every package
1211 //
1212 throw new AutoGenException("Can not find Ppi GUID ["
1213 + ppiKeyWord + "] declaration in every packages. ");
1214 }
1215 }
1216 }
1217
1218 /**
1219 * ProtocolGuidToAutogenc
1220 *
1221 * This function gets GUIDs from SPD file accrodeing to <Protocol>
1222 * information and write those GUIDs to AutoGen.c.
1223 *
1224 * @param fileBuffer
1225 * String Buffer for Autogen.c file.
1226 * @throws BuildException
1227 * Protocol name must set.
1228 */
1229 void ProtocolGuidToAutogenC(StringBuffer fileBuffer) throws BuildException {
1230 String[] cNameGuid = null;
1231
1232 String[] protocolList = SurfaceAreaQuery.getProtocolArray(this.arch);
1233
1234 //
1235 // Add result to Autogen global list.
1236 //
1237 for (int i = 0; i < protocolList.length; i++) {
1238 this.mProtocolList.add(protocolList[i]);
1239 }
1240
1241 String[] protocolNotifyList = SurfaceAreaQuery
1242 .getProtocolNotifyArray(this.arch);
1243
1244 for (int i = 0; i < protocolNotifyList.length; i++) {
1245 this.mProtocolList.add(protocolNotifyList[i]);
1246 }
1247
1248 //
1249 // Get the NAME and GUID from dependence SPD and write to Autogen.c
1250 //
1251 Iterator protocolIterator = this.mProtocolList.iterator();
1252 String protocolKeyWord = null;
1253
1254
1255 while (protocolIterator.hasNext()) {
1256 protocolKeyWord = protocolIterator.next().toString();
1257 cNameGuid = GlobalData.getProtocolGuid(this.mDepPkgList, protocolKeyWord);
1258 if (cNameGuid != null) {
1259 fileBuffer
1260 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1261 fileBuffer.append(cNameGuid[0]);
1262 fileBuffer.append(" = { ");
1263 fileBuffer.append(CommonDefinition.formatGuidName(cNameGuid[1]));
1264 fileBuffer.append(" } ;");
1265 } else {
1266 //
1267 // If can't find protocol GUID declaration in every package
1268 //
1269 throw new BuildException("Can not find protocol Guid ["
1270 + protocolKeyWord + "] declaration in every packages. ");
1271 }
1272 }
1273 }
1274
1275 /**
1276 * GuidGuidToAutogenc
1277 *
1278 * This function gets GUIDs from SPD file accrodeing to <Guids> information
1279 * and write those GUIDs to AutoGen.c.
1280 *
1281 * @param fileBuffer
1282 * String Buffer for Autogen.c file.
1283 *
1284 */
1285 void GuidGuidToAutogenC(StringBuffer fileBuffer) throws AutoGenException {
1286 String[] cNameGuid = null;
1287 String guidKeyWord = null;
1288
1289 String[] guidList = SurfaceAreaQuery.getGuidEntryArray(this.arch);
1290
1291 for (int i = 0; i < guidList.length; i++) {
1292 this.mGuidList.add(guidList[i]);
1293 }
1294
1295
1296 Iterator guidIterator = this.mGuidList.iterator();
1297 while (guidIterator.hasNext()) {
1298 guidKeyWord = guidIterator.next().toString();
1299 cNameGuid = GlobalData.getGuid(this.mDepPkgList, guidKeyWord);
1300
1301 if (cNameGuid != null) {
1302 fileBuffer
1303 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1304 fileBuffer.append(cNameGuid[0]);
1305 fileBuffer.append(" = { ");
1306 fileBuffer.append(CommonDefinition.formatGuidName(cNameGuid[1]));
1307 fileBuffer.append("} ;");
1308 } else {
1309 //
1310 // If can't find GUID declaration in every package
1311 //
1312 throw new AutoGenException("Can not find Guid [" + guidKeyWord
1313 + "] declaration in every packages. ");
1314 }
1315
1316 }
1317 }
1318
1319 /**
1320 * LibInstanceToAutogenC
1321 *
1322 * This function adds dependent library instance to autogen.c,which
1323 * includeing library's constructor, destructor, and library dependent ppi,
1324 * protocol, guid, pcd information.
1325 *
1326 * @param fileBuffer
1327 * String buffer for AutoGen.c
1328 * @throws BuildException
1329 */
1330 void LibInstanceToAutogenC(StringBuffer fileBuffer) throws BuildException {
1331 int index;
1332
1333 String moduleType = SurfaceAreaQuery.getModuleType();
1334 List<String> libConstructList = new ArrayList<String>();
1335 List<String> libDestructList = new ArrayList<String>();
1336
1337 String libConstructName = null;
1338 String libDestructName = null;
1339 ModuleIdentification[] libraryIdList = SurfaceAreaQuery
1340 .getLibraryInstance(this.arch);
1341
1342 try {
1343 if (libraryIdList != null) {
1344 //
1345 // Reorder library instance sequence.
1346 //
1347 AutogenLibOrder libOrder = new AutogenLibOrder(libraryIdList,
1348 this.arch);
1349 List<ModuleIdentification> orderList = libOrder
1350 .orderLibInstance();
1351
1352 if (orderList != null) {
1353 //
1354 // Process library instance one by one.
1355 //
1356 for (int i = 0; i < orderList.size(); i++) {
1357
1358 //
1359 // Get library instance basename.
1360 //
1361 ModuleIdentification libInstanceId = orderList.get(i);
1362
1363 //
1364 // Get override map
1365 //
1366
1367 Map<String, XmlObject> libDoc = GlobalData.getDoc(
1368 libInstanceId, this.arch);
1369 SurfaceAreaQuery.push(libDoc);
1370
1371 //
1372 // Get <PPis>, <Protocols>, <Guids> list of this library
1373 // instance.
1374 //
1375 String[] ppiList = SurfaceAreaQuery.getPpiArray(this.arch);
1376 String[] ppiNotifyList = SurfaceAreaQuery
1377 .getPpiNotifyArray(this.arch);
1378 String[] protocolList = SurfaceAreaQuery
1379 .getProtocolArray(this.arch);
1380 String[] protocolNotifyList = SurfaceAreaQuery
1381 .getProtocolNotifyArray(this.arch);
1382 String[] guidList = SurfaceAreaQuery
1383 .getGuidEntryArray(this.arch);
1384 PackageIdentification[] pkgList = SurfaceAreaQuery.getDependencePkg(this.arch);
1385
1386 //
1387 // Add those ppi, protocol, guid in global ppi,
1388 // protocol, guid
1389 // list.
1390 //
1391 for (index = 0; index < ppiList.length; index++) {
1392 this.mPpiList.add(ppiList[index]);
1393 }
1394
1395 for (index = 0; index < ppiNotifyList.length; index++) {
1396 this.mPpiList.add(ppiNotifyList[index]);
1397 }
1398
1399 for (index = 0; index < protocolList.length; index++) {
1400 this.mProtocolList.add(protocolList[index]);
1401 }
1402
1403 for (index = 0; index < protocolNotifyList.length; index++) {
1404 this.mProtocolList.add(protocolNotifyList[index]);
1405 }
1406
1407 for (index = 0; index < guidList.length; index++) {
1408 this.mGuidList.add(guidList[index]);
1409 }
1410 for (index = 0; index < pkgList.length; index++){
1411 if (!this.mDepPkgList.contains(pkgList[index])){
1412 this.mDepPkgList.add(pkgList[index]);
1413 }
1414 }
1415
1416 //
1417 // If not yet parse this library instance's constructor
1418 // element,parse it.
1419 //
1420 libConstructName = SurfaceAreaQuery
1421 .getLibConstructorName();
1422 libDestructName = SurfaceAreaQuery
1423 .getLibDestructorName();
1424
1425 SurfaceAreaQuery.pop();
1426 //
1427 // Add dependent library instance constructor function.
1428 //
1429 if (libConstructName != null) {
1430 libConstructList.add(libConstructName);
1431 }
1432 //
1433 // Add dependent library instance destructor fuction.
1434 //
1435 if (libDestructName != null) {
1436 libDestructList.add(libDestructName);
1437 }
1438 }
1439
1440 }
1441
1442 //
1443 // Add library constructor to AutoGen.c
1444 //
1445 LibConstructorToAutogenC(libConstructList, moduleType,
1446 fileBuffer/* autogenC */);
1447 //
1448 // Add library destructor to AutoGen.c
1449 //
1450 LibDestructorToAutogenC(libDestructList, moduleType, fileBuffer/* autogenC */);
1451 }
1452
1453 } catch (Exception e) {
1454 throw new BuildException(e.getMessage());
1455 }
1456 }
1457
1458 /**
1459 * LibConstructorToAutogenc
1460 *
1461 * This function writes library constructor list to AutoGen.c. The library
1462 * constructor's parameter and return value depend on module type.
1463 *
1464 * @param libInstanceList
1465 * List of library construct name.
1466 * @param moduleType
1467 * Module type.
1468 * @param fileBuffer
1469 * String buffer for AutoGen.c
1470 * @throws Exception
1471 */
1472 void LibConstructorToAutogenC(List<String> libInstanceList,
1473 String moduleType, StringBuffer fileBuffer) throws Exception {
1474 boolean isFirst = true;
1475
1476 //
1477 // The library constructor's parameter and return value depend on
1478 // module type.
1479 //
1480 for (int i = 0; i < libInstanceList.size(); i++) {
1481 switch (CommonDefinition.getModuleType(moduleType)) {
1482 case CommonDefinition.ModuleTypeBase:
1483 fileBuffer.append("RETURN_STATUS\r\n");
1484 fileBuffer.append(libInstanceList.get(i));
1485 fileBuffer.append(" (\r\n");
1486 fileBuffer.append(" VOID\r\n");
1487 fileBuffer.append(" );\r\n");
1488 break;
1489
1490 case CommonDefinition.ModuleTypePeiCore:
1491 case CommonDefinition.ModuleTypePeim:
1492 fileBuffer.append("EFI_STATUS\r\n");
1493 fileBuffer.append(libInstanceList.get(i));
1494 fileBuffer.append(" (\r\n");
1495 fileBuffer
1496 .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1497 fileBuffer
1498 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1499 fileBuffer.append(" );\r\n");
1500 break;
1501
1502 case CommonDefinition.ModuleTypeDxeCore:
1503 case CommonDefinition.ModuleTypeDxeDriver:
1504 case CommonDefinition.ModuleTypeDxeRuntimeDriver:
1505 case CommonDefinition.ModuleTypeDxeSmmDriver:
1506 case CommonDefinition.ModuleTypeDxeSalDriver:
1507 case CommonDefinition.ModuleTypeUefiDriver:
1508 case CommonDefinition.ModuleTypeUefiApplication:
1509 fileBuffer.append("EFI_STATUS\r\n");
1510 fileBuffer.append(libInstanceList.get(i));
1511 fileBuffer.append(" (\r\n");
1512 fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");
1513 fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1514 fileBuffer.append(" );\r\n");
1515 break;
1516 }
1517 }
1518
1519 //
1520 // Add ProcessLibraryConstructorList in AutoGen.c
1521 //
1522 fileBuffer.append("VOID\r\n");
1523 fileBuffer.append("ProcessLibraryConstructorList (\r\n");
1524 switch (CommonDefinition.getModuleType(moduleType)) {
1525 case CommonDefinition.ModuleTypeBase:
1526 fileBuffer.append(" VOID\r\n");
1527 break;
1528
1529 case CommonDefinition.ModuleTypePeiCore:
1530 case CommonDefinition.ModuleTypePeim:
1531 fileBuffer.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1532 fileBuffer
1533 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1534 break;
1535
1536 case CommonDefinition.ModuleTypeDxeCore:
1537 case CommonDefinition.ModuleTypeDxeDriver:
1538 case CommonDefinition.ModuleTypeDxeRuntimeDriver:
1539 case CommonDefinition.ModuleTypeDxeSmmDriver:
1540 case CommonDefinition.ModuleTypeDxeSalDriver:
1541 case CommonDefinition.ModuleTypeUefiDriver:
1542 case CommonDefinition.ModuleTypeUefiApplication:
1543 fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");
1544 fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1545 break;
1546 }
1547
1548 fileBuffer.append(" )\r\n");
1549 fileBuffer.append("{\r\n");
1550 //
1551 // If no constructor function, return EFI_SUCCESS.
1552 //
1553 //if (libInstanceList.size() == 0){
1554 // fileBuffer.append(" return EFI_SUCCESS;\r\n");
1555 //}
1556 for (int i = 0; i < libInstanceList.size(); i++) {
1557 if (isFirst) {
1558 fileBuffer.append(" EFI_STATUS Status;\r\n");
1559 fileBuffer.append(" Status = EFI_SUCCESS;\r\n");
1560 fileBuffer.append("\r\n");
1561 isFirst = false;
1562 }
1563 switch (CommonDefinition.getModuleType(moduleType)) {
1564 case CommonDefinition.ModuleTypeBase:
1565 fileBuffer.append(" Status = ");
1566 fileBuffer.append(libInstanceList.get(i));
1567 fileBuffer.append("();\r\n");
1568 fileBuffer.append(" VOID\r\n");
1569 break;
1570 case CommonDefinition.ModuleTypePeiCore:
1571 case CommonDefinition.ModuleTypePeim:
1572 fileBuffer.append(" Status = ");
1573 fileBuffer.append(libInstanceList.get(i));
1574 fileBuffer.append(" (FfsHeader, PeiServices);\r\n");
1575 break;
1576 case CommonDefinition.ModuleTypeDxeCore:
1577 case CommonDefinition.ModuleTypeDxeDriver:
1578 case CommonDefinition.ModuleTypeDxeRuntimeDriver:
1579 case CommonDefinition.ModuleTypeDxeSmmDriver:
1580 case CommonDefinition.ModuleTypeDxeSalDriver:
1581 case CommonDefinition.ModuleTypeUefiDriver:
1582 case CommonDefinition.ModuleTypeUefiApplication:
1583 fileBuffer.append(" Status = ");
1584 fileBuffer.append(libInstanceList.get(i));
1585 fileBuffer.append(" (ImageHandle, SystemTable);\r\n");
1586 break;
1587 default:
1588 EdkLog.log(EdkLog.EDK_INFO,"Autogen don't know how to deal with module type -"+ moduleType + " !");
1589 }
1590 fileBuffer.append(" ASSERT_EFI_ERROR (Status);\r\n");
1591 }
1592 fileBuffer.append("}\r\n");
1593 }
1594
1595 /**
1596 * LibDestructorToAutogenc
1597 *
1598 * This function writes library destructor list to AutoGen.c. The library
1599 * destructor's parameter and return value depend on module type.
1600 *
1601 * @param libInstanceList
1602 * List of library destructor name.
1603 * @param moduleType
1604 * Module type.
1605 * @param fileBuffer
1606 * String buffer for AutoGen.c
1607 * @throws Exception
1608 */
1609 void LibDestructorToAutogenC(List<String> libInstanceList,
1610 String moduleType, StringBuffer fileBuffer) throws Exception {
1611 boolean isFirst = true;
1612 for (int i = 0; i < libInstanceList.size(); i++) {
1613 switch (CommonDefinition.getModuleType(moduleType)) {
1614 case CommonDefinition.ModuleTypeBase:
1615 fileBuffer.append("RETURN_STATUS\n");
1616 fileBuffer.append(libInstanceList.get(i));
1617 fileBuffer.append(" (\r\n");
1618 fileBuffer.append(" VOID\r\n");
1619 fileBuffer.append(" );\r\n");
1620 break;
1621 case CommonDefinition.ModuleTypePeiCore:
1622 case CommonDefinition.ModuleTypePeim:
1623 fileBuffer.append("EFI_STATUS\r\n");
1624 fileBuffer.append(libInstanceList.get(i));
1625 fileBuffer.append(" (\r\n");
1626 fileBuffer
1627 .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1628 fileBuffer
1629 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1630 fileBuffer.append(" );\r\n");
1631 break;
1632 case CommonDefinition.ModuleTypeDxeCore:
1633 case CommonDefinition.ModuleTypeDxeDriver:
1634 case CommonDefinition.ModuleTypeDxeRuntimeDriver:
1635 case CommonDefinition.ModuleTypeDxeSmmDriver:
1636 case CommonDefinition.ModuleTypeDxeSalDriver:
1637 case CommonDefinition.ModuleTypeUefiDriver:
1638 case CommonDefinition.ModuleTypeUefiApplication:
1639 fileBuffer.append("EFI_STATUS\r\n");
1640 fileBuffer.append(libInstanceList.get(i));
1641 fileBuffer.append(" (\r\n");
1642 fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");
1643 fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1644 fileBuffer.append(" );\r\n");
1645 break;
1646 }
1647 }
1648
1649 //
1650 // Write ProcessLibraryDestructor list to autogen.c
1651 //
1652 switch (CommonDefinition.getModuleType(moduleType)) {
1653 case CommonDefinition.ModuleTypeBase:
1654 case CommonDefinition.ModuleTypePeiCore:
1655 case CommonDefinition.ModuleTypePeim:
1656 break;
1657 case CommonDefinition.ModuleTypeDxeCore:
1658 case CommonDefinition.ModuleTypeDxeDriver:
1659 case CommonDefinition.ModuleTypeDxeRuntimeDriver:
1660 case CommonDefinition.ModuleTypeDxeSmmDriver:
1661 case CommonDefinition.ModuleTypeDxeSalDriver:
1662 case CommonDefinition.ModuleTypeUefiDriver:
1663 case CommonDefinition.ModuleTypeUefiApplication:
1664 fileBuffer.append("VOID\r\n");
1665 fileBuffer.append("ProcessLibraryDestructorList (\r\n");
1666 fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");
1667 fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1668 fileBuffer.append(" )\r\n");
1669 fileBuffer.append("{\r\n");
1670 //
1671 // If no library destructor function, return EFI_SUCCESS.
1672 //
1673
1674 for (int i = 0; i < libInstanceList.size(); i++) {
1675 if (isFirst) {
1676 fileBuffer.append(" EFI_STATUS Status;\r\n");
1677 fileBuffer.append(" Status = EFI_SUCCESS;\r\n");
1678 fileBuffer.append("\r\n");
1679 isFirst = false;
1680 }
1681 fileBuffer.append(" Status = ");
1682 fileBuffer.append(libInstanceList.get(i));
1683 fileBuffer.append("(ImageHandle, SystemTable);\r\n");
1684 fileBuffer.append(" ASSERT_EFI_ERROR (Status);\r\n");
1685 }
1686 fileBuffer.append("}\r\n");
1687 break;
1688 }
1689 }
1690
1691 /**
1692 * ExternsDriverBindingToAutoGenC
1693 *
1694 * This function is to write DRIVER_BINDING, COMPONENT_NAME,
1695 * DRIVER_CONFIGURATION, DRIVER_DIAGNOSTIC in AutoGen.c.
1696 *
1697 * @param fileBuffer
1698 * String buffer for AutoGen.c
1699 */
1700 void ExternsDriverBindingToAutoGenC(StringBuffer fileBuffer)
1701 throws BuildException {
1702
1703 //
1704 // Check what <extern> contains. And the number of following elements
1705 // under <extern> should be same. 1. DRIVER_BINDING 2. COMPONENT_NAME
1706 // 3.DRIVER_CONFIGURATION 4. DRIVER_DIAGNOSTIC
1707 //
1708
1709 String[] drvBindList = SurfaceAreaQuery.getDriverBindingArray();
1710
1711 //
1712 // If component name protocol,component configuration protocol,
1713 // component diagnostic protocol is not null or empty, check
1714 // if every one have the same number of the driver binding protocol.
1715 //
1716 if (drvBindList == null || drvBindList.length == 0) {
1717 return;
1718 }
1719
1720 String[] compNamList = SurfaceAreaQuery.getComponentNameArray();
1721 String[] compConfList = SurfaceAreaQuery.getDriverConfigArray();
1722 String[] compDiagList = SurfaceAreaQuery.getDriverDiagArray();
1723
1724 int BitMask = 0;
1725
1726 //
1727 // Write driver binding protocol extern to autogen.c
1728 //
1729 for (int i = 0; i < drvBindList.length; i++) {
1730 fileBuffer.append("extern EFI_DRIVER_BINDING_PROTOCOL ");
1731 fileBuffer.append(drvBindList[i]);
1732 fileBuffer.append(";\r\n");
1733 }
1734
1735 //
1736 // Write component name protocol extern to autogen.c
1737 //
1738 if (compNamList != null && compNamList.length != 0) {
1739 if (drvBindList.length != compNamList.length) {
1740 throw new BuildException(
1741 "Different number of Driver Binding and Component Name protocols!");
1742 }
1743
1744 BitMask |= 0x01;
1745 for (int i = 0; i < compNamList.length; i++) {
1746 fileBuffer.append("extern EFI_COMPONENT_NAME_PROTOCOL ");
1747 fileBuffer.append(compNamList[i]);
1748 fileBuffer.append(";\r\n");
1749 }
1750 }
1751
1752 //
1753 // Write driver configration protocol extern to autogen.c
1754 //
1755 if (compConfList != null && compConfList.length != 0) {
1756 if (drvBindList.length != compConfList.length) {
1757 throw new BuildException(
1758 "Different number of Driver Binding and Driver Configuration protocols!");
1759 }
1760
1761 BitMask |= 0x02;
1762 for (int i = 0; i < compConfList.length; i++) {
1763 fileBuffer.append("extern EFI_DRIVER_CONFIGURATION_PROTOCOL ");
1764 fileBuffer.append(compConfList[i]);
1765 fileBuffer.append(";\r\n");
1766 }
1767 }
1768
1769 //
1770 // Write driver dignastic protocol extern to autogen.c
1771 //
1772 if (compDiagList != null && compDiagList.length != 0) {
1773 if (drvBindList.length != compDiagList.length) {
1774 throw new BuildException(
1775 "Different number of Driver Binding and Driver Configuration protocols!");
1776 }
1777
1778 BitMask |= 0x04;
1779 for (int i = 0; i < compDiagList.length; i++) {
1780 fileBuffer.append("extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL ");
1781 fileBuffer.append(compDiagList[i]);
1782 fileBuffer.append(";\r\n");
1783 }
1784 }
1785
1786 //
1787 // Write driver module protocol bitmask.
1788 //
1789 fileBuffer
1790 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverModelProtocolBitmask = ");
1791 fileBuffer.append(Integer.toString(BitMask));
1792 fileBuffer.append(";\r\n");
1793
1794 //
1795 // Write driver module protocol list entry
1796 //
1797 fileBuffer
1798 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverModelProtocolListEntries = ");
1799
1800 fileBuffer.append(Integer.toString(drvBindList.length));
1801 fileBuffer.append(";\r\n");
1802
1803 //
1804 // Write drive module protocol list to autogen.c
1805 //
1806 fileBuffer
1807 .append("GLOBAL_REMOVE_IF_UNREFERENCED const EFI_DRIVER_MODEL_PROTOCOL_LIST _gDriverModelProtocolList[] = {");
1808 for (int i = 0; i < drvBindList.length; i++) {
1809 if (i != 0) {
1810 fileBuffer.append(",");
1811 }
1812 fileBuffer.append("\r\n {\r\n");
1813 fileBuffer.append(" &");
1814 fileBuffer.append(drvBindList[i]);
1815 fileBuffer.append(", \r\n");
1816
1817 if (compNamList != null) {
1818 fileBuffer.append(" &");
1819 fileBuffer.append(compNamList[i]);
1820 fileBuffer.append(", \r\n");
1821 } else {
1822 fileBuffer.append(" NULL, \r\n");
1823 }
1824
1825 if (compConfList != null) {
1826 fileBuffer.append(" &");
1827 fileBuffer.append(compConfList[i]);
1828 fileBuffer.append(", \r\n");
1829 } else {
1830 fileBuffer.append(" NULL, \r\n");
1831 }
1832
1833 if (compDiagList != null) {
1834 fileBuffer.append(" &");
1835 fileBuffer.append(compDiagList[i]);
1836 fileBuffer.append(", \r\n");
1837 } else {
1838 fileBuffer.append(" NULL, \r\n");
1839 }
1840 fileBuffer.append(" }");
1841 }
1842 fileBuffer.append("\r\n};\r\n");
1843 }
1844
1845 /**
1846 * ExternCallBackToAutoGenC
1847 *
1848 * This function adds <SetVirtualAddressMapCallBack> and
1849 * <ExitBootServicesCallBack> infomation to AutoGen.c
1850 *
1851 * @param fileBuffer
1852 * String buffer for AutoGen.c
1853 * @throws BuildException
1854 */
1855 void ExternCallBackToAutoGenC(StringBuffer fileBuffer)
1856 throws BuildException {
1857 String[] setVirtualList = SurfaceAreaQuery
1858 .getSetVirtualAddressMapCallBackArray();
1859 String[] exitBootList = SurfaceAreaQuery
1860 .getExitBootServicesCallBackArray();
1861 String moduleType = SurfaceAreaQuery.getModuleType();
1862 boolean UefiOrDxeModule = false;
1863 int Count = 0;
1864 int i;
1865
1866 switch (CommonDefinition.getModuleType(moduleType)) {
1867 case CommonDefinition.ModuleTypeDxeDriver:
1868 case CommonDefinition.ModuleTypeDxeRuntimeDriver:
1869 case CommonDefinition.ModuleTypeDxeSalDriver:
1870 case CommonDefinition.ModuleTypeUefiDriver:
1871 case CommonDefinition.ModuleTypeUefiApplication:
1872 //
1873 // Entry point lib for these module types needs to know the count
1874 // of entryPoint.
1875 //
1876 UefiOrDxeModule = true;
1877 fileBuffer
1878 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverSetVirtualAddressMapEventCount = ");
1879
1880 //
1881 // If the list is not valid or has no entries set count to zero else
1882 // set count to the number of valid entries
1883 //
1884 Count = 0;
1885 if (setVirtualList != null) {
1886 for (i = 0; i < setVirtualList.length; i++) {
1887 if (setVirtualList[i].equalsIgnoreCase("")) {
1888 break;
1889 }
1890 }
1891 Count = i;
1892 }
1893
1894 fileBuffer.append(Integer.toString(Count));
1895 fileBuffer.append(";\r\n\r\n");
1896 break;
1897 default:
1898 break;
1899 }
1900
1901 if (setVirtualList == null) {
1902 if (UefiOrDxeModule) {
1903 //
1904 // No data so make a NULL list
1905 //
1906 fileBuffer
1907 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {\r\n");
1908 fileBuffer.append(" NULL\r\n");
1909 fileBuffer.append("};\r\n\r\n");
1910 }
1911 } else {
1912 //
1913 // Write SetVirtualAddressMap function definition.
1914 //
1915 for (i = 0; i < setVirtualList.length; i++) {
1916 if (setVirtualList[i].equalsIgnoreCase("")) {
1917 break;
1918 }
1919 fileBuffer.append("VOID\r\n");
1920 fileBuffer.append("EFIAPI\r\n");
1921 fileBuffer.append(setVirtualList[i]);
1922 fileBuffer.append(" (\r\n");
1923 fileBuffer.append(" IN EFI_EVENT Event,\r\n");
1924 fileBuffer.append(" IN VOID *Context\r\n");
1925 fileBuffer.append(" );\r\n\r\n");
1926 }
1927
1928 //
1929 // Write SetVirtualAddressMap entry point array.
1930 //
1931 fileBuffer
1932 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {");
1933 for (i = 0; i < setVirtualList.length; i++) {
1934 if (setVirtualList[i].equalsIgnoreCase("")) {
1935 break;
1936 }
1937
1938 if (i == 0) {
1939 fileBuffer.append("\r\n ");
1940 } else {
1941 fileBuffer.append(",\r\n ");
1942 }
1943
1944 fileBuffer.append(setVirtualList[i]);
1945 }
1946 //
1947 // If module is not DXE_DRIVER, DXE_RUNTIME_DIRVER, UEFI_DRIVER
1948 // UEFI_APPLICATION and DXE_SAL_DRIVER add the NULL at the end of
1949 // _gDriverSetVirtualAddressMapEvent list.
1950 //
1951 if (!UefiOrDxeModule) {
1952 fileBuffer.append(",\r\n NULL");
1953 }
1954 fileBuffer.append("\r\n};\r\n\r\n");
1955 }
1956
1957 if (UefiOrDxeModule) {
1958 //
1959 // Entry point lib for these module types needs to know the count.
1960 //
1961 fileBuffer
1962 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverExitBootServicesEventCount = ");
1963
1964 //
1965 // If the list is not valid or has no entries set count to zero else
1966 // set count to the number of valid entries.
1967 //
1968 Count = 0;
1969 if (exitBootList != null) {
1970 if (setVirtualList != null) {
1971 for (i = 0; i < exitBootList.length; i++) {
1972 if (exitBootList[i].equalsIgnoreCase("")) {
1973 break;
1974 }
1975 }
1976 Count = i;
1977 }
1978 }
1979 fileBuffer.append(Integer.toString(Count));
1980 fileBuffer.append(";\r\n\r\n");
1981 }
1982
1983 if (exitBootList == null) {
1984 if (UefiOrDxeModule) {
1985 //
1986 // No data so make a NULL list.
1987 //
1988 fileBuffer
1989 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {\r\n");
1990 fileBuffer.append(" NULL\r\n");
1991 fileBuffer.append("};\r\n\r\n");
1992 }
1993 } else {
1994 //
1995 // Write DriverExitBootServices function definition.
1996 //
1997 for (i = 0; i < exitBootList.length; i++) {
1998 if (exitBootList[i].equalsIgnoreCase("")) {
1999 break;
2000 }
2001
2002 fileBuffer.append("VOID\r\n");
2003 fileBuffer.append("EFIAPI\r\n");
2004 fileBuffer.append(exitBootList[i]);
2005 fileBuffer.append(" (\r\n");
2006 fileBuffer.append(" IN EFI_EVENT Event,\r\n");
2007 fileBuffer.append(" IN VOID *Context\r\n");
2008 fileBuffer.append(" );\r\n\r\n");
2009 }
2010
2011 //
2012 // Write DriverExitBootServices entry point array.
2013 //
2014 fileBuffer
2015 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {");
2016 for (i = 0; i < exitBootList.length; i++) {
2017 if (exitBootList[i].equalsIgnoreCase("")) {
2018 break;
2019 }
2020
2021 if (i == 0) {
2022 fileBuffer.append("\r\n ");
2023 } else {
2024 fileBuffer.append(",\r\n ");
2025 }
2026 fileBuffer.append(exitBootList[i]);
2027 }
2028 if (!UefiOrDxeModule) {
2029 fileBuffer.append(",\r\n NULL");
2030 }
2031 fileBuffer.append("\r\n};\r\n\r\n");
2032 }
2033
2034 }
2035
2036 }