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