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