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