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