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