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