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