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