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