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