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