]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/autogen/AutoGen.java
7de80e6c72ea4d1ed98727b6af70b2ebe7ccc73e
[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) {
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
886 .append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");
887 fileBuffer
888 .append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n\r\n");
889
890 fileBuffer.append("EFI_STATUS\r\n");
891 fileBuffer.append("EFIAPI\r\n");
892 fileBuffer.append("ProcessModuleEntryPointList (\r\n");
893 fileBuffer.append(" EFI_HANDLE ImageHandle,\r\n");
894 fileBuffer.append(" EFI_SYSTEM_TABLE *SystemTable\r\n");
895 fileBuffer.append(" )\r\n\r\n");
896 fileBuffer.append("{\r\n");
897 fileBuffer.append(" return EFI_SUCCESS;\r\n");
898 fileBuffer.append("}\r\n\r\n");
899 break;
900 } else {
901 for (int i = 0; i < entryPointList.length; i++) {
902 if (!entryPointList[i].equals("")) {
903 fileBuffer.append("EFI_STATUS\r\n");
904 fileBuffer.append("EFIAPI\r\n");
905 fileBuffer.append(entryPointList[i]);
906 fileBuffer.append(" (\r\n");
907 fileBuffer.append(" EFI_HANDLE ImageHandle,\r\n");
908 fileBuffer.append(" EFI_SYSTEM_TABLE *SystemTable\r\n");
909 fileBuffer.append(" );\r\n");
910 entryPointCount++;
911 } else {
912 break;
913 }
914 }
915 fileBuffer
916 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
917 fileBuffer.append(Integer.toString(entryPointCount));
918 fileBuffer.append(";\r\n");
919 fileBuffer
920 .append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");
921 fileBuffer
922 .append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n\r\n");
923
924 fileBuffer.append("EFI_STATUS\r\n");
925 fileBuffer.append("EFIAPI\r\n");
926 fileBuffer.append("ProcessModuleEntryPointList (\r\n");
927 fileBuffer.append(" EFI_HANDLE ImageHandle,\r\n");
928 fileBuffer.append(" EFI_SYSTEM_TABLE *SystemTable\r\n");
929 fileBuffer.append(" )\r\n\r\n");
930 fileBuffer.append("{\r\n");
931
932
933 for (int i = 0; i < entryPointList.length; i++) {
934 fileBuffer
935 .append(" if (SetJump (&mJumpContext) == 0) {\r\n");
936 fileBuffer.append(" ExitDriver (");
937 fileBuffer.append(entryPointList[i]);
938 fileBuffer.append(" (ImageHandle, SystemTable));\r\n");
939 fileBuffer.append(" ASSERT (FALSE);\r\n");
940 fileBuffer.append(" }\r\n");
941
942 }
943 fileBuffer.append(" return mDriverEntryPointStatus;\r\n");
944 fileBuffer.append("}\r\n\r\n");
945
946 fileBuffer.append("VOID\r\n");
947 fileBuffer.append("EFIAPI\r\n");
948 fileBuffer.append("ExitDriver (\r\n");
949 fileBuffer.append(" IN EFI_STATUS Status\n");
950 fileBuffer.append(" )\r\n\r\n");
951 fileBuffer.append("{\r\n");
952 fileBuffer
953 .append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");
954 fileBuffer.append(" mDriverEntryPointStatus = Status;\r\n");
955 fileBuffer.append(" }\r\n");
956 fileBuffer.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");
957 fileBuffer.append(" ASSERT (FALSE);\r\n");
958 fileBuffer.append("}\r\n\r\n");
959
960 }
961
962
963 //
964 // Add "ModuleUnloadImage" for DxeSmmDriver module type;
965 //
966 entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();
967 entryPointList = CommonDefinition.remDupString(entryPointList);
968 entryPointCount = 0;
969
970 fileBuffer
971 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");
972 fileBuffer.append(Integer.toString(entryPointCount));
973 fileBuffer.append(";\r\n\r\n");
974
975 if (entryPointList != null) {
976 for (int i = 0; i < entryPointList.length; i++) {
977 if (!entryPointList[i].equals("")) {
978 fileBuffer.append("EFI_STATUS\r\n");
979 fileBuffer.append("EFIAPI\r\n");
980 fileBuffer.append(entryPointList[i]);
981 fileBuffer.append(" (\r\n");
982 fileBuffer
983 .append(" EFI_HANDLE ImageHandle\r\n");
984 fileBuffer.append(" );\r\n");
985 } else {
986 break;
987 }
988 }
989 }
990
991 fileBuffer.append("EFI_STATUS\r\n");
992 fileBuffer.append("EFIAPI\r\n");
993 fileBuffer.append("ProcessModuleUnloadList (\r\n");
994 fileBuffer.append(" EFI_HANDLE ImageHandle\r\n");
995 fileBuffer.append(" )\r\n");
996 fileBuffer.append("{\r\n");
997
998 if (entryPointCount == 0) {
999 fileBuffer.append(" return EFI_SUCCESS;\r\n");
1000 } else if (entryPointCount == 1) {
1001 fileBuffer.append(" return ");
1002 fileBuffer.append(entryPointList[0]);
1003 fileBuffer.append("(ImageHandle);\r\n");
1004 } else {
1005 fileBuffer.append(" EFI_STATUS Status;\r\n\r\n");
1006 fileBuffer.append(" Status = EFI_SUCCESS;\r\n\r\n");
1007 for (int i = 0; i < entryPointList.length; i++) {
1008 if (i == 0){
1009 fileBuffer.append(" Status = ");
1010 fileBuffer.append(entryPointList[i]);
1011 fileBuffer.append("(ImageHandle);\r\n");
1012 }else{
1013 fileBuffer.append(" if (EFI_ERROR (Status)) {\r\n");
1014 fileBuffer.append(" ");
1015 fileBuffer.append(entryPointList[i]);
1016 fileBuffer.append("(ImageHandle);\r\n");
1017 fileBuffer.append(" } else {\r\n");
1018 fileBuffer.append(" Status = ");
1019 fileBuffer.append(entryPointList[i]);
1020 fileBuffer.append("(ImageHandle);\r\n");
1021 fileBuffer.append(" }\r\n");
1022 }
1023 }
1024 fileBuffer.append(" return Status;\r\n");
1025 }
1026 fileBuffer.append("}\r\n\r\n");
1027 break;
1028
1029 case CommonDefinition.ModuleTypeDxeRuntimeDriver:
1030 case CommonDefinition.ModuleTypeDxeDriver:
1031 case CommonDefinition.ModuleTypeDxeSalDriver:
1032 case CommonDefinition.ModuleTypeUefiDriver:
1033 case CommonDefinition.ModuleTypeUefiApplication:
1034 entryPointCount = 0;
1035 fileBuffer.append("const UINT32 _gUefiDriverRevision = 0;\r\n");
1036 //
1037 // If entry point is null, create a empty ProcessModuleEntryPointList function.
1038 //
1039 if (entryPointList == null || entryPointList.length == 0){
1040 fileBuffer
1041 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = 0;\r\n");
1042 fileBuffer.append("EFI_STATUS\r\n");
1043 fileBuffer.append("EFIAPI\r\n");
1044 fileBuffer.append("ProcessModuleEntryPointList (\r\n");
1045 fileBuffer.append(" EFI_HANDLE ImageHandle,\r\n");
1046 fileBuffer.append(" EFI_SYSTEM_TABLE *SystemTable\r\n");
1047 fileBuffer.append(" )\r\n\r\n");
1048 fileBuffer.append("{\r\n");
1049 fileBuffer.append(" return EFI_SUCCESS;\r\n");
1050 fileBuffer.append("}\r\n");
1051
1052 }else {
1053 for (int i = 0; i < entryPointList.length; i++) {
1054
1055 fileBuffer.append("EFI_STATUS\r\n");
1056 fileBuffer.append("EFIAPI\r\n");
1057 fileBuffer.append(entryPointList[i]);
1058 fileBuffer.append(" (\r\n");
1059 fileBuffer.append(" EFI_HANDLE ImageHandle,\r\n");
1060 fileBuffer.append(" EFI_SYSTEM_TABLE *SystemTable\r\n");
1061 fileBuffer.append(" );\r\n");
1062 entryPointCount++;
1063 }
1064
1065 fileBuffer
1066 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");
1067 fileBuffer.append(Integer.toString(entryPointCount));
1068 fileBuffer.append(";\r\n");
1069 if (entryPointCount > 1) {
1070 fileBuffer
1071 .append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");
1072 fileBuffer
1073 .append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n");
1074 }
1075 fileBuffer.append("\n");
1076
1077 fileBuffer.append("EFI_STATUS\r\n");
1078 fileBuffer.append("EFIAPI\r\n");
1079 fileBuffer.append("ProcessModuleEntryPointList (\r\n");
1080 fileBuffer.append(" EFI_HANDLE ImageHandle,\r\n");
1081 fileBuffer.append(" EFI_SYSTEM_TABLE *SystemTable\r\n");
1082 fileBuffer.append(" )\r\n\r\n");
1083 fileBuffer.append("{\r\n");
1084
1085 if (entryPointCount == 1) {
1086 fileBuffer.append(" return (");
1087 fileBuffer.append(entryPointList[0]);
1088 fileBuffer.append(" (ImageHandle, SystemTable));\r\n");
1089 } else {
1090 for (int i = 0; i < entryPointList.length; i++) {
1091 if (!entryPointList[i].equals("")) {
1092 fileBuffer
1093 .append(" if (SetJump (&mJumpContext) == 0) {\r\n");
1094 fileBuffer.append(" ExitDriver (");
1095 fileBuffer.append(entryPointList[i]);
1096 fileBuffer.append(" (ImageHandle, SystemTable));\r\n");
1097 fileBuffer.append(" ASSERT (FALSE);\r\n");
1098 fileBuffer.append(" }\r\n");
1099 } else {
1100 break;
1101 }
1102 }
1103 fileBuffer.append(" return mDriverEntryPointStatus;\r\n");
1104 }
1105 fileBuffer.append("}\r\n\r\n");
1106
1107 fileBuffer.append("VOID\n");
1108 fileBuffer.append("EFIAPI\n");
1109 fileBuffer.append("ExitDriver (\r\n");
1110 fileBuffer.append(" IN EFI_STATUS Status\n");
1111 fileBuffer.append(" )\r\n\r\n");
1112 fileBuffer.append("{\r\n");
1113 if (entryPointCount <= 1) {
1114 fileBuffer.append(" if (EFI_ERROR (Status)) {\r\n");
1115 fileBuffer
1116 .append(" ProcessLibraryDestructorList (gImageHandle, gST);\r\n");
1117 fileBuffer.append(" }\r\n");
1118 fileBuffer
1119 .append(" gBS->Exit (gImageHandle, Status, 0, NULL);\r\n");
1120 } else {
1121 fileBuffer
1122 .append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");
1123 fileBuffer.append(" mDriverEntryPointStatus = Status;\r\n");
1124 fileBuffer.append(" }\r\n");
1125 fileBuffer.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");
1126 fileBuffer.append(" ASSERT (FALSE);\r\n");
1127 }
1128 fileBuffer.append("}\r\n\r\n");
1129
1130 }
1131
1132 //
1133 // Add ModuleUnloadImage for DxeDriver and UefiDriver module type.
1134 //
1135 entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();
1136 //
1137 // Remover duplicate unload entry point.
1138 //
1139 entryPointList = CommonDefinition.remDupString(entryPointList);
1140 entryPointCount = 0;
1141 if (entryPointList != null) {
1142 for (int i = 0; i < entryPointList.length; i++) {
1143 if (!entryPointList[i].equals("")) {
1144 fileBuffer.append("EFI_STATUS\r\n");
1145 fileBuffer.append("EFIAPI\r\n");
1146 fileBuffer.append(entryPointList[i]);
1147 fileBuffer.append(" (\r\n");
1148 fileBuffer
1149 .append(" EFI_HANDLE ImageHandle\r\n");
1150 fileBuffer.append(" );\r\n");
1151 entryPointCount++;
1152 } else {
1153 break;
1154 }
1155 }
1156 }
1157
1158 fileBuffer
1159 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");
1160 fileBuffer.append(Integer.toString(entryPointCount));
1161 fileBuffer.append(";\r\n\r\n");
1162
1163 if (entryPointList != null) {
1164 for (int i = 0; i < entryPointList.length; i++) {
1165 if (!entryPointList[i].equals("")) {
1166 fileBuffer.append("EFI_STATUS\r\n");
1167 fileBuffer.append("EFIAPI\r\n");
1168 fileBuffer.append(entryPointList[i]);
1169 fileBuffer.append(" (\r\n");
1170 fileBuffer
1171 .append(" EFI_HANDLE ImageHandle\r\n");
1172 fileBuffer.append(" );\r\n");
1173 } else {
1174 break;
1175 }
1176 }
1177 }
1178
1179 fileBuffer.append("EFI_STATUS\n");
1180 fileBuffer.append("EFIAPI\r\n");
1181 fileBuffer.append("ProcessModuleUnloadList (\r\n");
1182 fileBuffer.append(" EFI_HANDLE ImageHandle\r\n");
1183 fileBuffer.append(" )\r\n");
1184 fileBuffer.append("{\r\n");
1185
1186 if (entryPointCount == 0) {
1187 fileBuffer.append(" return EFI_SUCCESS;\r\n");
1188 } else if (entryPointCount == 1) {
1189 fileBuffer.append(" return ");
1190 fileBuffer.append(entryPointList[0]);
1191 fileBuffer.append("(ImageHandle);\r\n");
1192 } else {
1193 fileBuffer.append(" EFI_STATUS Status;\r\n\r\n");
1194 fileBuffer.append(" Status = EFI_SUCCESS;\r\n\r\n");
1195 for (int i = 0; i < entryPointList.length; i++) {
1196 if (!entryPointList[i].equals("")) {
1197 fileBuffer.append(" if (EFI_ERROR (Status)) {\r\n");
1198 fileBuffer.append(" ");
1199 fileBuffer.append(entryPointList[i]);
1200 fileBuffer.append("(ImageHandle);\r\n");
1201 fileBuffer.append(" } else {\r\n");
1202 fileBuffer.append(" Status = ");
1203 fileBuffer.append(entryPointList[i]);
1204 fileBuffer.append("(ImageHandle);\r\n");
1205 fileBuffer.append(" }\r\n");
1206 } else {
1207 break;
1208 }
1209 }
1210 fileBuffer.append(" return Status;\r\n");
1211 }
1212 fileBuffer.append("}\r\n\r\n");
1213 break;
1214 }
1215 }
1216
1217 /**
1218 * PpiGuidToAutogenc
1219 *
1220 * This function gets GUIDs from SPD file accrodeing to <PPIs> information
1221 * and write those GUIDs to AutoGen.c.
1222 *
1223 * @param fileBuffer
1224 * String Buffer for Autogen.c file.
1225 * @throws BuildException
1226 * Guid must set value!
1227 */
1228 void PpiGuidToAutogenC(StringBuffer fileBuffer) throws AutoGenException {
1229 String[] cNameGuid = null;
1230
1231 //
1232 // Get the all PPI adn PPI Notify from MSA file,
1233 // then add those PPI ,and PPI Notify name to list.
1234 //
1235
1236 String[] ppiList = SurfaceAreaQuery.getPpiArray(this.arch);
1237 for (int i = 0; i < ppiList.length; i++) {
1238 this.mPpiList.add(ppiList[i]);
1239 }
1240
1241 String[] ppiNotifyList = SurfaceAreaQuery.getPpiNotifyArray(this.arch);
1242 for (int i = 0; i < ppiNotifyList.length; i++) {
1243 this.mPpiList.add(ppiNotifyList[i]);
1244 }
1245
1246 //
1247 // Find CNAME and GUID from dependence SPD file and write to Autogen.c
1248 //
1249 Iterator ppiIterator = this.mPpiList.iterator();
1250 String ppiKeyWord = null;
1251 while (ppiIterator.hasNext()) {
1252 ppiKeyWord = ppiIterator.next().toString();
1253 cNameGuid = GlobalData.getPpiGuid(this.mDepPkgList, ppiKeyWord);
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 Ppi GUID declaration in every package
1264 //
1265 throw new AutoGenException("Can not find Ppi GUID ["
1266 + ppiKeyWord + "] declaration in every packages. ");
1267 }
1268 }
1269 }
1270
1271 /**
1272 * ProtocolGuidToAutogenc
1273 *
1274 * This function gets GUIDs from SPD file accrodeing to <Protocol>
1275 * information and write those GUIDs to AutoGen.c.
1276 *
1277 * @param fileBuffer
1278 * String Buffer for Autogen.c file.
1279 * @throws BuildException
1280 * Protocol name must set.
1281 */
1282 void ProtocolGuidToAutogenC(StringBuffer fileBuffer) throws BuildException {
1283 String[] cNameGuid = null;
1284
1285 String[] protocolList = SurfaceAreaQuery.getProtocolArray(this.arch);
1286
1287 //
1288 // Add result to Autogen global list.
1289 //
1290 for (int i = 0; i < protocolList.length; i++) {
1291 this.mProtocolList.add(protocolList[i]);
1292 }
1293
1294 String[] protocolNotifyList = SurfaceAreaQuery
1295 .getProtocolNotifyArray(this.arch);
1296
1297 for (int i = 0; i < protocolNotifyList.length; i++) {
1298 this.mProtocolList.add(protocolNotifyList[i]);
1299 }
1300
1301 //
1302 // Get the NAME and GUID from dependence SPD and write to Autogen.c
1303 //
1304 Iterator protocolIterator = this.mProtocolList.iterator();
1305 String protocolKeyWord = null;
1306
1307
1308 while (protocolIterator.hasNext()) {
1309 protocolKeyWord = protocolIterator.next().toString();
1310 cNameGuid = GlobalData.getProtocolGuid(this.mDepPkgList, protocolKeyWord);
1311 if (cNameGuid != null) {
1312 fileBuffer
1313 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1314 fileBuffer.append(cNameGuid[0]);
1315 fileBuffer.append(" = { ");
1316 fileBuffer.append(CommonDefinition.formatGuidName(cNameGuid[1]));
1317 fileBuffer.append(" } ;");
1318 } else {
1319 //
1320 // If can't find protocol GUID declaration in every package
1321 //
1322 throw new BuildException("Can not find protocol Guid ["
1323 + protocolKeyWord + "] declaration in every packages. ");
1324 }
1325 }
1326 }
1327
1328 /**
1329 * GuidGuidToAutogenc
1330 *
1331 * This function gets GUIDs from SPD file accrodeing to <Guids> information
1332 * and write those GUIDs to AutoGen.c.
1333 *
1334 * @param fileBuffer
1335 * String Buffer for Autogen.c file.
1336 *
1337 */
1338 void GuidGuidToAutogenC(StringBuffer fileBuffer) throws AutoGenException {
1339 String[] cNameGuid = null;
1340 String guidKeyWord = null;
1341
1342 String[] guidList = SurfaceAreaQuery.getGuidEntryArray(this.arch);
1343
1344 for (int i = 0; i < guidList.length; i++) {
1345 this.mGuidList.add(guidList[i]);
1346 }
1347
1348
1349 Iterator guidIterator = this.mGuidList.iterator();
1350 while (guidIterator.hasNext()) {
1351 guidKeyWord = guidIterator.next().toString();
1352 cNameGuid = GlobalData.getGuid(this.mDepPkgList, guidKeyWord);
1353
1354 if (cNameGuid != null) {
1355 fileBuffer
1356 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");
1357 fileBuffer.append(cNameGuid[0]);
1358 fileBuffer.append(" = { ");
1359 fileBuffer.append(CommonDefinition.formatGuidName(cNameGuid[1]));
1360 fileBuffer.append("} ;");
1361 } else {
1362 //
1363 // If can't find GUID declaration in every package
1364 //
1365 throw new AutoGenException("Can not find Guid [" + guidKeyWord
1366 + "] declaration in every packages. ");
1367 }
1368
1369 }
1370 }
1371
1372 /**
1373 * LibInstanceToAutogenC
1374 *
1375 * This function adds dependent library instance to autogen.c,which
1376 * includeing library's constructor, destructor, and library dependent ppi,
1377 * protocol, guid, pcd information.
1378 *
1379 * @param fileBuffer
1380 * String buffer for AutoGen.c
1381 * @throws BuildException
1382 */
1383 void LibInstanceToAutogenC(StringBuffer fileBuffer) throws BuildException {
1384 int index;
1385
1386 String moduleType = SurfaceAreaQuery.getModuleType();
1387 List<String> libConstructList = new ArrayList<String>();
1388 List<String> libDestructList = new ArrayList<String>();
1389
1390 String libConstructName = null;
1391 String libDestructName = null;
1392 ModuleIdentification[] libraryIdList = SurfaceAreaQuery
1393 .getLibraryInstance(this.arch);
1394
1395 try {
1396 if (libraryIdList != null) {
1397 //
1398 // Reorder library instance sequence.
1399 //
1400 AutogenLibOrder libOrder = new AutogenLibOrder(libraryIdList,
1401 this.arch);
1402 List<ModuleIdentification> orderList = libOrder
1403 .orderLibInstance();
1404
1405 if (orderList != null) {
1406 //
1407 // Process library instance one by one.
1408 //
1409 for (int i = 0; i < orderList.size(); i++) {
1410
1411 //
1412 // Get library instance basename.
1413 //
1414 ModuleIdentification libInstanceId = orderList.get(i);
1415
1416 //
1417 // Get override map
1418 //
1419
1420 Map<String, XmlObject> libDoc = GlobalData.getDoc(
1421 libInstanceId, this.arch);
1422 SurfaceAreaQuery.push(libDoc);
1423
1424 //
1425 // Get <PPis>, <Protocols>, <Guids> list of this library
1426 // instance.
1427 //
1428 String[] ppiList = SurfaceAreaQuery.getPpiArray(this.arch);
1429 String[] ppiNotifyList = SurfaceAreaQuery
1430 .getPpiNotifyArray(this.arch);
1431 String[] protocolList = SurfaceAreaQuery
1432 .getProtocolArray(this.arch);
1433 String[] protocolNotifyList = SurfaceAreaQuery
1434 .getProtocolNotifyArray(this.arch);
1435 String[] guidList = SurfaceAreaQuery
1436 .getGuidEntryArray(this.arch);
1437 PackageIdentification[] pkgList = SurfaceAreaQuery.getDependencePkg(this.arch);
1438
1439 //
1440 // Add those ppi, protocol, guid in global ppi,
1441 // protocol, guid
1442 // list.
1443 //
1444 for (index = 0; index < ppiList.length; index++) {
1445 this.mPpiList.add(ppiList[index]);
1446 }
1447
1448 for (index = 0; index < ppiNotifyList.length; index++) {
1449 this.mPpiList.add(ppiNotifyList[index]);
1450 }
1451
1452 for (index = 0; index < protocolList.length; index++) {
1453 this.mProtocolList.add(protocolList[index]);
1454 }
1455
1456 for (index = 0; index < protocolNotifyList.length; index++) {
1457 this.mProtocolList.add(protocolNotifyList[index]);
1458 }
1459
1460 for (index = 0; index < guidList.length; index++) {
1461 this.mGuidList.add(guidList[index]);
1462 }
1463 for (index = 0; index < pkgList.length; index++){
1464 if (!this.mDepPkgList.contains(pkgList[index])){
1465 this.mDepPkgList.add(pkgList[index]);
1466 }
1467 }
1468
1469 //
1470 // If not yet parse this library instance's constructor
1471 // element,parse it.
1472 //
1473 libConstructName = SurfaceAreaQuery
1474 .getLibConstructorName();
1475 libDestructName = SurfaceAreaQuery
1476 .getLibDestructorName();
1477
1478 SurfaceAreaQuery.pop();
1479 //
1480 // Add dependent library instance constructor function.
1481 //
1482 if (libConstructName != null) {
1483 libConstructList.add(libConstructName);
1484 }
1485 //
1486 // Add dependent library instance destructor fuction.
1487 //
1488 if (libDestructName != null) {
1489 libDestructList.add(libDestructName);
1490 }
1491 }
1492
1493 }
1494
1495 //
1496 // Add library constructor to AutoGen.c
1497 //
1498 LibConstructorToAutogenC(libConstructList, moduleType,
1499 fileBuffer/* autogenC */);
1500 //
1501 // Add library destructor to AutoGen.c
1502 //
1503 LibDestructorToAutogenC(libDestructList, moduleType, fileBuffer/* autogenC */);
1504 }
1505
1506 } catch (Exception e) {
1507 throw new BuildException(e.getMessage());
1508 }
1509 }
1510
1511 /**
1512 * LibConstructorToAutogenc
1513 *
1514 * This function writes library constructor list to AutoGen.c. The library
1515 * constructor's parameter and return value depend on module type.
1516 *
1517 * @param libInstanceList
1518 * List of library construct name.
1519 * @param moduleType
1520 * Module type.
1521 * @param fileBuffer
1522 * String buffer for AutoGen.c
1523 * @throws Exception
1524 */
1525 void LibConstructorToAutogenC(List<String> libInstanceList,
1526 String moduleType, StringBuffer fileBuffer) throws Exception {
1527 boolean isFirst = true;
1528
1529 //
1530 // The library constructor's parameter and return value depend on
1531 // module type.
1532 //
1533 for (int i = 0; i < libInstanceList.size(); i++) {
1534 switch (CommonDefinition.getModuleType(moduleType)) {
1535 case CommonDefinition.ModuleTypeBase:
1536 fileBuffer.append("RETURN_STATUS\r\n");
1537 fileBuffer.append(libInstanceList.get(i));
1538 fileBuffer.append(" (\r\n");
1539 fileBuffer.append(" VOID\r\n");
1540 fileBuffer.append(" );\r\n");
1541 break;
1542
1543 case CommonDefinition.ModuleTypePeiCore:
1544 case CommonDefinition.ModuleTypePeim:
1545 fileBuffer.append("EFI_STATUS\r\n");
1546 fileBuffer.append(libInstanceList.get(i));
1547 fileBuffer.append(" (\r\n");
1548 fileBuffer
1549 .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1550 fileBuffer
1551 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1552 fileBuffer.append(" );\r\n");
1553 break;
1554
1555 case CommonDefinition.ModuleTypeDxeCore:
1556 case CommonDefinition.ModuleTypeDxeDriver:
1557 case CommonDefinition.ModuleTypeDxeRuntimeDriver:
1558 case CommonDefinition.ModuleTypeDxeSmmDriver:
1559 case CommonDefinition.ModuleTypeDxeSalDriver:
1560 case CommonDefinition.ModuleTypeUefiDriver:
1561 case CommonDefinition.ModuleTypeUefiApplication:
1562 fileBuffer.append("EFI_STATUS\r\n");
1563 fileBuffer.append(libInstanceList.get(i));
1564 fileBuffer.append(" (\r\n");
1565 fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");
1566 fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1567 fileBuffer.append(" );\r\n");
1568 break;
1569 }
1570 }
1571
1572 //
1573 // Add ProcessLibraryConstructorList in AutoGen.c
1574 //
1575 fileBuffer.append("VOID\r\n");
1576 fileBuffer.append("ProcessLibraryConstructorList (\r\n");
1577 switch (CommonDefinition.getModuleType(moduleType)) {
1578 case CommonDefinition.ModuleTypeBase:
1579 fileBuffer.append(" VOID\r\n");
1580 break;
1581
1582 case CommonDefinition.ModuleTypePeiCore:
1583 case CommonDefinition.ModuleTypePeim:
1584 fileBuffer.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1585 fileBuffer
1586 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1587 break;
1588
1589 case CommonDefinition.ModuleTypeDxeCore:
1590 case CommonDefinition.ModuleTypeDxeDriver:
1591 case CommonDefinition.ModuleTypeDxeRuntimeDriver:
1592 case CommonDefinition.ModuleTypeDxeSmmDriver:
1593 case CommonDefinition.ModuleTypeDxeSalDriver:
1594 case CommonDefinition.ModuleTypeUefiDriver:
1595 case CommonDefinition.ModuleTypeUefiApplication:
1596 fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");
1597 fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1598 break;
1599 }
1600
1601 fileBuffer.append(" )\r\n");
1602 fileBuffer.append("{\r\n");
1603 //
1604 // If no constructor function, return EFI_SUCCESS.
1605 //
1606 //if (libInstanceList.size() == 0){
1607 // fileBuffer.append(" return EFI_SUCCESS;\r\n");
1608 //}
1609 for (int i = 0; i < libInstanceList.size(); i++) {
1610 if (isFirst) {
1611 fileBuffer.append(" EFI_STATUS Status;\r\n");
1612 fileBuffer.append(" Status = EFI_SUCCESS;\r\n");
1613 fileBuffer.append("\r\n");
1614 isFirst = false;
1615 }
1616 switch (CommonDefinition.getModuleType(moduleType)) {
1617 case CommonDefinition.ModuleTypeBase:
1618 fileBuffer.append(" Status = ");
1619 fileBuffer.append(libInstanceList.get(i));
1620 fileBuffer.append("();\r\n");
1621 fileBuffer.append(" VOID\r\n");
1622 break;
1623 case CommonDefinition.ModuleTypePeiCore:
1624 case CommonDefinition.ModuleTypePeim:
1625 fileBuffer.append(" Status = ");
1626 fileBuffer.append(libInstanceList.get(i));
1627 fileBuffer.append(" (FfsHeader, PeiServices);\r\n");
1628 break;
1629 case CommonDefinition.ModuleTypeDxeCore:
1630 case CommonDefinition.ModuleTypeDxeDriver:
1631 case CommonDefinition.ModuleTypeDxeRuntimeDriver:
1632 case CommonDefinition.ModuleTypeDxeSmmDriver:
1633 case CommonDefinition.ModuleTypeDxeSalDriver:
1634 case CommonDefinition.ModuleTypeUefiDriver:
1635 case CommonDefinition.ModuleTypeUefiApplication:
1636 fileBuffer.append(" Status = ");
1637 fileBuffer.append(libInstanceList.get(i));
1638 fileBuffer.append(" (ImageHandle, SystemTable);\r\n");
1639 break;
1640 default:
1641 EdkLog.log(EdkLog.EDK_INFO,"Autogen don't know how to deal with module type -"+ moduleType + " !");
1642 }
1643 fileBuffer.append(" ASSERT_EFI_ERROR (Status);\r\n");
1644 }
1645 fileBuffer.append("}\r\n");
1646 }
1647
1648 /**
1649 * LibDestructorToAutogenc
1650 *
1651 * This function writes library destructor list to AutoGen.c. The library
1652 * destructor's parameter and return value depend on module type.
1653 *
1654 * @param libInstanceList
1655 * List of library destructor name.
1656 * @param moduleType
1657 * Module type.
1658 * @param fileBuffer
1659 * String buffer for AutoGen.c
1660 * @throws Exception
1661 */
1662 void LibDestructorToAutogenC(List<String> libInstanceList,
1663 String moduleType, StringBuffer fileBuffer) throws Exception {
1664 boolean isFirst = true;
1665 for (int i = 0; i < libInstanceList.size(); i++) {
1666 switch (CommonDefinition.getModuleType(moduleType)) {
1667 case CommonDefinition.ModuleTypeBase:
1668 fileBuffer.append("RETURN_STATUS\n");
1669 fileBuffer.append(libInstanceList.get(i));
1670 fileBuffer.append(" (\r\n");
1671 fileBuffer.append(" VOID\r\n");
1672 fileBuffer.append(" );\r\n");
1673 break;
1674 case CommonDefinition.ModuleTypePeiCore:
1675 case CommonDefinition.ModuleTypePeim:
1676 fileBuffer.append("EFI_STATUS\r\n");
1677 fileBuffer.append(libInstanceList.get(i));
1678 fileBuffer.append(" (\r\n");
1679 fileBuffer
1680 .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");
1681 fileBuffer
1682 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");
1683 fileBuffer.append(" );\r\n");
1684 break;
1685 case CommonDefinition.ModuleTypeDxeCore:
1686 case CommonDefinition.ModuleTypeDxeDriver:
1687 case CommonDefinition.ModuleTypeDxeRuntimeDriver:
1688 case CommonDefinition.ModuleTypeDxeSmmDriver:
1689 case CommonDefinition.ModuleTypeDxeSalDriver:
1690 case CommonDefinition.ModuleTypeUefiDriver:
1691 case CommonDefinition.ModuleTypeUefiApplication:
1692 fileBuffer.append("EFI_STATUS\r\n");
1693 fileBuffer.append(libInstanceList.get(i));
1694 fileBuffer.append(" (\r\n");
1695 fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");
1696 fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1697 fileBuffer.append(" );\r\n");
1698 break;
1699 }
1700 }
1701
1702 //
1703 // Write ProcessLibraryDestructor list to autogen.c
1704 //
1705 switch (CommonDefinition.getModuleType(moduleType)) {
1706 case CommonDefinition.ModuleTypeBase:
1707 case CommonDefinition.ModuleTypePeiCore:
1708 case CommonDefinition.ModuleTypePeim:
1709 break;
1710 case CommonDefinition.ModuleTypeDxeCore:
1711 case CommonDefinition.ModuleTypeDxeDriver:
1712 case CommonDefinition.ModuleTypeDxeRuntimeDriver:
1713 case CommonDefinition.ModuleTypeDxeSmmDriver:
1714 case CommonDefinition.ModuleTypeDxeSalDriver:
1715 case CommonDefinition.ModuleTypeUefiDriver:
1716 case CommonDefinition.ModuleTypeUefiApplication:
1717 fileBuffer.append("VOID\r\n");
1718 fileBuffer.append("ProcessLibraryDestructorList (\r\n");
1719 fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");
1720 fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");
1721 fileBuffer.append(" )\r\n");
1722 fileBuffer.append("{\r\n");
1723 //
1724 // If no library destructor function, return EFI_SUCCESS.
1725 //
1726
1727 for (int i = 0; i < libInstanceList.size(); i++) {
1728 if (isFirst) {
1729 fileBuffer.append(" EFI_STATUS Status;\r\n");
1730 fileBuffer.append(" Status = EFI_SUCCESS;\r\n");
1731 fileBuffer.append("\r\n");
1732 isFirst = false;
1733 }
1734 fileBuffer.append(" Status = ");
1735 fileBuffer.append(libInstanceList.get(i));
1736 fileBuffer.append("(ImageHandle, SystemTable);\r\n");
1737 fileBuffer.append(" ASSERT_EFI_ERROR (Status);\r\n");
1738 }
1739 fileBuffer.append("}\r\n");
1740 break;
1741 }
1742 }
1743
1744 /**
1745 * ExternsDriverBindingToAutoGenC
1746 *
1747 * This function is to write DRIVER_BINDING, COMPONENT_NAME,
1748 * DRIVER_CONFIGURATION, DRIVER_DIAGNOSTIC in AutoGen.c.
1749 *
1750 * @param fileBuffer
1751 * String buffer for AutoGen.c
1752 */
1753 void ExternsDriverBindingToAutoGenC(StringBuffer fileBuffer)
1754 throws BuildException {
1755
1756 //
1757 // Check what <extern> contains. And the number of following elements
1758 // under <extern> should be same. 1. DRIVER_BINDING 2. COMPONENT_NAME
1759 // 3.DRIVER_CONFIGURATION 4. DRIVER_DIAGNOSTIC
1760 //
1761
1762 String[] drvBindList = SurfaceAreaQuery.getDriverBindingArray();
1763
1764 //
1765 // If component name protocol,component configuration protocol,
1766 // component diagnostic protocol is not null or empty, check
1767 // if every one have the same number of the driver binding protocol.
1768 //
1769 if (drvBindList == null || drvBindList.length == 0) {
1770 return;
1771 }
1772
1773 String[] compNamList = SurfaceAreaQuery.getComponentNameArray();
1774 String[] compConfList = SurfaceAreaQuery.getDriverConfigArray();
1775 String[] compDiagList = SurfaceAreaQuery.getDriverDiagArray();
1776
1777 int BitMask = 0;
1778
1779 //
1780 // Write driver binding protocol extern to autogen.c
1781 //
1782 for (int i = 0; i < drvBindList.length; i++) {
1783 fileBuffer.append("extern EFI_DRIVER_BINDING_PROTOCOL ");
1784 fileBuffer.append(drvBindList[i]);
1785 fileBuffer.append(";\r\n");
1786 }
1787
1788 //
1789 // Write component name protocol extern to autogen.c
1790 //
1791 if (compNamList != null && compNamList.length != 0) {
1792 if (drvBindList.length != compNamList.length) {
1793 throw new BuildException(
1794 "Different number of Driver Binding and Component Name protocols!");
1795 }
1796
1797 BitMask |= 0x01;
1798 for (int i = 0; i < compNamList.length; i++) {
1799 fileBuffer.append("extern EFI_COMPONENT_NAME_PROTOCOL ");
1800 fileBuffer.append(compNamList[i]);
1801 fileBuffer.append(";\r\n");
1802 }
1803 }
1804
1805 //
1806 // Write driver configration protocol extern to autogen.c
1807 //
1808 if (compConfList != null && compConfList.length != 0) {
1809 if (drvBindList.length != compConfList.length) {
1810 throw new BuildException(
1811 "Different number of Driver Binding and Driver Configuration protocols!");
1812 }
1813
1814 BitMask |= 0x02;
1815 for (int i = 0; i < compConfList.length; i++) {
1816 fileBuffer.append("extern EFI_DRIVER_CONFIGURATION_PROTOCOL ");
1817 fileBuffer.append(compConfList[i]);
1818 fileBuffer.append(";\r\n");
1819 }
1820 }
1821
1822 //
1823 // Write driver dignastic protocol extern to autogen.c
1824 //
1825 if (compDiagList != null && compDiagList.length != 0) {
1826 if (drvBindList.length != compDiagList.length) {
1827 throw new BuildException(
1828 "Different number of Driver Binding and Driver Configuration protocols!");
1829 }
1830
1831 BitMask |= 0x04;
1832 for (int i = 0; i < compDiagList.length; i++) {
1833 fileBuffer.append("extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL ");
1834 fileBuffer.append(compDiagList[i]);
1835 fileBuffer.append(";\r\n");
1836 }
1837 }
1838
1839 //
1840 // Write driver module protocol bitmask.
1841 //
1842 fileBuffer
1843 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverModelProtocolBitmask = ");
1844 fileBuffer.append(Integer.toString(BitMask));
1845 fileBuffer.append(";\r\n");
1846
1847 //
1848 // Write driver module protocol list entry
1849 //
1850 fileBuffer
1851 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverModelProtocolListEntries = ");
1852
1853 fileBuffer.append(Integer.toString(drvBindList.length));
1854 fileBuffer.append(";\r\n");
1855
1856 //
1857 // Write drive module protocol list to autogen.c
1858 //
1859 fileBuffer
1860 .append("GLOBAL_REMOVE_IF_UNREFERENCED const EFI_DRIVER_MODEL_PROTOCOL_LIST _gDriverModelProtocolList[] = {");
1861 for (int i = 0; i < drvBindList.length; i++) {
1862 if (i != 0) {
1863 fileBuffer.append(",");
1864 }
1865 fileBuffer.append("\r\n {\r\n");
1866 fileBuffer.append(" &");
1867 fileBuffer.append(drvBindList[i]);
1868 fileBuffer.append(", \r\n");
1869
1870 if (compNamList != null) {
1871 fileBuffer.append(" &");
1872 fileBuffer.append(compNamList[i]);
1873 fileBuffer.append(", \r\n");
1874 } else {
1875 fileBuffer.append(" NULL, \r\n");
1876 }
1877
1878 if (compConfList != null) {
1879 fileBuffer.append(" &");
1880 fileBuffer.append(compConfList[i]);
1881 fileBuffer.append(", \r\n");
1882 } else {
1883 fileBuffer.append(" NULL, \r\n");
1884 }
1885
1886 if (compDiagList != null) {
1887 fileBuffer.append(" &");
1888 fileBuffer.append(compDiagList[i]);
1889 fileBuffer.append(", \r\n");
1890 } else {
1891 fileBuffer.append(" NULL, \r\n");
1892 }
1893 fileBuffer.append(" }");
1894 }
1895 fileBuffer.append("\r\n};\r\n");
1896 }
1897
1898 /**
1899 * ExternCallBackToAutoGenC
1900 *
1901 * This function adds <SetVirtualAddressMapCallBack> and
1902 * <ExitBootServicesCallBack> infomation to AutoGen.c
1903 *
1904 * @param fileBuffer
1905 * String buffer for AutoGen.c
1906 * @throws BuildException
1907 */
1908 void ExternCallBackToAutoGenC(StringBuffer fileBuffer)
1909 throws BuildException {
1910 String[] setVirtualList = SurfaceAreaQuery
1911 .getSetVirtualAddressMapCallBackArray();
1912 String[] exitBootList = SurfaceAreaQuery
1913 .getExitBootServicesCallBackArray();
1914 String moduleType = SurfaceAreaQuery.getModuleType();
1915 boolean UefiOrDxeModule = false;
1916 int Count = 0;
1917 int i;
1918
1919 switch (CommonDefinition.getModuleType(moduleType)) {
1920 case CommonDefinition.ModuleTypeDxeDriver:
1921 case CommonDefinition.ModuleTypeDxeRuntimeDriver:
1922 case CommonDefinition.ModuleTypeDxeSalDriver:
1923 case CommonDefinition.ModuleTypeUefiDriver:
1924 case CommonDefinition.ModuleTypeUefiApplication:
1925 //
1926 // Entry point lib for these module types needs to know the count
1927 // of entryPoint.
1928 //
1929 UefiOrDxeModule = true;
1930 fileBuffer
1931 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverSetVirtualAddressMapEventCount = ");
1932
1933 //
1934 // If the list is not valid or has no entries set count to zero else
1935 // set count to the number of valid entries
1936 //
1937 Count = 0;
1938 if (setVirtualList != null) {
1939 for (i = 0; i < setVirtualList.length; i++) {
1940 if (setVirtualList[i].equalsIgnoreCase("")) {
1941 break;
1942 }
1943 }
1944 Count = i;
1945 }
1946
1947 fileBuffer.append(Integer.toString(Count));
1948 fileBuffer.append(";\r\n\r\n");
1949 break;
1950 default:
1951 break;
1952 }
1953
1954 if (setVirtualList == null) {
1955 if (UefiOrDxeModule) {
1956 //
1957 // No data so make a NULL list
1958 //
1959 fileBuffer
1960 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {\r\n");
1961 fileBuffer.append(" NULL\r\n");
1962 fileBuffer.append("};\r\n\r\n");
1963 }
1964 } else {
1965 //
1966 // Write SetVirtualAddressMap function definition.
1967 //
1968 for (i = 0; i < setVirtualList.length; i++) {
1969 if (setVirtualList[i].equalsIgnoreCase("")) {
1970 break;
1971 }
1972 fileBuffer.append("VOID\r\n");
1973 fileBuffer.append("EFIAPI\r\n");
1974 fileBuffer.append(setVirtualList[i]);
1975 fileBuffer.append(" (\r\n");
1976 fileBuffer.append(" IN EFI_EVENT Event,\r\n");
1977 fileBuffer.append(" IN VOID *Context\r\n");
1978 fileBuffer.append(" );\r\n\r\n");
1979 }
1980
1981 //
1982 // Write SetVirtualAddressMap entry point array.
1983 //
1984 fileBuffer
1985 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {");
1986 for (i = 0; i < setVirtualList.length; i++) {
1987 if (setVirtualList[i].equalsIgnoreCase("")) {
1988 break;
1989 }
1990
1991 if (i == 0) {
1992 fileBuffer.append("\r\n ");
1993 } else {
1994 fileBuffer.append(",\r\n ");
1995 }
1996
1997 fileBuffer.append(setVirtualList[i]);
1998 }
1999 //
2000 // If module is not DXE_DRIVER, DXE_RUNTIME_DIRVER, UEFI_DRIVER
2001 // UEFI_APPLICATION and DXE_SAL_DRIVER add the NULL at the end of
2002 // _gDriverSetVirtualAddressMapEvent list.
2003 //
2004 if (!UefiOrDxeModule) {
2005 fileBuffer.append(",\r\n NULL");
2006 }
2007 fileBuffer.append("\r\n};\r\n\r\n");
2008 }
2009
2010 if (UefiOrDxeModule) {
2011 //
2012 // Entry point lib for these module types needs to know the count.
2013 //
2014 fileBuffer
2015 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverExitBootServicesEventCount = ");
2016
2017 //
2018 // If the list is not valid or has no entries set count to zero else
2019 // set count to the number of valid entries.
2020 //
2021 Count = 0;
2022 if (exitBootList != null) {
2023 if (setVirtualList != null) {
2024 for (i = 0; i < exitBootList.length; i++) {
2025 if (exitBootList[i].equalsIgnoreCase("")) {
2026 break;
2027 }
2028 }
2029 Count = i;
2030 }
2031 }
2032 fileBuffer.append(Integer.toString(Count));
2033 fileBuffer.append(";\r\n\r\n");
2034 }
2035
2036 if (exitBootList == null) {
2037 if (UefiOrDxeModule) {
2038 //
2039 // No data so make a NULL list.
2040 //
2041 fileBuffer
2042 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {\r\n");
2043 fileBuffer.append(" NULL\r\n");
2044 fileBuffer.append("};\r\n\r\n");
2045 }
2046 } else {
2047 //
2048 // Write DriverExitBootServices function definition.
2049 //
2050 for (i = 0; i < exitBootList.length; i++) {
2051 if (exitBootList[i].equalsIgnoreCase("")) {
2052 break;
2053 }
2054
2055 fileBuffer.append("VOID\r\n");
2056 fileBuffer.append("EFIAPI\r\n");
2057 fileBuffer.append(exitBootList[i]);
2058 fileBuffer.append(" (\r\n");
2059 fileBuffer.append(" IN EFI_EVENT Event,\r\n");
2060 fileBuffer.append(" IN VOID *Context\r\n");
2061 fileBuffer.append(" );\r\n\r\n");
2062 }
2063
2064 //
2065 // Write DriverExitBootServices entry point array.
2066 //
2067 fileBuffer
2068 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {");
2069 for (i = 0; i < exitBootList.length; i++) {
2070 if (exitBootList[i].equalsIgnoreCase("")) {
2071 break;
2072 }
2073
2074 if (i == 0) {
2075 fileBuffer.append("\r\n ");
2076 } else {
2077 fileBuffer.append(",\r\n ");
2078 }
2079 fileBuffer.append(exitBootList[i]);
2080 }
2081 if (!UefiOrDxeModule) {
2082 fileBuffer.append(",\r\n NULL");
2083 }
2084 fileBuffer.append("\r\n};\r\n\r\n");
2085 }
2086
2087 }
2088
2089 }