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