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