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