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