]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Java/Source/GenBuild/org/tianocore/build/autogen/AutoGen.java
Disp dependencies in error in case of circular dependency
[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
127 \r
128 //\r
129 // Instance of SurfaceAreaQuery\r
130 //\r
83fba802 131 private SurfaceAreaQuery saq = null;\r
2eb7d78d 132 \r
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
cb4d97bd 172 \r
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
186 + "'s " \r
187 + fileName \r
188 + " is exist, but can't be open!!");\r
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
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
208 + "'s " \r
209 + fileName \r
210 + " can't be create!!");\r
211 return false;\r
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
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
e425f073 252 setPcdComponentName();\r
253 setPcdDriverDiagnostic();\r
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
e425f073 299 + CommonDefinition.AUTOGENH\r
300 + this.moduleId.getGuid().replaceAll("-", "_") \r
301 + ToolDefinitions.LINE_SEPARATOR);\r
cb4d97bd 302 fileBuffer.append(CommonDefinition.DEFINE \r
e425f073 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
e425f073 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
e425f073 461 fileBuffer\r
2f403520 462 .append("GLOBAL_REMOVE_IF_UNREFERENCED GUID gEfiCallerIdGuid = {");\r
e425f073 463 } else {\r
464 fileBuffer\r
2f403520 465 .append("GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiCallerIdGuid = {");\r
e425f073 466 }\r
2f403520 467 \r
5f907e4a 468 if (guid == null) {\r
469 throw new AutoGenException("Guid value must set!\n");\r
470 }\r
471\r
472 //\r
473 // Formate Guid as ANSI c form.Example:\r
474 // {0xd2b2b828, 0x826, 0x48a7,{0xb3, 0xdf, 0x98, 0x3c, 0x0, 0x60, 0x24,\r
475 // 0xf0}}\r
476 //\r
477\r
478 fileBuffer.append(guid);\r
479 fileBuffer.append("};\r\n");\r
480\r
481 //\r
482 // Generate library instance consumed protocol, guid, ppi, pcd list.\r
483 // Save those to this.protocolList, this.ppiList, this.pcdList,\r
484 // this.guidList. Write Consumed library constructor and desconstuct to\r
485 // autogen.c\r
486 //\r
136adffc 487 LibInstanceToAutogenC(fileBuffer);\r
ff225cbb 488\r
878ddf1f 489 //\r
136adffc 490 // Get module dependent Package identification.\r
878ddf1f 491 //\r
83fba802 492 PackageIdentification[] packages = saq.getDependencePkg(this.arch);\r
5f907e4a 493 for (int i = 0; i < packages.length; i++) {\r
494 if (!this.mDepPkgList.contains(packages[i])) {\r
136adffc 495 this.mDepPkgList.add(packages[i]);\r
878ddf1f 496 }\r
ff225cbb 497\r
136adffc 498 }\r
ff225cbb 499\r
5f907e4a 500 //\r
501 // Write consumed ppi, guid, protocol to autogen.c\r
502 //\r
503 ProtocolGuidToAutogenC(fileBuffer);\r
504 PpiGuidToAutogenC(fileBuffer);\r
505 GuidGuidToAutogenC(fileBuffer);\r
ff225cbb 506\r
5f907e4a 507 //\r
508 // Call pcd autogen.\r
509 //\r
510 this.myPcdAutogen = new PCDAutoGenAction(moduleId, \r
511 arch, \r
512 false, \r
513 null,\r
2eb7d78d 514 pcdDriverType, \r
515 parentId);\r
61528a1b 516 \r
517 this.myPcdAutogen.execute();\r
5f907e4a 518 if (this.myPcdAutogen != null) {\r
519 fileBuffer.append("\r\n");\r
11eb278a 520 fileBuffer.append(this.myPcdAutogen.getCAutoGenString());\r
5f907e4a 521 }\r
522\r
523 if (!saveFile(outputPath + File.separatorChar + "AutoGen.c", fileBuffer)) {\r
61528a1b 524 throw new AutoGenException("Failed to generate AutoGen.c !!!");\r
5f907e4a 525 }\r
526\r
527 }\r
528\r
529 /**\r
cb4d97bd 530 libGenAutogenH\r
531 \r
532 This function generates AutoGen.h for library.\r
533 \r
534 @throws BuildException\r
535 Failed to generate AutoGen.c.\r
536 **/\r
61528a1b 537 void libGenAutogenH() throws EdkException {\r
5f907e4a 538\r
539 Set<String> libClassIncludeH;\r
540 String moduleType;\r
541 List<String> headerFileList;\r
542 Iterator item;\r
543 StringBuffer fileBuffer = new StringBuffer(10240);\r
544\r
545 //\r
546 // Write Autogen.h header notation\r
547 //\r
cb4d97bd 548 fileBuffer.append(CommonDefinition.AUTOGENHNOTATION);\r
5f907e4a 549\r
550 //\r
551 // Add #ifndef ${BaseName}_AUTOGENH\r
552 // #def ${BseeName}_AUTOGENH\r
553 //\r
cb4d97bd 554 fileBuffer.append(CommonDefinition.IFNDEF \r
e425f073 555 + CommonDefinition.AUTOGENH\r
556 + this.moduleId.getGuid().replaceAll("-", "_") \r
557 + ToolDefinitions.LINE_SEPARATOR);\r
cb4d97bd 558 fileBuffer.append(CommonDefinition.DEFINE \r
e425f073 559 + CommonDefinition.AUTOGENH\r
560 + this.moduleId.getGuid().replaceAll("-", "_") \r
561 + ToolDefinitions.LINE_SEPARATOR \r
562 + ToolDefinitions.LINE_SEPARATOR);\r
5f907e4a 563\r
564 //\r
565 // Write EFI_SPECIFICATION_VERSION and EDK_RELEASE_VERSION\r
566 // to autogen.h file.\r
567 // Note: the specification version and release version should\r
568 // be get from module surface area instead of hard code.\r
569 //\r
cb4d97bd 570 fileBuffer.append(CommonDefinition.AUTOGENHBEGIN);\r
83fba802 571 String[] specList = saq.getExternSpecificaiton();\r
5f907e4a 572 for (int i = 0; i < specList.length; i++) {\r
cb4d97bd 573 fileBuffer.append(CommonDefinition.DEFINE + specList[i]\r
5f907e4a 574 + "\r\n");\r
575 }\r
576 // fileBuffer.append(CommonDefinition.autoGenHLine1);\r
577 // fileBuffer.append(CommonDefinition.autoGenHLine2);\r
578\r
579 //\r
580 // Write consumed package's mdouleInfo related *.h file to autogen.h.\r
581 //\r
83fba802 582 moduleType = saq.getModuleType();\r
583 PackageIdentification[] cosumedPkglist = saq\r
5f907e4a 584 .getDependencePkg(this.arch);\r
585 headerFileList = depPkgToAutogenH(cosumedPkglist, moduleType);\r
586 item = headerFileList.iterator();\r
587 while (item.hasNext()) {\r
588 fileBuffer.append(item.next().toString());\r
589 }\r
590 //\r
591 // Write library class's related *.h file to autogen.h\r
592 //\r
83fba802 593 String[] libClassList = saq\r
cb4d97bd 594 .getLibraryClasses(CommonDefinition.ALWAYSCONSUMED, this.arch);\r
5f907e4a 595 if (libClassList != null) {\r
596 libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
597 item = libClassIncludeH.iterator();\r
598 while (item.hasNext()) {\r
599 fileBuffer.append(item.next().toString());\r
600 }\r
601 }\r
602\r
83fba802 603 libClassList = saq\r
cb4d97bd 604 .getLibraryClasses(CommonDefinition.ALWAYSPRODUCED, this.arch);\r
5f907e4a 605 if (libClassList != null) {\r
606 libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
607 item = libClassIncludeH.iterator();\r
608 while (item.hasNext()) {\r
609 fileBuffer.append(item.next().toString());\r
610 }\r
611 }\r
cb4d97bd 612 fileBuffer.append(ToolDefinitions.LINE_SEPARATOR);\r
136adffc 613\r
73b4e31a 614 //\r
ff225cbb 615 // If is TianoR8FlashMap, copy {Fv_DIR}/FlashMap.h to\r
73b4e31a 616 // {DEST_DIR_DRBUG}/FlashMap.h\r
ff225cbb 617 //\r
83fba802 618 if (saq.isHaveTianoR8FlashMap()) {\r
cb4d97bd 619 fileBuffer.append(CommonDefinition.INCLUDE);\r
73b4e31a 620 fileBuffer.append(" <");\r
cb4d97bd 621 fileBuffer.append(CommonDefinition.TIANOR8PLASHMAPH + ">\r\n");\r
73b4e31a 622 copyFlashMapHToDebugDir();\r
623 }\r
624\r
5f907e4a 625 //\r
626 // Write PCD information to library AutoGen.h.\r
627 //\r
628 if (this.myPcdAutogen != null) {\r
136adffc 629 fileBuffer.append("\r\n");\r
11eb278a 630 fileBuffer.append(this.myPcdAutogen.getHAutoGenString());\r
5f907e4a 631 }\r
632\r
633 //\r
634 // Append the #endif at AutoGen.h\r
635 //\r
636 fileBuffer.append("#endif\r\n");\r
637\r
638 //\r
639 // Save content of string buffer to AutoGen.h file.\r
640 //\r
641 if (!saveFile(outputPath + File.separatorChar + "AutoGen.h", fileBuffer)) {\r
61528a1b 642 throw new AutoGenException("Failed to generate AutoGen.h !!!");\r
5f907e4a 643 }\r
644 }\r
645\r
646 /**\r
cb4d97bd 647 libGenAutogenC\r
648 \r
649 This function generates AutoGen.h for library.\r
650 \r
651 @throws BuildException\r
652 Failed to generate AutoGen.c.\r
653 **/\r
61528a1b 654 void libGenAutogenC() throws EdkException {\r
5f907e4a 655 StringBuffer fileBuffer = new StringBuffer(10240);\r
656\r
657 //\r
658 // Write Autogen.c header notation\r
659 //\r
cb4d97bd 660 fileBuffer.append(CommonDefinition.AUTOGENCNOTATION);\r
5f907e4a 661\r
cb4d97bd 662 fileBuffer.append(ToolDefinitions.LINE_SEPARATOR);\r
663 fileBuffer.append(ToolDefinitions.LINE_SEPARATOR);\r
5f907e4a 664\r
665 //\r
666 // Call pcd autogen.\r
667 //\r
668 this.myPcdAutogen = new PCDAutoGenAction(moduleId,\r
669 arch,\r
670 true,\r
7432a214 671 saq.getModulePcdEntryNameArray(this.arch),\r
2eb7d78d 672 pcdDriverType, \r
673 parentId);\r
61528a1b 674 this.myPcdAutogen.execute();\r
5f907e4a 675 if (this.myPcdAutogen != null) {\r
cb4d97bd 676 fileBuffer.append(ToolDefinitions.LINE_SEPARATOR);\r
11eb278a 677 fileBuffer.append(this.myPcdAutogen.getCAutoGenString());\r
5f907e4a 678 }\r
679\r
680 if (!saveFile(outputPath + File.separatorChar + "AutoGen.c", fileBuffer)) {\r
61528a1b 681 throw new AutoGenException("Failed to generate AutoGen.c !!!");\r
5f907e4a 682 }\r
683 }\r
684\r
685 /**\r
cb4d97bd 686 LibraryClassToAutogenH\r
687 \r
688 This function returns *.h files declared by library classes which are\r
689 consumed or produced by current build module or library.\r
690 \r
691 @param libClassList\r
692 List of library class which consumed or produce by current\r
693 build module or library.\r
694 @return includeStrList List of *.h file.\r
695 **/\r
5f907e4a 696 Set<String> LibraryClassToAutogenH(String[] libClassList)\r
61528a1b 697 throws EdkException {\r
cb4d97bd 698 Set<String> includeStrList = new LinkedHashSet<String>();\r
699 String includeName[];\r
5f907e4a 700 String str = "";\r
701\r
702 //\r
703 // Get include file from GlobalData's SPDTable according to\r
704 // library class name.\r
705 //\r
5f907e4a 706 for (int i = 0; i < libClassList.length; i++) {\r
cb4d97bd 707 includeName = GlobalData.getLibraryClassHeaderFiles(\r
e425f073 708 saq.getDependencePkg(this.arch),\r
5f907e4a 709 libClassList[i]);\r
e425f073 710 if (includeName == null) {\r
711 throw new AutoGenException("Can not find library class ["\r
5f907e4a 712 + libClassList[i] + "] declaration in any SPD package. ");\r
713 }\r
cb4d97bd 714 for (int j = 0; j < includeName.length; j++) {\r
715 String includeNameStr = includeName[j];\r
5f907e4a 716 if (includeNameStr != null) {\r
cb4d97bd 717 str = CommonDefinition.INCLUDE + " " + "<";\r
5f907e4a 718 str = str + includeNameStr + ">\r\n";\r
cb4d97bd 719 includeStrList.add(str);\r
5f907e4a 720 includeNameStr = null;\r
878ddf1f 721 }\r
5f907e4a 722 }\r
723 }\r
cb4d97bd 724 return includeStrList;\r
5f907e4a 725 }\r
726\r
727 /**\r
cb4d97bd 728 IncludesToAutogenH\r
729 \r
730 This function add include file in AutoGen.h file.\r
731 \r
732 @param packageNameList\r
733 List of module depended package.\r
734 @param moduleType\r
735 Module type.\r
736 @return\r
737 **/\r
5f907e4a 738 List<String> depPkgToAutogenH(PackageIdentification[] packageNameList,\r
739 String moduleType) throws AutoGenException {\r
740\r
741 List<String> includeStrList = new LinkedList<String>();\r
742 String pkgHeader;\r
743 String includeStr = "";\r
744\r
745 //\r
746 // Get include file from moduleInfo file\r
747 //\r
748 for (int i = 0; i < packageNameList.length; i++) {\r
749 pkgHeader = GlobalData.getPackageHeaderFiles(packageNameList[i],\r
750 moduleType);\r
751 if (pkgHeader == null) {\r
752 throw new AutoGenException("Can not find package ["\r
753 + packageNameList[i]\r
754 + "] declaration in any SPD package. ");\r
755 } else if (!pkgHeader.equalsIgnoreCase("")) {\r
cb4d97bd 756 includeStr = CommonDefinition.INCLUDE + " <" + pkgHeader\r
5f907e4a 757 + ">\r\n";\r
758 includeStrList.add(includeStr);\r
759 }\r
760 }\r
761\r
762 return includeStrList;\r
763 }\r
764\r
765 /**\r
cb4d97bd 766 EntryPointToAutoGen\r
767 \r
768 This function convert <ModuleEntryPoint> & <ModuleUnloadImage>\r
769 information in mas to AutoGen.c\r
770 \r
771 @param entryPointList\r
772 List of entry point.\r
773 @param fileBuffer\r
774 String buffer fo AutoGen.c.\r
775 @throws Exception\r
776 **/\r
777 void EntryPointToAutoGen(String[] entryPointList, String[] unloadImageList, StringBuffer fileBuffer)\r
61528a1b 778 throws EdkException {\r
5f907e4a 779\r
83fba802 780 String typeStr = saq.getModuleType();\r
e425f073 781 int unloadImageCount = 0;\r
cb4d97bd 782 int entryPointCount = 0;\r
5f907e4a 783\r
784 //\r
785 // The parameters and return value of entryPoint is difference\r
786 // for difference module type.\r
787 //\r
788 switch (CommonDefinition.getModuleType(typeStr)) {\r
789 \r
790 case CommonDefinition.ModuleTypePeiCore:\r
791 if (entryPointList == null ||entryPointList.length != 1 ) {\r
61528a1b 792 throw new AutoGenException(\r
5f907e4a 793 "Module type = 'PEI_CORE', can have only one module entry point!");\r
794 } else {\r
795 fileBuffer.append("EFI_STATUS\r\n");\r
5f907e4a 796 fileBuffer.append(entryPointList[0]);\r
797 fileBuffer.append(" (\r\n");\r
136adffc 798 fileBuffer\r
5f907e4a 799 .append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n");\r
136adffc 800 fileBuffer\r
5f907e4a 801 .append(" IN VOID *OldCoreData\r\n");\r
802 fileBuffer.append(" );\r\n\r\n");\r
136adffc 803\r
804 fileBuffer.append("EFI_STATUS\r\n");\r
805 fileBuffer.append("EFIAPI\r\n");\r
806 fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r
5f907e4a 807 fileBuffer\r
808 .append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n");\r
809 fileBuffer\r
810 .append(" IN VOID *OldCoreData\r\n");\r
136adffc 811 fileBuffer.append(" )\r\n\r\n");\r
812 fileBuffer.append("{\r\n");\r
5f907e4a 813 fileBuffer.append(" return ");\r
814 fileBuffer.append(entryPointList[0]);\r
815 fileBuffer.append(" (PeiStartupDescriptor, OldCoreData);\r\n");\r
816 fileBuffer.append("}\r\n\r\n");\r
817 }\r
818 break;\r
878ddf1f 819\r
5f907e4a 820 case CommonDefinition.ModuleTypeDxeCore:\r
821 fileBuffer.append("const UINT32 _gUefiDriverRevision = 0;\r\n");\r
822 if (entryPointList == null || entryPointList.length != 1) {\r
61528a1b 823 throw new AutoGenException(\r
5f907e4a 824 "Module type = 'DXE_CORE', can have only one module entry point!");\r
825 } else {\r
ff225cbb 826\r
5f907e4a 827 fileBuffer.append("VOID\r\n");\r
5f907e4a 828 fileBuffer.append(entryPointList[0]);\r
829 fileBuffer.append(" (\n");\r
830 fileBuffer.append(" IN VOID *HobStart\r\n");\r
831 fileBuffer.append(" );\r\n\r\n");\r
832\r
833 fileBuffer.append("VOID\r\n");\r
834 fileBuffer.append("EFIAPI\r\n");\r
835 fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r
836 fileBuffer.append(" IN VOID *HobStart\r\n");\r
837 fileBuffer.append(" )\r\n\r\n");\r
838 fileBuffer.append("{\r\n");\r
839 fileBuffer.append(" ");\r
840 fileBuffer.append(entryPointList[0]);\r
841 fileBuffer.append(" (HobStart);\r\n");\r
842 fileBuffer.append("}\r\n\r\n");\r
843 }\r
844 break;\r
845\r
846 case CommonDefinition.ModuleTypePeim:\r
cb4d97bd 847 entryPointCount = 0;\r
5f907e4a 848 fileBuffer\r
849 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = 0;\r\n");\r
850 if (entryPointList == null || entryPointList.length == 0) {\r
851 fileBuffer.append("EFI_STATUS\r\n");\r
852 fileBuffer.append("EFIAPI\r\n");\r
853 fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r
854 fileBuffer.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");\r
855 fileBuffer.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");\r
856 fileBuffer.append(" )\r\n\r\n");\r
857 fileBuffer.append("{\r\n");\r
858 fileBuffer.append(" return EFI_SUCCESS;\r\n");\r
859 fileBuffer.append("}\r\n\r\n");\r
860 break;\r
861 }\r
862 for (int i = 0; i < entryPointList.length; i++) {\r
863 fileBuffer.append("EFI_STATUS\r\n");\r
5f907e4a 864 fileBuffer.append(entryPointList[i]);\r
865 fileBuffer.append(" (\r\n");\r
866 fileBuffer\r
867 .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");\r
868 fileBuffer\r
869 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");\r
870 fileBuffer.append(" );\r\n");\r
871 entryPointCount++;\r
872\r
873 }\r
874\r
875 fileBuffer.append("EFI_STATUS\r\n");\r
876 fileBuffer.append("EFIAPI\r\n");\r
877 fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r
878 fileBuffer.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");\r
879 fileBuffer.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");\r
880 fileBuffer.append(" )\r\n\r\n");\r
881 fileBuffer.append("{\r\n");\r
882 if (entryPointCount == 1) {\r
883 fileBuffer.append(" return ");\r
884 fileBuffer.append(entryPointList[0]);\r
885 fileBuffer.append(" (FfsHeader, PeiServices);\r\n");\r
886 } else {\r
887 fileBuffer.append(" EFI_STATUS Status;\r\n");\r
888 fileBuffer.append(" EFI_STATUS CombinedStatus;\r\n\r\n");\r
889 fileBuffer.append(" CombinedStatus = EFI_LOAD_ERROR;\r\n\r\n");\r
890 for (int i = 0; i < entryPointList.length; i++) {\r
891 if (!entryPointList[i].equals("")) {\r
892 fileBuffer.append(" Status = ");\r
893 fileBuffer.append(entryPointList[i]);\r
894 fileBuffer.append(" (FfsHeader, PeiServices);\r\n");\r
895 fileBuffer\r
896 .append(" if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {\r\n");\r
897 fileBuffer.append(" CombinedStatus = Status;\r\n");\r
898 fileBuffer.append(" }\r\n\r\n");\r
899 } else {\r
900 break;\r
901 }\r
902 }\r
903 fileBuffer.append(" return CombinedStatus;\r\n");\r
904 }\r
905 fileBuffer.append("}\r\n\r\n");\r
906 break;\r
907\r
908 case CommonDefinition.ModuleTypeDxeSmmDriver:\r
909 entryPointCount = 0;\r
910 //\r
911 // If entryPoint is null, create an empty ProcessModuleEntryPointList\r
912 // function.\r
913 //\r
914 if (entryPointList == null || entryPointList.length == 0) {\r
915 fileBuffer\r
916 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");\r
917 fileBuffer.append(Integer.toString(entryPointCount));\r
918 fileBuffer.append(";\r\n");\r
919 fileBuffer.append("EFI_STATUS\r\n");\r
920 fileBuffer.append("EFIAPI\r\n");\r
921 fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r
922 fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");\r
923 fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r
924 fileBuffer.append(" )\r\n\r\n");\r
925 fileBuffer.append("{\r\n");\r
926 fileBuffer.append(" return EFI_SUCCESS;\r\n");\r
927 fileBuffer.append("}\r\n\r\n");\r
928\r
929 } else {\r
930 for (int i = 0; i < entryPointList.length; i++) {\r
931 fileBuffer.append("EFI_STATUS\r\n");\r
5f907e4a 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
cb4d97bd 990 //entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();\r
991 //entryPointList = CommonDefinition.remDupString(entryPointList);\r
992 //entryPointCount = 0;\r
136adffc 993\r
e425f073 994 unloadImageCount = 0;\r
cb4d97bd 995 if (unloadImageList != null) {\r
996 for (int i = 0; i < unloadImageList.length; i++) {\r
a84091c4 997 fileBuffer.append("EFI_STATUS\r\n");\r
cb4d97bd 998 fileBuffer.append(unloadImageList[i]);\r
a84091c4 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
cb4d97bd 1003 unloadImageCount++;\r
a84091c4 1004 }\r
5f907e4a 1005 }\r
136adffc 1006\r
a84091c4 1007 fileBuffer\r
5f907e4a 1008 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");\r
cb4d97bd 1009 fileBuffer.append(Integer.toString(unloadImageCount));\r
5f907e4a 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
cb4d97bd 1019 if (unloadImageCount == 0) {\r
5f907e4a 1020 fileBuffer.append(" return EFI_SUCCESS;\r\n");\r
cb4d97bd 1021 } else if (unloadImageCount == 1) {\r
5f907e4a 1022 fileBuffer.append(" return ");\r
cb4d97bd 1023 fileBuffer.append(unloadImageList[0]);\r
5f907e4a 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
cb4d97bd 1028 for (int i = 0; i < unloadImageList.length; i++) {\r
5f907e4a 1029 if (i == 0) {\r
136adffc 1030 fileBuffer.append(" Status = ");\r
cb4d97bd 1031 fileBuffer.append(unloadImageList[i]);\r
136adffc 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
cb4d97bd 1036 fileBuffer.append(unloadImageList[i]);\r
878ddf1f 1037 fileBuffer.append("(ImageHandle);\r\n");\r
1038 fileBuffer.append(" } else {\r\n");\r
1039 fileBuffer.append(" Status = ");\r
cb4d97bd 1040 fileBuffer.append(unloadImageList[i]);\r
878ddf1f 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
136adffc 1077 fileBuffer.append(entryPointList[i]);\r
1078 fileBuffer.append(" (\r\n");\r
47f2f011 1079 fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");\r
1080 fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r
136adffc 1081 fileBuffer.append(" );\r\n");\r
1082 entryPointCount++;\r
878ddf1f 1083 }\r
1084\r
878ddf1f 1085 fileBuffer\r
5f907e4a 1086 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");\r
136adffc 1087 fileBuffer.append(Integer.toString(entryPointCount));\r
878ddf1f 1088 fileBuffer.append(";\r\n");\r
136adffc 1089 if (entryPointCount > 1) {\r
1090 fileBuffer\r
5f907e4a 1091 .append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");\r
136adffc 1092 fileBuffer\r
5f907e4a 1093 .append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n");\r
136adffc 1094 }\r
1095 fileBuffer.append("\n");\r
878ddf1f 1096\r
136adffc 1097 fileBuffer.append("EFI_STATUS\r\n");\r
1098 fileBuffer.append("EFIAPI\r\n");\r
1099 fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r
25832ed3 1100 fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");\r
1101 fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r
136adffc 1102 fileBuffer.append(" )\r\n\r\n");\r
1103 fileBuffer.append("{\r\n");\r
878ddf1f 1104\r
136adffc 1105 if (entryPointCount == 1) {\r
1106 fileBuffer.append(" return (");\r
1107 fileBuffer.append(entryPointList[0]);\r
1108 fileBuffer.append(" (ImageHandle, SystemTable));\r\n");\r
1109 } else {\r
1110 for (int i = 0; i < entryPointList.length; i++) {\r
1111 if (!entryPointList[i].equals("")) {\r
1112 fileBuffer\r
5f907e4a 1113 .append(" if (SetJump (&mJumpContext) == 0) {\r\n");\r
136adffc 1114 fileBuffer.append(" ExitDriver (");\r
1115 fileBuffer.append(entryPointList[i]);\r
1116 fileBuffer.append(" (ImageHandle, SystemTable));\r\n");\r
1117 fileBuffer.append(" ASSERT (FALSE);\r\n");\r
1118 fileBuffer.append(" }\r\n");\r
1119 } else {\r
1120 break;\r
1121 }\r
878ddf1f 1122 }\r
136adffc 1123 fileBuffer.append(" return mDriverEntryPointStatus;\r\n");\r
878ddf1f 1124 }\r
136adffc 1125 fileBuffer.append("}\r\n\r\n");\r
878ddf1f 1126\r
2336382f 1127 fileBuffer.append("VOID\r\n");\r
1128 fileBuffer.append("EFIAPI\r\n");\r
136adffc 1129 fileBuffer.append("ExitDriver (\r\n");\r
2336382f 1130 fileBuffer.append(" IN EFI_STATUS Status\r\n");\r
136adffc 1131 fileBuffer.append(" )\r\n\r\n");\r
1132 fileBuffer.append("{\r\n");\r
1133 if (entryPointCount <= 1) {\r
1134 fileBuffer.append(" if (EFI_ERROR (Status)) {\r\n");\r
1135 fileBuffer\r
5f907e4a 1136 .append(" ProcessLibraryDestructorList (gImageHandle, gST);\r\n");\r
136adffc 1137 fileBuffer.append(" }\r\n");\r
1138 fileBuffer\r
5f907e4a 1139 .append(" gBS->Exit (gImageHandle, Status, 0, NULL);\r\n");\r
878ddf1f 1140 } else {\r
136adffc 1141 fileBuffer\r
5f907e4a 1142 .append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");\r
136adffc 1143 fileBuffer.append(" mDriverEntryPointStatus = Status;\r\n");\r
1144 fileBuffer.append(" }\r\n");\r
1145 fileBuffer.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");\r
1146 fileBuffer.append(" ASSERT (FALSE);\r\n");\r
878ddf1f 1147 }\r
136adffc 1148 fileBuffer.append("}\r\n\r\n");\r
878ddf1f 1149\r
878ddf1f 1150 }\r
ff225cbb 1151\r
5f907e4a 1152 //\r
1153 // Add ModuleUnloadImage for DxeDriver and UefiDriver module type.\r
1154 //\r
d8f1335e 1155 //entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();\r
1156 //\r
1157 // Remover duplicate unload entry point.\r
1158 //\r
1159 //entryPointList = CommonDefinition.remDupString(entryPointList);\r
1160 //entryPointCount = 0;\r
e425f073 1161 unloadImageCount = 0;\r
cb4d97bd 1162 if (unloadImageList != null) {\r
1163 for (int i = 0; i < unloadImageList.length; i++) {\r
a84091c4 1164 fileBuffer.append("EFI_STATUS\r\n");\r
d8f1335e 1165 fileBuffer.append("EFIAPI\r\n");\r
cb4d97bd 1166 fileBuffer.append(unloadImageList[i]);\r
a84091c4 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
cb4d97bd 1171 unloadImageCount++;\r
5f907e4a 1172 }\r
1173 }\r
1174\r
1175 fileBuffer\r
1176 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");\r
cb4d97bd 1177 fileBuffer.append(Integer.toString(unloadImageCount));\r
5f907e4a 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
cb4d97bd 1187 if (unloadImageCount == 0) {\r
5f907e4a 1188 fileBuffer.append(" return EFI_SUCCESS;\r\n");\r
cb4d97bd 1189 } else if (unloadImageCount == 1) {\r
5f907e4a 1190 fileBuffer.append(" return ");\r
cb4d97bd 1191 fileBuffer.append(unloadImageList[0]);\r
5f907e4a 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
cb4d97bd 1196 for (int i = 0; i < unloadImageList.length; i++) {\r
25832ed3 1197 if (i == 0) {\r
1198 fileBuffer.append(" Status = ");\r
cb4d97bd 1199 fileBuffer.append(unloadImageList[i]);\r
25832ed3 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
cb4d97bd 1204 fileBuffer.append(unloadImageList[i]);\r
5f907e4a 1205 fileBuffer.append("(ImageHandle);\r\n");\r
1206 fileBuffer.append(" } else {\r\n");\r
1207 fileBuffer.append(" Status = ");\r
cb4d97bd 1208 fileBuffer.append(unloadImageList[i]);\r
5f907e4a 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
cb4d97bd 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
5f907e4a 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
83fba802 1239 String[] ppiList = saq.getPpiArray(this.arch);\r
5f907e4a 1240 for (int i = 0; i < ppiList.length; i++) {\r
1241 this.mPpiList.add(ppiList[i]);\r
1242 }\r
1243\r
83fba802 1244 String[] ppiNotifyList = saq.getPpiNotifyArray(this.arch);\r
5f907e4a 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
cb4d97bd 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
61528a1b 1285 void ProtocolGuidToAutogenC(StringBuffer fileBuffer) throws EdkException {\r
5f907e4a 1286 String[] cNameGuid = null;\r
1287\r
83fba802 1288 String[] protocolList = saq.getProtocolArray(this.arch);\r
5f907e4a 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
83fba802 1297 String[] protocolNotifyList = saq\r
5f907e4a 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
61528a1b 1325 throw new AutoGenException("Can not find protocol Guid ["\r
5f907e4a 1326 + protocolKeyWord + "] declaration in any SPD package!");\r
1327 }\r
1328 }\r
1329 }\r
1330\r
1331 /**\r
cb4d97bd 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
5f907e4a 1341 void GuidGuidToAutogenC(StringBuffer fileBuffer) throws AutoGenException {\r
1342 String[] cNameGuid = null;\r
1343 String guidKeyWord = null;\r
1344\r
83fba802 1345 String[] guidList = saq.getGuidEntryArray(this.arch);\r
5f907e4a 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
cb4d97bd 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
61528a1b 1386 void LibInstanceToAutogenC(StringBuffer fileBuffer) throws EdkException {\r
e425f073 1387 String moduleType = this.moduleId.getModuleType();\r
1388 //\r
1389 // Add library constructor to AutoGen.c\r
1390 //\r
1391 LibConstructorToAutogenC(libConstructList, moduleType,\r
1392 fileBuffer/* autogenC */);\r
1393 //\r
1394 // Add library destructor to AutoGen.c\r
1395 //\r
1396 LibDestructorToAutogenC(libDestructList, moduleType, fileBuffer/* autogenC */);\r
5f907e4a 1397 }\r
1398\r
1399 /**\r
cb4d97bd 1400 LibConstructorToAutogenc\r
1401 \r
1402 This function writes library constructor list to AutoGen.c. The library\r
1403 constructor's parameter and return value depend on module type.\r
1404 \r
1405 @param libInstanceList\r
1406 List of library construct name.\r
1407 @param moduleType\r
1408 Module type.\r
1409 @param fileBuffer\r
1410 String buffer for AutoGen.c\r
1411 @throws Exception\r
1412 **/\r
4353d8e1 1413 void LibConstructorToAutogenC(List<String[]> libInstanceList,\r
61528a1b 1414 String moduleType, StringBuffer fileBuffer) throws EdkException {\r
5f907e4a 1415 boolean isFirst = true;\r
1416\r
1417 //\r
1418 // The library constructor's parameter and return value depend on\r
1419 // module type.\r
1420 //\r
1421 for (int i = 0; i < libInstanceList.size(); i++) {\r
e425f073 1422 if (libInstanceList.get(i)[1].equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) {\r
1423 fileBuffer.append("RETURN_STATUS\r\n");\r
5f907e4a 1424 fileBuffer.append("EFIAPI\r\n");\r
4353d8e1 1425 fileBuffer.append(libInstanceList.get(i)[0]);\r
5f907e4a 1426 fileBuffer.append(" (\r\n");\r
1427 fileBuffer.append(" VOID\r\n");\r
1428 fileBuffer.append(" );\r\n");\r
e425f073 1429 } else {\r
1430 switch (CommonDefinition.getModuleType(moduleType)) {\r
4353d8e1 1431 case CommonDefinition.ModuleTypeBase:\r
1432 fileBuffer.append("RETURN_STATUS\r\n");\r
1433 fileBuffer.append("EFIAPI\r\n");\r
1434 fileBuffer.append(libInstanceList.get(i)[0]);\r
1435 fileBuffer.append(" (\r\n");\r
1436 fileBuffer.append(" VOID\r\n");\r
1437 fileBuffer.append(" );\r\n");\r
1438 break;\r
1439\r
1440 case CommonDefinition.ModuleTypePeiCore:\r
1441 case CommonDefinition.ModuleTypePeim:\r
e425f073 1442 fileBuffer.append("EFI_STATUS\r\n");\r
1443 fileBuffer.append("EFIAPI\r\n");\r
1444 fileBuffer.append(libInstanceList.get(i)[0]);\r
1445 fileBuffer.append(" (\r\n");\r
1446 fileBuffer\r
1447 .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");\r
1448 fileBuffer\r
1449 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");\r
1450 fileBuffer.append(" );\r\n");\r
1451 break;\r
1452 \r
1453 case CommonDefinition.ModuleTypeDxeCore:\r
1454 case CommonDefinition.ModuleTypeDxeDriver:\r
1455 case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
1456 case CommonDefinition.ModuleTypeDxeSmmDriver:\r
1457 case CommonDefinition.ModuleTypeDxeSalDriver:\r
1458 case CommonDefinition.ModuleTypeUefiDriver:\r
1459 case CommonDefinition.ModuleTypeUefiApplication:\r
1460 fileBuffer.append("EFI_STATUS\r\n");\r
1461 fileBuffer.append("EFIAPI\r\n");\r
1462 fileBuffer.append(libInstanceList.get(i)[0]);\r
1463 fileBuffer.append(" (\r\n");\r
1464 fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");\r
1465 fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r
1466 fileBuffer.append(" );\r\n");\r
1467 break;\r
1468\r
1469 }\r
5f907e4a 1470 }\r
1471 }\r
1472\r
1473 //\r
1474 // Add ProcessLibraryConstructorList in AutoGen.c\r
1475 //\r
1476 fileBuffer.append("VOID\r\n");\r
1477 fileBuffer.append("EFIAPI\r\n");\r
1478 fileBuffer.append("ProcessLibraryConstructorList (\r\n");\r
1479 switch (CommonDefinition.getModuleType(moduleType)) {\r
1480 case CommonDefinition.ModuleTypeBase:\r
1481 fileBuffer.append(" VOID\r\n");\r
1482 break;\r
1483\r
1484 case CommonDefinition.ModuleTypePeiCore:\r
1485 case CommonDefinition.ModuleTypePeim:\r
1486 fileBuffer.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");\r
1487 fileBuffer\r
1488 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");\r
1489 break;\r
1490\r
1491 case CommonDefinition.ModuleTypeDxeCore:\r
1492 case CommonDefinition.ModuleTypeDxeDriver:\r
1493 case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
1494 case CommonDefinition.ModuleTypeDxeSmmDriver:\r
1495 case CommonDefinition.ModuleTypeDxeSalDriver:\r
1496 case CommonDefinition.ModuleTypeUefiDriver:\r
1497 case CommonDefinition.ModuleTypeUefiApplication:\r
1498 fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");\r
1499 fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r
1500 break;\r
1501 }\r
1502\r
1503 fileBuffer.append(" )\r\n");\r
1504 fileBuffer.append("{\r\n");\r
136adffc 1505 //\r
1506 // If no constructor function, return EFI_SUCCESS.\r
1507 //\r
1508 //if (libInstanceList.size() == 0){\r
1509 // fileBuffer.append(" return EFI_SUCCESS;\r\n");\r
1510 //}\r
5f907e4a 1511 for (int i = 0; i < libInstanceList.size(); i++) {\r
1512 if (isFirst) {\r
1513 fileBuffer.append(" EFI_STATUS Status;\r\n");\r
136adffc 1514 fileBuffer.append(" Status = EFI_SUCCESS;\r\n");\r
5f907e4a 1515 fileBuffer.append("\r\n");\r
1516 isFirst = false;\r
1517 }\r
e425f073 1518 if (libInstanceList.get(i)[1].equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) {\r
5f907e4a 1519 fileBuffer.append(" Status = ");\r
4353d8e1 1520 fileBuffer.append(libInstanceList.get(i)[0]);\r
5f907e4a 1521 fileBuffer.append("();\r\n");\r
e425f073 1522 } else {\r
1523 switch (CommonDefinition.getModuleType(moduleType)) {\r
1524 case CommonDefinition.ModuleTypeBase:\r
1525 fileBuffer.append(" Status = ");\r
1526 fileBuffer.append(libInstanceList.get(i)[0]);\r
1527 fileBuffer.append("();\r\n");\r
1528 break;\r
1529 case CommonDefinition.ModuleTypePeiCore:\r
1530 case CommonDefinition.ModuleTypePeim:\r
1531 fileBuffer.append(" Status = ");\r
1532 fileBuffer.append(libInstanceList.get(i)[0]);\r
1533 fileBuffer.append(" (FfsHeader, PeiServices);\r\n");\r
1534 break;\r
1535 case CommonDefinition.ModuleTypeDxeCore:\r
1536 case CommonDefinition.ModuleTypeDxeDriver:\r
1537 case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
1538 case CommonDefinition.ModuleTypeDxeSmmDriver:\r
1539 case CommonDefinition.ModuleTypeDxeSalDriver:\r
1540 case CommonDefinition.ModuleTypeUefiDriver:\r
1541 case CommonDefinition.ModuleTypeUefiApplication:\r
1542 fileBuffer.append(" Status = ");\r
1543 fileBuffer.append(libInstanceList.get(i)[0]);\r
1544 fileBuffer.append(" (ImageHandle, SystemTable);\r\n");\r
1545 break;\r
1546 default:\r
1547 EdkLog.log(EdkLog.EDK_INFO,"Autogen doesn't know how to deal with module type - " + moduleType + "!");\r
1548 }\r
4353d8e1 1549 \r
5f907e4a 1550 }\r
1551 fileBuffer.append(" ASSERT_EFI_ERROR (Status);\r\n");\r
1552 }\r
1553 fileBuffer.append("}\r\n");\r
1554 }\r
1555\r
1556 /**\r
cb4d97bd 1557 LibDestructorToAutogenc\r
1558 \r
1559 This function writes library destructor list to AutoGen.c. The library\r
1560 destructor's parameter and return value depend on module type.\r
1561 \r
1562 @param libInstanceList\r
1563 List of library destructor name.\r
1564 @param moduleType\r
1565 Module type.\r
1566 @param fileBuffer\r
1567 String buffer for AutoGen.c\r
1568 @throws Exception\r
1569 **/\r
4353d8e1 1570 void LibDestructorToAutogenC(List<String[]> libInstanceList,\r
61528a1b 1571 String moduleType, StringBuffer fileBuffer) throws EdkException {\r
5f907e4a 1572 boolean isFirst = true;\r
1573 for (int i = 0; i < libInstanceList.size(); i++) {\r
e425f073 1574 if (libInstanceList.get(i)[1].equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) {\r
5f907e4a 1575 fileBuffer.append("RETURN_STATUS\r\n");\r
1576 fileBuffer.append("EFIAPI\r\n");\r
4353d8e1 1577 fileBuffer.append(libInstanceList.get(i)[0]);\r
5f907e4a 1578 fileBuffer.append(" (\r\n");\r
1579 fileBuffer.append(" VOID\r\n");\r
1580 fileBuffer.append(" );\r\n");\r
e425f073 1581 } else {\r
1582 switch (CommonDefinition.getModuleType(moduleType)) {\r
1583 case CommonDefinition.ModuleTypeBase:\r
1584 fileBuffer.append("RETURN_STATUS\r\n");\r
1585 fileBuffer.append("EFIAPI\r\n");\r
1586 fileBuffer.append(libInstanceList.get(i)[0]);\r
1587 fileBuffer.append(" (\r\n");\r
1588 fileBuffer.append(" VOID\r\n");\r
1589 fileBuffer.append(" );\r\n");\r
1590 break;\r
1591 case CommonDefinition.ModuleTypePeiCore:\r
1592 case CommonDefinition.ModuleTypePeim:\r
1593 fileBuffer.append("EFI_STATUS\r\n");\r
1594 fileBuffer.append("EFIAPI\r\n");\r
1595 fileBuffer.append(libInstanceList.get(i)[0]);\r
1596 fileBuffer.append(" (\r\n");\r
1597 fileBuffer\r
1598 .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");\r
1599 fileBuffer\r
1600 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");\r
1601 fileBuffer.append(" );\r\n");\r
1602 break;\r
1603 case CommonDefinition.ModuleTypeDxeCore:\r
1604 case CommonDefinition.ModuleTypeDxeDriver:\r
1605 case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
1606 case CommonDefinition.ModuleTypeDxeSmmDriver:\r
1607 case CommonDefinition.ModuleTypeDxeSalDriver:\r
1608 case CommonDefinition.ModuleTypeUefiDriver:\r
1609 case CommonDefinition.ModuleTypeUefiApplication:\r
1610 fileBuffer.append("EFI_STATUS\r\n");\r
1611 fileBuffer.append("EFIAPI\r\n");\r
1612 fileBuffer.append(libInstanceList.get(i)[0]);\r
1613 fileBuffer.append(" (\r\n");\r
1614 fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");\r
1615 fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r
1616 fileBuffer.append(" );\r\n");\r
1617 break;\r
1618 }\r
5f907e4a 1619 }\r
1620 }\r
1621\r
1622 //\r
1623 // Write ProcessLibraryDestructor list to autogen.c\r
1624 //\r
1625 switch (CommonDefinition.getModuleType(moduleType)) {\r
1626 case CommonDefinition.ModuleTypeBase:\r
1627 case CommonDefinition.ModuleTypePeiCore:\r
1628 case CommonDefinition.ModuleTypePeim:\r
1629 break;\r
1630 case CommonDefinition.ModuleTypeDxeCore:\r
1631 case CommonDefinition.ModuleTypeDxeDriver:\r
1632 case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
1633 case CommonDefinition.ModuleTypeDxeSmmDriver:\r
1634 case CommonDefinition.ModuleTypeDxeSalDriver:\r
1635 case CommonDefinition.ModuleTypeUefiDriver:\r
1636 case CommonDefinition.ModuleTypeUefiApplication:\r
1637 fileBuffer.append("VOID\r\n");\r
1638 fileBuffer.append("EFIAPI\r\n");\r
1639 fileBuffer.append("ProcessLibraryDestructorList (\r\n");\r
1640 fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");\r
1641 fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r
1642 fileBuffer.append(" )\r\n");\r
1643 fileBuffer.append("{\r\n");\r
878ddf1f 1644 //\r
136adffc 1645 // If no library destructor function, return EFI_SUCCESS.\r
878ddf1f 1646 //\r
ff225cbb 1647\r
5f907e4a 1648 for (int i = 0; i < libInstanceList.size(); i++) {\r
1649 if (isFirst) {\r
1650 fileBuffer.append(" EFI_STATUS Status;\r\n");\r
136adffc 1651 fileBuffer.append(" Status = EFI_SUCCESS;\r\n");\r
5f907e4a 1652 fileBuffer.append("\r\n");\r
1653 isFirst = false;\r
1654 }\r
e425f073 1655 if (libInstanceList.get(i)[1].equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) {\r
4353d8e1 1656 fileBuffer.append(" Status = ");\r
1657 fileBuffer.append(libInstanceList.get(i)[0]);\r
1658 fileBuffer.append("();\r\n");\r
1659 fileBuffer.append(" VOID\r\n");\r
e425f073 1660 } else {\r
1661 fileBuffer.append(" Status = ");\r
1662 fileBuffer.append(libInstanceList.get(i)[0]);\r
1663 fileBuffer.append("(ImageHandle, SystemTable);\r\n");\r
1664 fileBuffer.append(" ASSERT_EFI_ERROR (Status);\r\n");\r
1665 }\r
5f907e4a 1666 }\r
1667 fileBuffer.append("}\r\n");\r
1668 break;\r
1669 }\r
1670 }\r
1671\r
1672 /**\r
cb4d97bd 1673 ExternsDriverBindingToAutoGenC\r
1674 \r
1675 This function is to write DRIVER_BINDING, COMPONENT_NAME,\r
1676 DRIVER_CONFIGURATION, DRIVER_DIAGNOSTIC in AutoGen.c.\r
1677 \r
1678 @param fileBuffer\r
1679 String buffer for AutoGen.c\r
1680 **/\r
5f907e4a 1681 void ExternsDriverBindingToAutoGenC(StringBuffer fileBuffer)\r
61528a1b 1682 throws EdkException {\r
5f907e4a 1683 //\r
d8f1335e 1684 // Get the arry of extern. The driverBindingGroup is a 2 dimension array.\r
e425f073 1685 // The second dimension is include following element: DriverBinding, \r
1686 // ComponentName, DriverConfiguration, DriverDiag;\r
1687 // \r
d8f1335e 1688 String[][] driverBindingGroup = this.saq.getExternProtocolGroup();\r
5f907e4a 1689\r
e87022aa 1690\r
e425f073 1691 //\r
1692 // inital BitMask;\r
1693 // \r
1694 int BitMask = 0;\r
5f907e4a 1695\r
1696 //\r
1697 // Write driver binding protocol extern to autogen.c\r
1698 //\r
d8f1335e 1699 for (int i = 0; i < driverBindingGroup.length; i++) {\r
e425f073 1700 if (driverBindingGroup[i][0] != null) {\r
1701 fileBuffer.append("extern EFI_DRIVER_BINDING_PROTOCOL ");\r
d8f1335e 1702 fileBuffer.append(driverBindingGroup[i][0]);\r
1703 fileBuffer.append(";\r\n");\r
e425f073 1704 } \r
5f907e4a 1705 }\r
1706\r
1707 //\r
1708 // Write component name protocol extern to autogen.c\r
1709 //\r
e425f073 1710 if (!componentNamePcd) {\r
1711 for (int i = 0; i < driverBindingGroup.length; i++) {\r
1712 if (driverBindingGroup[i][1]!= null) {\r
1713 if (driverBindingGroup[i][0] != null) {\r
1714 BitMask |= 0x01;\r
1715 fileBuffer.append("extern EFI_COMPONENT_NAME_PROTOCOL ");\r
e87022aa 1716 fileBuffer.append(driverBindingGroup[i][1]);\r
1717 fileBuffer.append(";\r\n");\r
e425f073 1718 } else {\r
e87022aa 1719 throw new AutoGenException("DriverBinding can't be empty!!");\r
e425f073 1720 }\r
1721 }\r
1722 }\r
1723 }\r
e87022aa 1724 \r
5f907e4a 1725 //\r
1726 // Write driver configration protocol extern to autogen.c\r
1727 //\r
e425f073 1728 for (int i = 0; i < driverBindingGroup.length; i++) {\r
1729 if (driverBindingGroup[i][2] != null) {\r
1730 if (driverBindingGroup[i][0] != null) {\r
d8f1335e 1731 BitMask |= 0x02;\r
e425f073 1732 fileBuffer.append("extern EFI_DRIVER_CONFIGURATION_PROTOCOL ");\r
d8f1335e 1733 fileBuffer.append(driverBindingGroup[i][2]);\r
1734 fileBuffer.append(";\r\n");\r
e425f073 1735 } else {\r
d8f1335e 1736 throw new AutoGenException("DriverBinding can't be empty!!");\r
e425f073 1737 }\r
1738 }\r
1739 }\r
d8f1335e 1740 \r
5f907e4a 1741 //\r
1742 // Write driver dignastic protocol extern to autogen.c\r
1743 //\r
e425f073 1744 if (!driverDiagnostPcd) {\r
1745 for (int i = 0; i < driverBindingGroup.length; i++) {\r
1746 if (driverBindingGroup[i][3] != null) {\r
1747 if (driverBindingGroup[i][0] != null) {\r
e87022aa 1748 BitMask |= 0x04;\r
1749 fileBuffer.append("extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL ");\r
1750 fileBuffer.append(driverBindingGroup[i][3]);\r
1751 fileBuffer.append(";\r\n");\r
e425f073 1752 } else {\r
e87022aa 1753 throw new AutoGenException("DriverBinding can't be empty!!");\r
e425f073 1754 }\r
1755 }\r
1756 }\r
1757 }\r
1758 \r
d8f1335e 1759 \r
5f907e4a 1760 //\r
1761 // Write driver module protocol bitmask.\r
1762 //\r
1763 fileBuffer\r
1764 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverModelProtocolBitmask = ");\r
1765 fileBuffer.append(Integer.toString(BitMask));\r
1766 fileBuffer.append(";\r\n");\r
1767\r
1768 //\r
1769 // Write driver module protocol list entry\r
1770 //\r
1771 fileBuffer\r
1772 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverModelProtocolListEntries = ");\r
1773\r
d8f1335e 1774 fileBuffer.append(Integer.toString(driverBindingGroup.length));\r
5f907e4a 1775 fileBuffer.append(";\r\n");\r
1776\r
1777 //\r
1778 // Write drive module protocol list to autogen.c\r
1779 //\r
e425f073 1780 if (driverBindingGroup.length > 0) {\r
1781 fileBuffer\r
5f907e4a 1782 .append("GLOBAL_REMOVE_IF_UNREFERENCED const EFI_DRIVER_MODEL_PROTOCOL_LIST _gDriverModelProtocolList[] = {");\r
e425f073 1783 }\r
d8f1335e 1784 \r
e425f073 1785 \r
d8f1335e 1786 for (int i = 0; i < driverBindingGroup.length; i++) {\r
5f907e4a 1787 if (i != 0) {\r
1788 fileBuffer.append(",");\r
1789 }\r
e425f073 1790 //\r
1791 // DriverBinding\r
1792 // \r
1793 fileBuffer.append("\r\n {\r\n");\r
5f907e4a 1794 fileBuffer.append(" &");\r
d8f1335e 1795 fileBuffer.append(driverBindingGroup[i][0]);\r
5f907e4a 1796 fileBuffer.append(", \r\n");\r
e425f073 1797 \r
e87022aa 1798 //\r
e425f073 1799 // ComponentName\r
1800 // \r
1801 if (driverBindingGroup[i][1] != null && componentNamePcd != true) {\r
5f907e4a 1802 fileBuffer.append(" &");\r
d8f1335e 1803 fileBuffer.append(driverBindingGroup[i][1]);\r
5f907e4a 1804 fileBuffer.append(", \r\n");\r
1805 } else {\r
1806 fileBuffer.append(" NULL, \r\n");\r
1807 }\r
1808\r
e425f073 1809 //\r
1810 // DriverConfiguration\r
1811 // \r
d8f1335e 1812 if (driverBindingGroup[i][2] != null) {\r
5f907e4a 1813 fileBuffer.append(" &");\r
d8f1335e 1814 fileBuffer.append(driverBindingGroup[i][2]);\r
5f907e4a 1815 fileBuffer.append(", \r\n");\r
1816 } else {\r
1817 fileBuffer.append(" NULL, \r\n");\r
1818 }\r
1819\r
e425f073 1820 //\r
1821 // DriverDiagnostic\r
1822 // \r
1823 if (driverBindingGroup[i][3] != null && driverDiagnostPcd != true) {\r
5f907e4a 1824 fileBuffer.append(" &");\r
d8f1335e 1825 fileBuffer.append(driverBindingGroup[i][3]);\r
5f907e4a 1826 fileBuffer.append(", \r\n");\r
1827 } else {\r
1828 fileBuffer.append(" NULL, \r\n");\r
1829 }\r
1830 fileBuffer.append(" }");\r
1831 }\r
d8f1335e 1832\r
e425f073 1833 if (driverBindingGroup.length > 0) {\r
1834 fileBuffer.append("\r\n};\r\n");\r
1835 }\r
5f907e4a 1836 }\r
1837\r
1838 /**\r
cb4d97bd 1839 ExternCallBackToAutoGenC\r
1840 \r
1841 This function adds <SetVirtualAddressMapCallBack> and\r
1842 <ExitBootServicesCallBack> infomation to AutoGen.c\r
1843 \r
1844 @param fileBuffer\r
1845 String buffer for AutoGen.c\r
1846 @throws BuildException\r
1847 **/\r
5f907e4a 1848 void ExternCallBackToAutoGenC(StringBuffer fileBuffer)\r
61528a1b 1849 throws EdkException {\r
5f907e4a 1850 //\r
1851 // Collect module's <SetVirtualAddressMapCallBack> and\r
1852 // <ExitBootServiceCallBack> and add to setVirtualAddList\r
1853 // exitBootServiceList.\r
1854 //\r
83fba802 1855 String[] setVirtuals = saq.getSetVirtualAddressMapCallBackArray();\r
1856 String[] exitBoots = saq.getExitBootServicesCallBackArray();\r
a2733a33 1857 if (setVirtuals != null) {\r
1858 for (int j = 0; j < setVirtuals.length; j++) {\r
5f907e4a 1859 this.setVirtalAddList.add(setVirtuals[j]);\r
1860 }\r
1861 }\r
1862 if (exitBoots != null) {\r
1863 for (int k = 0; k < exitBoots.length; k++) {\r
1864 this.exitBootServiceList.add(exitBoots[k]);\r
1865 }\r
1866 }\r
1867 //\r
1868 // Add c code in autogen.c which relate to <SetVirtualAddressMapCallBack>\r
1869 // and <ExitBootServicesCallBack>\r
1870 //\r
1871 String moduleType = this.moduleId.getModuleType();\r
5f907e4a 1872 switch (CommonDefinition.getModuleType(moduleType)) {\r
1873 case CommonDefinition.ModuleTypeDxeDriver:\r
1874 case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
1875 case CommonDefinition.ModuleTypeDxeSalDriver:\r
1876 case CommonDefinition.ModuleTypeUefiDriver:\r
e425f073 1877 case CommonDefinition.ModuleTypeUefiApplication:\r
1878 //\r
1879 // If moduleType is one of above, call setVirtualAddressToAutogenC,\r
1880 // and setExitBootServiceToAutogenC.\r
1881 // \r
c60019f6 1882 setVirtualAddressToAutogenC(fileBuffer);\r
e425f073 1883 setExitBootServiceToAutogenC(fileBuffer);\r
5f907e4a 1884 break;\r
1885 default:\r
1886 break;\r
1887 }\r
5f907e4a 1888 }\r
878ddf1f 1889\r
cb4d97bd 1890 /**\r
1891 copyFlashMapHToDebugDir\r
1892 \r
1893 This function is to copy the falshmap.h to debug directory and change \r
1894 its name to TianoR8FlashMap.h\r
1895 \r
1896 @param \r
1897 @return\r
1898 **/\r
73b4e31a 1899 private void copyFlashMapHToDebugDir() throws AutoGenException{\r
ff225cbb 1900\r
cb4d97bd 1901 File inFile = new File(fvDir + File.separatorChar + CommonDefinition.FLASHMAPH);\r
73b4e31a 1902 int size = (int)inFile.length();\r
1903 byte[] buffer = new byte[size];\r
cb4d97bd 1904 File outFile = new File (this.outputPath + File.separatorChar + CommonDefinition.TIANOR8PLASHMAPH);\r
5f907e4a 1905 //\r
1906 // If TianoR8FlashMap.h existed and the flashMap.h don't change,\r
1907 // do nothing.\r
1908 //\r
31a9215c 1909 if ((!outFile.exists()) ||(inFile.lastModified() - outFile.lastModified()) >= 0) {\r
e425f073 1910 if (inFile.exists()) {\r
1911 try{\r
1912 FileInputStream fis = new FileInputStream (inFile);\r
1913 fis.read(buffer);\r
1914 FileOutputStream fos = new FileOutputStream(outFile);\r
1915 fos.write(buffer);\r
1916 fis.close();\r
1917 fos.close();\r
1918 } catch (IOException e){\r
61528a1b 1919 throw new AutoGenException("The file, flashMap.h can't be open!");\r
e425f073 1920 }\r
1921 \r
1922 } else {\r
1923 throw new AutoGenException("The file, flashMap.h doesn't exist!");\r
1924 }\r
5f907e4a 1925 }\r
73b4e31a 1926 }\r
ff225cbb 1927\r
2336382f 1928 /**\r
cb4d97bd 1929 This function first order the library instances, then collect\r
1930 library instance 's PPI, Protocol, GUID,\r
1931 SetVirtalAddressMapCallBack, ExitBootServiceCallBack, and\r
1932 Destructor, Constructor.\r
1933 \r
1934 @param\r
1935 @return \r
5f907e4a 1936 **/\r
892b0e7a 1937 private void collectLibInstanceInfo() throws EdkException{\r
5f907e4a 1938 int index;\r
1939\r
5f907e4a 1940 String libConstructName = null;\r
1941 String libDestructName = null;\r
e425f073 1942 String libModuleType = null;\r
5f907e4a 1943 String[] setVirtuals = null;\r
1944 String[] exitBoots = null;\r
1945\r
83fba802 1946 ModuleIdentification[] libraryIdList = saq.getLibraryInstance(this.arch);\r
5f907e4a 1947\r
e425f073 1948 if (libraryIdList != null) {\r
1949 //\r
1950 // Reorder library instance sequence.\r
1951 //\r
1952 AutogenLibOrder libOrder = new AutogenLibOrder(libraryIdList,\r
1953 this.arch);\r
1954 List<ModuleIdentification> orderList = libOrder\r
1955 .orderLibInstance();\r
1956 \r
1957 if (orderList != null) {\r
1958 //\r
1959 // Process library instance one by one.\r
1960 //\r
1961 for (int i = 0; i < orderList.size(); i++) {\r
1962 //\r
1963 // Get library instance basename.\r
1964 //\r
1965 ModuleIdentification libInstanceId = orderList.get(i);\r
1966 \r
1967 //\r
1968 // Get override map\r
1969 //\r
1970 \r
1971 Map<String, XmlObject> libDoc = GlobalData.getDoc(libInstanceId, this.arch);\r
1972 saq.push(libDoc);\r
1973 //\r
1974 // Get <PPis>, <Protocols>, <Guids> list of this library\r
1975 // instance.\r
1976 //\r
1977 String[] ppiList = saq.getPpiArray(this.arch);\r
1978 String[] ppiNotifyList = saq.getPpiNotifyArray(this.arch);\r
1979 String[] protocolList = saq.getProtocolArray(this.arch);\r
1980 String[] protocolNotifyList = saq.getProtocolNotifyArray(this.arch);\r
1981 String[] guidList = saq.getGuidEntryArray(this.arch);\r
1982 PackageIdentification[] pkgList = saq.getDependencePkg(this.arch);\r
1983 \r
1984 //\r
1985 // Add those ppi, protocol, guid in global ppi,\r
1986 // protocol, guid\r
1987 // list.\r
1988 //\r
1989 for (index = 0; index < ppiList.length; index++) {\r
1990 this.mPpiList.add(ppiList[index]);\r
1991 }\r
1992 \r
1993 for (index = 0; index < ppiNotifyList.length; index++) {\r
1994 this.mPpiList.add(ppiNotifyList[index]);\r
1995 }\r
1996 \r
1997 for (index = 0; index < protocolList.length; index++) {\r
1998 this.mProtocolList.add(protocolList[index]);\r
1999 }\r
2000 \r
2001 for (index = 0; index < protocolNotifyList.length; index++) {\r
2002 this.mProtocolList.add(protocolNotifyList[index]);\r
2003 }\r
2004 \r
2005 for (index = 0; index < guidList.length; index++) {\r
2006 this.mGuidList.add(guidList[index]);\r
2007 }\r
2008 for (index = 0; index < pkgList.length; index++) {\r
2009 if (!this.mDepPkgList.contains(pkgList[index])) {\r
2010 this.mDepPkgList.add(pkgList[index]);\r
2011 }\r
2012 }\r
2013 \r
2014 //\r
2015 // If not yet parse this library instance's constructor\r
2016 // element,parse it.\r
2017 //\r
2018 libConstructName = saq.getLibConstructorName();\r
2019 libDestructName = saq.getLibDestructorName();\r
2020 libModuleType = saq.getModuleType();\r
2021 \r
2022 //\r
2023 // Collect SetVirtualAddressMapCallBack and\r
2024 // ExitBootServiceCallBack.\r
2025 //\r
2026 setVirtuals = saq.getSetVirtualAddressMapCallBackArray();\r
2027 exitBoots = saq.getExitBootServicesCallBackArray();\r
2028 if (setVirtuals != null) {\r
2029 for (int j = 0; j < setVirtuals.length; j++) {\r
2030 this.setVirtalAddList.add(setVirtuals[j]);\r
2031 }\r
2032 }\r
2033 if (exitBoots != null) {\r
2034 for (int k = 0; k < exitBoots.length; k++) {\r
2035 this.exitBootServiceList.add(exitBoots[k]);\r
2036 }\r
2037 }\r
2038 saq.pop();\r
2039 //\r
2040 // Add dependent library instance constructor function.\r
2041 //\r
2042 if (libConstructName != null) {\r
2043 this.libConstructList.add(new String[] {libConstructName, libModuleType});\r
2044 }\r
2045 //\r
2046 // Add dependent library instance destructor fuction.\r
2047 //\r
2048 if (libDestructName != null) {\r
2049 this.libDestructList.add(new String[] {libDestructName, libModuleType});\r
2050 }\r
2051 }\r
2052 }\r
2053 }\r
5f907e4a 2054 }\r
e425f073 2055 private void setVirtualAddressToAutogenC(StringBuffer fileBuffer){\r
c60019f6 2056 //\r
2057 // Entry point lib for these module types needs to know the count\r
2058 // of entryPoint.\r
2059 //\r
e425f073 2060 fileBuffer\r
c60019f6 2061 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverSetVirtualAddressMapEventCount = ");\r
2062\r
e425f073 2063 //\r
2064 // If the list is not valid or has no entries set count to zero else\r
2065 // set count to the number of valid entries\r
2066 //\r
2067 int Count = 0;\r
2068 int i = 0;\r
2069 if (this.setVirtalAddList != null) {\r
2070 for (i = 0; i < this.setVirtalAddList.size(); i++) {\r
2071 if (this.setVirtalAddList.get(i).equalsIgnoreCase("")) {\r
2072 break;\r
2073 }\r
2074 }\r
2075 Count = i;\r
2076 }\r
2077 \r
2078 fileBuffer.append(Integer.toString(Count));\r
2079 fileBuffer.append(";\r\n\r\n");\r
2080 if (this.setVirtalAddList == null || this.setVirtalAddList.size() == 0) {\r
2081 //\r
2082 // No data so make a NULL list\r
2083 //\r
2084 fileBuffer\r
2085 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {\r\n");\r
2086 fileBuffer.append(" NULL\r\n");\r
2087 fileBuffer.append("};\r\n\r\n");\r
2088 } else {\r
2089 //\r
2090 // Write SetVirtualAddressMap function definition.\r
2091 //\r
2092 for (i = 0; i < this.setVirtalAddList.size(); i++) {\r
2093 if (this.setVirtalAddList.get(i).equalsIgnoreCase("")) {\r
2094 break;\r
2095 }\r
2096 fileBuffer.append("VOID\r\n");\r
2097 fileBuffer.append("EFIAPI\r\n");\r
2098 fileBuffer.append(this.setVirtalAddList.get(i));\r
2099 fileBuffer.append(" (\r\n");\r
2100 fileBuffer.append(" IN EFI_EVENT Event,\r\n");\r
2101 fileBuffer.append(" IN VOID *Context\r\n");\r
2102 fileBuffer.append(" );\r\n\r\n");\r
2103 }\r
2104 \r
2105 //\r
2106 // Write SetVirtualAddressMap entry point array.\r
2107 //\r
2108 fileBuffer\r
2109 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {");\r
2110 for (i = 0; i < this.setVirtalAddList.size(); i++) {\r
2111 if (this.setVirtalAddList.get(i).equalsIgnoreCase("")) {\r
2112 break;\r
2113 }\r
2114 \r
2115 if (i == 0) {\r
2116 fileBuffer.append("\r\n ");\r
2117 } else {\r
2118 fileBuffer.append(",\r\n ");\r
2119 }\r
2120 \r
2121 fileBuffer.append(this.setVirtalAddList.get(i));\r
2122 }\r
2123 //\r
2124 // add the NULL at the end of _gDriverSetVirtualAddressMapEvent list.\r
2125 //\r
2126 fileBuffer.append(",\r\n NULL");\r
2127 fileBuffer.append("\r\n};\r\n\r\n");\r
2128 }\r
c60019f6 2129 }\r
2130\r
2131\r
2132 private void setExitBootServiceToAutogenC(StringBuffer fileBuffer){\r
2133 //\r
e425f073 2134 // Entry point lib for these module types needs to know the count.\r
2135 //\r
2136 fileBuffer\r
2137 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverExitBootServicesEventCount = ");\r
2138 \r
2139 //\r
2140 // If the list is not valid or has no entries set count to zero else\r
2141 // set count to the number of valid entries.\r
2142 //\r
2143 int Count = 0;\r
c60019f6 2144 int i = 0; \r
e425f073 2145 if (this.exitBootServiceList != null) {\r
2146 for (i = 0; i < this.exitBootServiceList.size(); i++) {\r
2147 if (this.exitBootServiceList.get(i).equalsIgnoreCase("")) {\r
2148 break;\r
2149 }\r
2150 }\r
2151 Count = i;\r
2152 }\r
2153 fileBuffer.append(Integer.toString(Count));\r
2154 fileBuffer.append(";\r\n\r\n");\r
2155 \r
c60019f6 2156 if (this.exitBootServiceList == null || this.exitBootServiceList.size() == 0) {\r
e425f073 2157 // \r
2158 // No data so make a NULL list.\r
2159 //\r
2160 fileBuffer\r
2161 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {\r\n");\r
2162 fileBuffer.append(" NULL\r\n");\r
2163 fileBuffer.append("};\r\n\r\n");\r
2164 } else {\r
2165 //\r
2166 // Write DriverExitBootServices function definition.\r
2167 //\r
2168 for (i = 0; i < this.exitBootServiceList.size(); i++) {\r
2169 if (this.exitBootServiceList.get(i).equalsIgnoreCase("")) {\r
2170 break;\r
2171 }\r
2172 \r
2173 fileBuffer.append("VOID\r\n");\r
2174 fileBuffer.append("EFIAPI\r\n");\r
2175 fileBuffer.append(this.exitBootServiceList.get(i));\r
2176 fileBuffer.append(" (\r\n");\r
2177 fileBuffer.append(" IN EFI_EVENT Event,\r\n");\r
2178 fileBuffer.append(" IN VOID *Context\r\n");\r
2179 fileBuffer.append(" );\r\n\r\n");\r
2180 }\r
2181 \r
2182 //\r
2183 // Write DriverExitBootServices entry point array.\r
2184 //\r
2185 fileBuffer\r
2186 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {");\r
2187 for (i = 0; i < this.exitBootServiceList.size(); i++) {\r
2188 if (this.exitBootServiceList.get(i).equalsIgnoreCase("")) {\r
2189 break;\r
2190 }\r
2191 \r
2192 if (i == 0) {\r
2193 fileBuffer.append("\r\n ");\r
2194 } else {\r
2195 fileBuffer.append(",\r\n ");\r
2196 }\r
2197 fileBuffer.append(this.exitBootServiceList.get(i));\r
2198 }\r
2199 \r
2200 fileBuffer.append(",\r\n NULL");\r
2201 fileBuffer.append("\r\n};\r\n\r\n");\r
2202 } \r
2203 }\r
2204 /**\r
2205 setPcdComponentName\r
2206 \r
2207 Get the Pcd Value of ComponentName to \r
2208 decide whether need to disable the componentName. \r
2209 \r
2210 **/\r
2211 public void setPcdComponentName (){\r
2212 String pcdValue = null;\r
2213 pcdValue = saq.getPcdValueBycName("PcdComponentNameDisable");\r
2214 if (pcdValue != null && pcdValue.equalsIgnoreCase("true")) {\r
2215 this.componentNamePcd = true;\r
2216 }\r
2217 }\r
2218 \r
2219 /**\r
2220 setPcdDriverDiagnostic \r
2221 \r
2222 Get the Pcd Value of DriverDiagnostic to \r
2223 decide whether need to disable DriverDiagnostic.\r
2224 \r
2225 **/\r
2226 public void setPcdDriverDiagnostic (){\r
2227 String pcdValue = null;\r
2228 pcdValue = saq.getPcdValueBycName("PcdDriverDiagnosticsDisable");\r
2229 if (pcdValue != null && pcdValue.equalsIgnoreCase("true")) {\r
2230 this.driverDiagnostPcd = true;\r
2231 } \r
2232 } \r
2233 \r
2336382f 2234}\r