]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Java/Source/GenBuild/org/tianocore/build/autogen/AutoGen.java
Restored the SetVirtualAddress and SetExitBootService related code generation for...
[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
a5dd05b5 1103 if (CommonDefinition.getModuleType(typeStr) == CommonDefinition.ModuleTypeUefiApplication) {\r
1104 fileBuffer.append(" Exit (");\r
1105 } else {\r
1106 fileBuffer.append(" ExitDriver (");\r
1107 }\r
136adffc 1108 fileBuffer.append(entryPointList[i]);\r
aacce761 1109 fileBuffer.append(" (ImageHandle, SystemTable));\r\n");\r
1110 fileBuffer.append(" ASSERT (FALSE);\r\n");\r
1111 fileBuffer.append(" }\r\n");\r
136adffc 1112 } else {\r
1113 break;\r
1114 }\r
878ddf1f 1115 }\r
aacce761 1116 fileBuffer.append(" return mDriverEntryPointStatus;\r\n");\r
878ddf1f 1117 }\r
aacce761 1118 fileBuffer.append("}\r\n\r\n");\r
1119\r
a5dd05b5 1120 if (CommonDefinition.getModuleType(typeStr) != CommonDefinition.ModuleTypeUefiApplication) {\r
1121 fileBuffer.append("VOID\r\n");\r
1122 fileBuffer.append("EFIAPI\r\n");\r
1123 fileBuffer.append("ExitDriver (\r\n");\r
1124 fileBuffer.append(" IN EFI_STATUS Status\r\n");\r
1125 fileBuffer.append(" )\r\n\r\n");\r
1126 fileBuffer.append("{\r\n");\r
1127 if (entryPointCount <= 1) {\r
1128 fileBuffer.append(" if (EFI_ERROR (Status)) {\r\n");\r
1129 fileBuffer.append(" ProcessLibraryDestructorList (gImageHandle, gST);\r\n");\r
1130 fileBuffer.append(" }\r\n");\r
1131 fileBuffer.append(" gBS->Exit (gImageHandle, Status, 0, NULL);\r\n");\r
1132 } else {\r
1133 fileBuffer.append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");\r
1134 fileBuffer.append(" mDriverEntryPointStatus = Status;\r\n");\r
1135 fileBuffer.append(" }\r\n");\r
1136 fileBuffer.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");\r
1137 fileBuffer.append(" ASSERT (FALSE);\r\n");\r
1138 }\r
1139 fileBuffer.append("}\r\n\r\n");\r
878ddf1f 1140 }\r
878ddf1f 1141 }\r
ff225cbb 1142\r
8c8b94e2 1143 if (CommonDefinition.getModuleType(typeStr) == CommonDefinition.ModuleTypeUefiApplication) {\r
1144 break;\r
1145 }\r
5f907e4a 1146 //\r
1147 // Add ModuleUnloadImage for DxeDriver and UefiDriver module type.\r
1148 //\r
d8f1335e 1149 //entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();\r
1150 //\r
1151 // Remover duplicate unload entry point.\r
1152 //\r
1153 //entryPointList = CommonDefinition.remDupString(entryPointList);\r
1154 //entryPointCount = 0;\r
a387de3b 1155 unloadImageCount = 0;\r
cb4d97bd 1156 if (unloadImageList != null) {\r
1157 for (int i = 0; i < unloadImageList.length; i++) {\r
149127db 1158 functionDeclarations.append("EFI_STATUS\r\n");\r
1159 functionDeclarations.append("EFIAPI\r\n");\r
1160 functionDeclarations.append(unloadImageList[i]);\r
1161 functionDeclarations.append(" (\r\n");\r
1162 functionDeclarations.append(" IN EFI_HANDLE ImageHandle\r\n");\r
1163 functionDeclarations.append(" );\r\n");\r
cb4d97bd 1164 unloadImageCount++;\r
5f907e4a 1165 }\r
1166 }\r
1167\r
a387de3b 1168 fileBuffer.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");\r
cb4d97bd 1169 fileBuffer.append(Integer.toString(unloadImageCount));\r
aacce761 1170 fileBuffer.append(";\r\n\r\n");\r
5f907e4a 1171\r
aacce761 1172 fileBuffer.append("EFI_STATUS\r\n");\r
1173 fileBuffer.append("EFIAPI\r\n");\r
1174 fileBuffer.append("ProcessModuleUnloadList (\r\n");\r
1175 fileBuffer.append(" IN EFI_HANDLE ImageHandle\r\n");\r
1176 fileBuffer.append(" )\r\n");\r
1177 fileBuffer.append("{\r\n");\r
5f907e4a 1178\r
cb4d97bd 1179 if (unloadImageCount == 0) {\r
aacce761 1180 fileBuffer.append(" return EFI_SUCCESS;\r\n");\r
cb4d97bd 1181 } else if (unloadImageCount == 1) {\r
5f907e4a 1182 fileBuffer.append(" return ");\r
cb4d97bd 1183 fileBuffer.append(unloadImageList[0]);\r
aacce761 1184 fileBuffer.append("(ImageHandle);\r\n");\r
5f907e4a 1185 } else {\r
aacce761 1186 fileBuffer.append(" EFI_STATUS Status;\r\n\r\n");\r
1187 fileBuffer.append(" Status = EFI_SUCCESS;\r\n\r\n");\r
cb4d97bd 1188 for (int i = 0; i < unloadImageList.length; i++) {\r
25832ed3 1189 if (i == 0) {\r
1190 fileBuffer.append(" Status = ");\r
cb4d97bd 1191 fileBuffer.append(unloadImageList[i]);\r
aacce761 1192 fileBuffer.append("(ImageHandle);\r\n");\r
5f907e4a 1193 } else {\r
aacce761 1194 fileBuffer.append(" if (EFI_ERROR (Status)) {\r\n");\r
5f907e4a 1195 fileBuffer.append(" ");\r
cb4d97bd 1196 fileBuffer.append(unloadImageList[i]);\r
aacce761 1197 fileBuffer.append("(ImageHandle);\r\n");\r
1198 fileBuffer.append(" } else {\r\n");\r
5f907e4a 1199 fileBuffer.append(" Status = ");\r
cb4d97bd 1200 fileBuffer.append(unloadImageList[i]);\r
aacce761 1201 fileBuffer.append("(ImageHandle);\r\n");\r
1202 fileBuffer.append(" }\r\n");\r
25832ed3 1203 }\r
5f907e4a 1204 }\r
aacce761 1205 fileBuffer.append(" return Status;\r\n");\r
5f907e4a 1206 }\r
aacce761 1207 fileBuffer.append("}\r\n\r\n");\r
5f907e4a 1208 break;\r
1209 }\r
1210 }\r
1211\r
1212 /**\r
90a98f29 1213 CNameToAutogenc\r
cb4d97bd 1214 \r
90a98f29 1215 This function gets GUIDs from SPD file accrodeing to <Protocols> <Ppis> \r
1216 <Guids> information and write those GUIDs to AutoGen.c.\r
cb4d97bd 1217 \r
1218 @param fileBuffer\r
1219 String Buffer for Autogen.c file.\r
1220 \r
1221 **/\r
90a98f29 1222 void CNameToAutogenC(StringBuffer fileBuffer) throws AutoGenException {\r
5f907e4a 1223 String[] cNameGuid = null;\r
1224 String guidKeyWord = null;\r
1225\r
90a98f29 1226 String[] cnameList = saq.getCNameArray(this.arch);\r
1227 for (int i = 0; i < cnameList.length; i++) {\r
1228 this.mGuidCNameList.add(cnameList[i]);\r
5f907e4a 1229 }\r
1230\r
1231\r
90a98f29 1232 Iterator guidIterator = this.mGuidCNameList.iterator();\r
5f907e4a 1233 while (guidIterator.hasNext()) {\r
1234 guidKeyWord = guidIterator.next().toString();\r
1235 cNameGuid = GlobalData.getGuid(this.mDepPkgList, guidKeyWord);\r
90a98f29 1236 if (cNameGuid == null) {\r
1237 cNameGuid = GlobalData.getProtocolGuid(this.mDepPkgList, guidKeyWord);\r
1238 if (cNameGuid == null) {\r
1239 cNameGuid = GlobalData.getPpiGuid(this.mDepPkgList, guidKeyWord);\r
1240 if (cNameGuid == null) {\r
1241 //\r
1242 // If can't find GUID declaration in every package, stop the build\r
1243 //\r
1244 EdkLog.log(EdkLog.EDK_INFO,"WARN: Can not find Guid [" + guidKeyWord + "] declaration in any SPD file.");\r
1245 continue;\r
1246 //throw new AutoGenException("Can not find Guid [" + guidKeyWord\r
1247 // + "] declaration in any SPD package. ");\r
1248 }\r
1249 }\r
5f907e4a 1250 }\r
1251\r
90a98f29 1252 fileBuffer.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r
1253 fileBuffer.append(cNameGuid[0]);\r
1254 fileBuffer.append(" = { ");\r
1255 fileBuffer.append(CommonDefinition.formatGuidName(cNameGuid[1]));\r
1256 fileBuffer.append("} ;");\r
5f907e4a 1257 }\r
1258 }\r
1259\r
1260 /**\r
cb4d97bd 1261 LibInstanceToAutogenC\r
1262 \r
1263 This function adds dependent library instance to autogen.c,which\r
1264 includeing library's constructor, destructor, and library dependent ppi,\r
1265 protocol, guid, pcd information.\r
1266 \r
1267 @param fileBuffer\r
1268 String buffer for AutoGen.c\r
1269 @throws BuildException\r
1270 **/\r
61528a1b 1271 void LibInstanceToAutogenC(StringBuffer fileBuffer) throws EdkException {\r
a387de3b 1272 String moduleType = this.moduleId.getModuleType();\r
1273 //\r
1274 // Add library constructor to AutoGen.c\r
1275 //\r
700279a9 1276 LibConstructorToAutogenC(libConstructList, moduleType, fileBuffer);\r
a387de3b 1277 //\r
1278 // Add library destructor to AutoGen.c\r
1279 //\r
700279a9 1280 LibDestructorToAutogenC(libDestructList, moduleType, fileBuffer);\r
5f907e4a 1281 }\r
1282\r
f9081b64 1283 /**\r
1284 LibConstructorToAutogenH\r
1285 \r
1286 This function writes library constructor declarations AutoGen.h. The library\r
1287 constructor's parameter and return value depend on module type.\r
1288 \r
1289 @param libInstanceList\r
1290 List of library construct name.\r
1291 @param moduleType\r
1292 Module type.\r
1293 @param fileBuffer\r
1294 String buffer for AutoGen.c\r
1295 @throws Exception\r
1296 **/\r
aacce761 1297 void LibConstructorToAutogenH(String moduleType) throws EdkException {\r
f9081b64 1298 boolean isFirst = true;\r
1299\r
1300 //\r
1301 // If not yet parse this library instance's constructor\r
1302 // element,parse it.\r
1303 //\r
1304 String libConstructName = saq.getLibConstructorName();\r
1305 if (libConstructName == null) {\r
1306 return;\r
1307 }\r
1308\r
1309 //\r
1310 // The library constructor's parameter and return value depend on\r
1311 // module type.\r
1312 //\r
1313 if (moduleType.equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) {\r
aacce761 1314 functionDeclarations.append("RETURN_STATUS\r\n");\r
1315 functionDeclarations.append("EFIAPI\r\n");\r
1316 functionDeclarations.append(libConstructName);\r
1317 functionDeclarations.append(" (\r\n");\r
1318 functionDeclarations.append(" VOID\r\n");\r
1319 functionDeclarations.append(" );\r\n");\r
f9081b64 1320 } else {\r
1321 switch (CommonDefinition.getModuleType(moduleType)) {\r
1322 case CommonDefinition.ModuleTypeBase:\r
aacce761 1323 functionDeclarations.append("RETURN_STATUS\r\n");\r
1324 functionDeclarations.append("EFIAPI\r\n");\r
1325 functionDeclarations.append(libConstructName);\r
1326 functionDeclarations.append(" (\r\n");\r
1327 functionDeclarations.append(" VOID\r\n");\r
1328 functionDeclarations.append(" );\r\n");\r
f9081b64 1329 break;\r
1330\r
1331 case CommonDefinition.ModuleTypePeiCore:\r
1332 case CommonDefinition.ModuleTypePeim:\r
aacce761 1333 functionDeclarations.append("EFI_STATUS\r\n");\r
1334 functionDeclarations.append("EFIAPI\r\n");\r
1335 functionDeclarations.append(libConstructName);\r
1336 functionDeclarations.append(" (\r\n");\r
1337 functionDeclarations.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");\r
1338 functionDeclarations.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");\r
1339 functionDeclarations.append(" );\r\n");\r
f9081b64 1340 break;\r
1341\r
1342 case CommonDefinition.ModuleTypeDxeCore:\r
1343 case CommonDefinition.ModuleTypeDxeDriver:\r
1344 case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
1345 case CommonDefinition.ModuleTypeDxeSmmDriver:\r
1346 case CommonDefinition.ModuleTypeDxeSalDriver:\r
1347 case CommonDefinition.ModuleTypeUefiDriver:\r
1348 case CommonDefinition.ModuleTypeUefiApplication:\r
aacce761 1349 functionDeclarations.append("EFI_STATUS\r\n");\r
1350 functionDeclarations.append("EFIAPI\r\n");\r
1351 functionDeclarations.append(libConstructName);\r
1352 functionDeclarations.append(" (\r\n");\r
1353 functionDeclarations.append(" IN EFI_HANDLE ImageHandle,\r\n");\r
1354 functionDeclarations.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r
1355 functionDeclarations.append(" );\r\n");\r
f9081b64 1356 break;\r
1357\r
1358 }\r
1359 }\r
1360 }\r
1361\r
1362 /**\r
1363 LibDestructorToAutogenH\r
1364 \r
1365 This function writes library destructor declarations AutoGen.h. The library\r
1366 destructor's parameter and return value depend on module type.\r
1367 \r
1368 @param libInstanceList\r
1369 List of library destructor name.\r
1370 @param moduleType\r
1371 Module type.\r
1372 @param fileBuffer\r
1373 String buffer for AutoGen.c\r
1374 @throws Exception\r
1375 **/\r
aacce761 1376 void LibDestructorToAutogenH(String moduleType) throws EdkException {\r
f9081b64 1377 boolean isFirst = true;\r
1378 String libDestructName = saq.getLibDestructorName();\r
1379 if (libDestructName == null) {\r
1380 return;\r
1381 }\r
1382\r
1383 if (moduleType.equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) {\r
aacce761 1384 functionDeclarations.append("RETURN_STATUS\r\n");\r
1385 functionDeclarations.append("EFIAPI\r\n");\r
1386 functionDeclarations.append(libDestructName);\r
1387 functionDeclarations.append(" (\r\n");\r
1388 functionDeclarations.append(" VOID\r\n");\r
1389 functionDeclarations.append(" );\r\n");\r
f9081b64 1390 } else {\r
1391 switch (CommonDefinition.getModuleType(moduleType)) {\r
1392 case CommonDefinition.ModuleTypeBase:\r
aacce761 1393 functionDeclarations.append("RETURN_STATUS\r\n");\r
1394 functionDeclarations.append("EFIAPI\r\n");\r
1395 functionDeclarations.append(libDestructName);\r
1396 functionDeclarations.append(" (\r\n");\r
1397 functionDeclarations.append(" VOID\r\n");\r
1398 functionDeclarations.append(" );\r\n");\r
f9081b64 1399 break;\r
1400 case CommonDefinition.ModuleTypePeiCore:\r
1401 case CommonDefinition.ModuleTypePeim:\r
aacce761 1402 functionDeclarations.append("EFI_STATUS\r\n");\r
1403 functionDeclarations.append("EFIAPI\r\n");\r
1404 functionDeclarations.append(libDestructName);\r
1405 functionDeclarations.append(" (\r\n");\r
1406 functionDeclarations.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");\r
1407 functionDeclarations.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");\r
1408 functionDeclarations.append(" );\r\n");\r
f9081b64 1409 break;\r
1410 case CommonDefinition.ModuleTypeDxeCore:\r
1411 case CommonDefinition.ModuleTypeDxeDriver:\r
1412 case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
1413 case CommonDefinition.ModuleTypeDxeSmmDriver:\r
1414 case CommonDefinition.ModuleTypeDxeSalDriver:\r
1415 case CommonDefinition.ModuleTypeUefiDriver:\r
1416 case CommonDefinition.ModuleTypeUefiApplication:\r
aacce761 1417 functionDeclarations.append("EFI_STATUS\r\n");\r
1418 functionDeclarations.append("EFIAPI\r\n");\r
1419 functionDeclarations.append(libDestructName);\r
1420 functionDeclarations.append(" (\r\n");\r
1421 functionDeclarations.append(" IN EFI_HANDLE ImageHandle,\r\n");\r
1422 functionDeclarations.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r
1423 functionDeclarations.append(" );\r\n");\r
f9081b64 1424 break;\r
1425 }\r
1426 }\r
1427 }\r
1428\r
5f907e4a 1429 /**\r
cb4d97bd 1430 LibConstructorToAutogenc\r
1431 \r
1432 This function writes library constructor list to AutoGen.c. The library\r
1433 constructor's parameter and return value depend on module type.\r
1434 \r
1435 @param libInstanceList\r
1436 List of library construct name.\r
1437 @param moduleType\r
1438 Module type.\r
1439 @param fileBuffer\r
1440 String buffer for AutoGen.c\r
1441 @throws Exception\r
1442 **/\r
4353d8e1 1443 void LibConstructorToAutogenC(List<String[]> libInstanceList,\r
61528a1b 1444 String moduleType, StringBuffer fileBuffer) throws EdkException {\r
5f907e4a 1445 boolean isFirst = true;\r
1446\r
1447 //\r
1448 // The library constructor's parameter and return value depend on\r
1449 // module type.\r
1450 //\r
1451 for (int i = 0; i < libInstanceList.size(); i++) {\r
a387de3b 1452 if (libInstanceList.get(i)[1].equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) {\r
aacce761 1453 functionDeclarations.append("RETURN_STATUS\r\n");\r
1454 functionDeclarations.append("EFIAPI\r\n");\r
1455 functionDeclarations.append(libInstanceList.get(i)[0]);\r
1456 functionDeclarations.append(" (\r\n");\r
1457 functionDeclarations.append(" VOID\r\n");\r
1458 functionDeclarations.append(" );\r\n");\r
a387de3b 1459 } else {\r
1460 switch (CommonDefinition.getModuleType(moduleType)) {\r
4353d8e1 1461 case CommonDefinition.ModuleTypeBase:\r
aacce761 1462 functionDeclarations.append("RETURN_STATUS\r\n");\r
1463 functionDeclarations.append("EFIAPI\r\n");\r
1464 functionDeclarations.append(libInstanceList.get(i)[0]);\r
1465 functionDeclarations.append(" (\r\n");\r
1466 functionDeclarations.append(" VOID\r\n");\r
1467 functionDeclarations.append(" );\r\n");\r
4353d8e1 1468 break;\r
1469\r
1470 case CommonDefinition.ModuleTypePeiCore:\r
1471 case CommonDefinition.ModuleTypePeim:\r
aacce761 1472 functionDeclarations.append("EFI_STATUS\r\n");\r
1473 functionDeclarations.append("EFIAPI\r\n");\r
1474 functionDeclarations.append(libInstanceList.get(i)[0]);\r
1475 functionDeclarations.append(" (\r\n");\r
1476 functionDeclarations.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");\r
1477 functionDeclarations.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");\r
1478 functionDeclarations.append(" );\r\n");\r
a387de3b 1479 break;\r
1480\r
1481 case CommonDefinition.ModuleTypeDxeCore:\r
1482 case CommonDefinition.ModuleTypeDxeDriver:\r
1483 case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
1484 case CommonDefinition.ModuleTypeDxeSmmDriver:\r
1485 case CommonDefinition.ModuleTypeDxeSalDriver:\r
1486 case CommonDefinition.ModuleTypeUefiDriver:\r
1487 case CommonDefinition.ModuleTypeUefiApplication:\r
aacce761 1488 functionDeclarations.append("EFI_STATUS\r\n");\r
1489 functionDeclarations.append("EFIAPI\r\n");\r
1490 functionDeclarations.append(libInstanceList.get(i)[0]);\r
1491 functionDeclarations.append(" (\r\n");\r
1492 functionDeclarations.append(" IN EFI_HANDLE ImageHandle,\r\n");\r
1493 functionDeclarations.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r
1494 functionDeclarations.append(" );\r\n");\r
a387de3b 1495 break;\r
1496\r
1497 }\r
5f907e4a 1498 }\r
1499 }\r
1500\r
1501 //\r
1502 // Add ProcessLibraryConstructorList in AutoGen.c\r
1503 //\r
aacce761 1504 fileBuffer.append("VOID\r\n");\r
1505 fileBuffer.append("EFIAPI\r\n");\r
1506 fileBuffer.append("ProcessLibraryConstructorList (\r\n");\r
5f907e4a 1507 switch (CommonDefinition.getModuleType(moduleType)) {\r
1508 case CommonDefinition.ModuleTypeBase:\r
aacce761 1509 fileBuffer.append(" VOID\r\n");\r
5f907e4a 1510 break;\r
1511\r
1512 case CommonDefinition.ModuleTypePeiCore:\r
1513 case CommonDefinition.ModuleTypePeim:\r
aacce761 1514 fileBuffer.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");\r
a30ae9fa 1515 fileBuffer.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");\r
5f907e4a 1516 break;\r
1517\r
1518 case CommonDefinition.ModuleTypeDxeCore:\r
1519 case CommonDefinition.ModuleTypeDxeDriver:\r
1520 case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
1521 case CommonDefinition.ModuleTypeDxeSmmDriver:\r
1522 case CommonDefinition.ModuleTypeDxeSalDriver:\r
1523 case CommonDefinition.ModuleTypeUefiDriver:\r
1524 case CommonDefinition.ModuleTypeUefiApplication:\r
aacce761 1525 fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");\r
1526 fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r
5f907e4a 1527 break;\r
1528 }\r
1529\r
aacce761 1530 fileBuffer.append(" )\r\n");\r
1531 fileBuffer.append("{\r\n");\r
136adffc 1532 //\r
1533 // If no constructor function, return EFI_SUCCESS.\r
1534 //\r
5f907e4a 1535 for (int i = 0; i < libInstanceList.size(); i++) {\r
1536 if (isFirst) {\r
aacce761 1537 fileBuffer.append(" EFI_STATUS Status;\r\n");\r
1538 fileBuffer.append(" Status = EFI_SUCCESS;\r\n");\r
1539 fileBuffer.append("\r\n");\r
5f907e4a 1540 isFirst = false;\r
1541 }\r
a387de3b 1542 if (libInstanceList.get(i)[1].equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) {\r
5f907e4a 1543 fileBuffer.append(" Status = ");\r
4353d8e1 1544 fileBuffer.append(libInstanceList.get(i)[0]);\r
aacce761 1545 fileBuffer.append("();\r\n");\r
a387de3b 1546 } else {\r
1547 switch (CommonDefinition.getModuleType(moduleType)) {\r
1548 case CommonDefinition.ModuleTypeBase:\r
1549 fileBuffer.append(" Status = ");\r
1550 fileBuffer.append(libInstanceList.get(i)[0]);\r
aacce761 1551 fileBuffer.append("();\r\n");\r
a387de3b 1552 break;\r
1553 case CommonDefinition.ModuleTypePeiCore:\r
1554 case CommonDefinition.ModuleTypePeim:\r
1555 fileBuffer.append(" Status = ");\r
1556 fileBuffer.append(libInstanceList.get(i)[0]);\r
aacce761 1557 fileBuffer.append(" (FfsHeader, PeiServices);\r\n");\r
a387de3b 1558 break;\r
1559 case CommonDefinition.ModuleTypeDxeCore:\r
1560 case CommonDefinition.ModuleTypeDxeDriver:\r
1561 case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
1562 case CommonDefinition.ModuleTypeDxeSmmDriver:\r
1563 case CommonDefinition.ModuleTypeDxeSalDriver:\r
1564 case CommonDefinition.ModuleTypeUefiDriver:\r
1565 case CommonDefinition.ModuleTypeUefiApplication:\r
1566 fileBuffer.append(" Status = ");\r
1567 fileBuffer.append(libInstanceList.get(i)[0]);\r
aacce761 1568 fileBuffer.append(" (ImageHandle, SystemTable);\r\n");\r
a387de3b 1569 break;\r
1570 default:\r
1571 EdkLog.log(EdkLog.EDK_INFO,"Autogen doesn't know how to deal with module type - " + moduleType + "!");\r
1572 }\r
1573\r
5f907e4a 1574 }\r
aacce761 1575 fileBuffer.append(" ASSERT_EFI_ERROR (Status);\r\n");\r
5f907e4a 1576 }\r
aacce761 1577 fileBuffer.append("}\r\n");\r
5f907e4a 1578 }\r
1579\r
1580 /**\r
cb4d97bd 1581 LibDestructorToAutogenc\r
1582 \r
1583 This function writes library destructor list to AutoGen.c. The library\r
1584 destructor's parameter and return value depend on module type.\r
1585 \r
1586 @param libInstanceList\r
1587 List of library destructor name.\r
1588 @param moduleType\r
1589 Module type.\r
1590 @param fileBuffer\r
1591 String buffer for AutoGen.c\r
1592 @throws Exception\r
1593 **/\r
4353d8e1 1594 void LibDestructorToAutogenC(List<String[]> libInstanceList,\r
61528a1b 1595 String moduleType, StringBuffer fileBuffer) throws EdkException {\r
5f907e4a 1596 boolean isFirst = true;\r
1597 for (int i = 0; i < libInstanceList.size(); i++) {\r
a387de3b 1598 if (libInstanceList.get(i)[1].equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) {\r
aacce761 1599 functionDeclarations.append("RETURN_STATUS\r\n");\r
1600 functionDeclarations.append("EFIAPI\r\n");\r
1601 functionDeclarations.append(libInstanceList.get(i)[0]);\r
1602 functionDeclarations.append(" (\r\n");\r
1603 functionDeclarations.append(" VOID\r\n");\r
1604 functionDeclarations.append(" );\r\n");\r
a387de3b 1605 } else {\r
1606 switch (CommonDefinition.getModuleType(moduleType)) {\r
1607 case CommonDefinition.ModuleTypeBase:\r
aacce761 1608 functionDeclarations.append("RETURN_STATUS\r\n");\r
1609 functionDeclarations.append("EFIAPI\r\n");\r
1610 functionDeclarations.append(libInstanceList.get(i)[0]);\r
1611 functionDeclarations.append(" (\r\n");\r
1612 functionDeclarations.append(" VOID\r\n");\r
1613 functionDeclarations.append(" );\r\n");\r
a387de3b 1614 break;\r
1615 case CommonDefinition.ModuleTypePeiCore:\r
1616 case CommonDefinition.ModuleTypePeim:\r
aacce761 1617 functionDeclarations.append("EFI_STATUS\r\n");\r
1618 functionDeclarations.append("EFIAPI\r\n");\r
1619 functionDeclarations.append(libInstanceList.get(i)[0]);\r
1620 functionDeclarations.append(" (\r\n");\r
1621 functionDeclarations.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");\r
1622 functionDeclarations.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");\r
1623 functionDeclarations.append(" );\r\n");\r
a387de3b 1624 break;\r
1625 case CommonDefinition.ModuleTypeDxeCore:\r
1626 case CommonDefinition.ModuleTypeDxeDriver:\r
1627 case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
1628 case CommonDefinition.ModuleTypeDxeSmmDriver:\r
1629 case CommonDefinition.ModuleTypeDxeSalDriver:\r
1630 case CommonDefinition.ModuleTypeUefiDriver:\r
1631 case CommonDefinition.ModuleTypeUefiApplication:\r
aacce761 1632 functionDeclarations.append("EFI_STATUS\r\n");\r
1633 functionDeclarations.append("EFIAPI\r\n");\r
1634 functionDeclarations.append(libInstanceList.get(i)[0]);\r
1635 functionDeclarations.append(" (\r\n");\r
1636 functionDeclarations.append(" IN EFI_HANDLE ImageHandle,\r\n");\r
1637 functionDeclarations.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r
1638 functionDeclarations.append(" );\r\n");\r
a387de3b 1639 break;\r
1640 }\r
5f907e4a 1641 }\r
1642 }\r
1643\r
1644 //\r
1645 // Write ProcessLibraryDestructor list to autogen.c\r
1646 //\r
1647 switch (CommonDefinition.getModuleType(moduleType)) {\r
1648 case CommonDefinition.ModuleTypeBase:\r
1649 case CommonDefinition.ModuleTypePeiCore:\r
1650 case CommonDefinition.ModuleTypePeim:\r
1651 break;\r
1652 case CommonDefinition.ModuleTypeDxeCore:\r
1653 case CommonDefinition.ModuleTypeDxeDriver:\r
1654 case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
1655 case CommonDefinition.ModuleTypeDxeSmmDriver:\r
1656 case CommonDefinition.ModuleTypeDxeSalDriver:\r
1657 case CommonDefinition.ModuleTypeUefiDriver:\r
1658 case CommonDefinition.ModuleTypeUefiApplication:\r
aacce761 1659 fileBuffer.append("VOID\r\n");\r
1660 fileBuffer.append("EFIAPI\r\n");\r
1661 fileBuffer.append("ProcessLibraryDestructorList (\r\n");\r
1662 fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");\r
1663 fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r
1664 fileBuffer.append(" )\r\n");\r
1665 fileBuffer.append("{\r\n");\r
878ddf1f 1666 //\r
136adffc 1667 // If no library destructor function, return EFI_SUCCESS.\r
878ddf1f 1668 //\r
ff225cbb 1669\r
5f907e4a 1670 for (int i = 0; i < libInstanceList.size(); i++) {\r
1671 if (isFirst) {\r
aacce761 1672 fileBuffer.append(" EFI_STATUS Status;\r\n");\r
1673 fileBuffer.append(" Status = EFI_SUCCESS;\r\n");\r
1674 fileBuffer.append("\r\n");\r
5f907e4a 1675 isFirst = false;\r
1676 }\r
a387de3b 1677 if (libInstanceList.get(i)[1].equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) {\r
4353d8e1 1678 fileBuffer.append(" Status = ");\r
1679 fileBuffer.append(libInstanceList.get(i)[0]);\r
aacce761 1680 fileBuffer.append("();\r\n");\r
1681 fileBuffer.append(" VOID\r\n");\r
a387de3b 1682 } else {\r
1683 fileBuffer.append(" Status = ");\r
1684 fileBuffer.append(libInstanceList.get(i)[0]);\r
aacce761 1685 fileBuffer.append("(ImageHandle, SystemTable);\r\n");\r
1686 fileBuffer.append(" ASSERT_EFI_ERROR (Status);\r\n");\r
a387de3b 1687 }\r
5f907e4a 1688 }\r
aacce761 1689 fileBuffer.append("}\r\n");\r
5f907e4a 1690 break;\r
1691 }\r
1692 }\r
1693\r
1694 /**\r
cb4d97bd 1695 ExternsDriverBindingToAutoGenC\r
1696 \r
1697 This function is to write DRIVER_BINDING, COMPONENT_NAME,\r
1698 DRIVER_CONFIGURATION, DRIVER_DIAGNOSTIC in AutoGen.c.\r
1699 \r
1700 @param fileBuffer\r
1701 String buffer for AutoGen.c\r
1702 **/\r
5f907e4a 1703 void ExternsDriverBindingToAutoGenC(StringBuffer fileBuffer)\r
61528a1b 1704 throws EdkException {\r
5f907e4a 1705 //\r
d8f1335e 1706 // Get the arry of extern. The driverBindingGroup is a 2 dimension array.\r
e425f073 1707 // The second dimension is include following element: DriverBinding, \r
1708 // ComponentName, DriverConfiguration, DriverDiag;\r
1709 // \r
d8f1335e 1710 String[][] driverBindingGroup = this.saq.getExternProtocolGroup();\r
5f907e4a 1711\r
e87022aa 1712\r
a387de3b 1713 //\r
1714 // inital BitMask;\r
1715 // \r
1716 int BitMask = 0;\r
5f907e4a 1717\r
1718 //\r
1719 // Write driver binding protocol extern to autogen.c\r
1720 //\r
d8f1335e 1721 for (int i = 0; i < driverBindingGroup.length; i++) {\r
e425f073 1722 if (driverBindingGroup[i][0] != null) {\r
2c9b03f2 1723 globalDeclarations.append("extern EFI_DRIVER_BINDING_PROTOCOL ");\r
1724 globalDeclarations.append(driverBindingGroup[i][0]);\r
1725 globalDeclarations.append(";\r\n");\r
a387de3b 1726 }\r
5f907e4a 1727 }\r
1728\r
1729 //\r
1730 // Write component name protocol extern to autogen.c\r
1731 //\r
e425f073 1732 if (!componentNamePcd) {\r
1733 for (int i = 0; i < driverBindingGroup.length; i++) {\r
1734 if (driverBindingGroup[i][1]!= null) {\r
1735 if (driverBindingGroup[i][0] != null) {\r
1736 BitMask |= 0x01;\r
2c9b03f2 1737 globalDeclarations.append("extern EFI_COMPONENT_NAME_PROTOCOL ");\r
1738 globalDeclarations.append(driverBindingGroup[i][1]);\r
1739 globalDeclarations.append(";\r\n");\r
e425f073 1740 } else {\r
e87022aa 1741 throw new AutoGenException("DriverBinding can't be empty!!");\r
e425f073 1742 }\r
a387de3b 1743 }\r
1744 }\r
1745 }\r
1746\r
5f907e4a 1747 //\r
1748 // Write driver configration protocol extern to autogen.c\r
1749 //\r
e425f073 1750 for (int i = 0; i < driverBindingGroup.length; i++) {\r
1751 if (driverBindingGroup[i][2] != null) {\r
1752 if (driverBindingGroup[i][0] != null) {\r
d8f1335e 1753 BitMask |= 0x02;\r
2c9b03f2 1754 globalDeclarations.append("extern EFI_DRIVER_CONFIGURATION_PROTOCOL ");\r
1755 globalDeclarations.append(driverBindingGroup[i][2]);\r
1756 globalDeclarations.append(";\r\n");\r
e425f073 1757 } else {\r
d8f1335e 1758 throw new AutoGenException("DriverBinding can't be empty!!");\r
e425f073 1759 }\r
1760 }\r
1761 }\r
a387de3b 1762\r
5f907e4a 1763 //\r
1764 // Write driver dignastic protocol extern to autogen.c\r
1765 //\r
e425f073 1766 if (!driverDiagnostPcd) {\r
1767 for (int i = 0; i < driverBindingGroup.length; i++) {\r
1768 if (driverBindingGroup[i][3] != null) {\r
1769 if (driverBindingGroup[i][0] != null) {\r
e87022aa 1770 BitMask |= 0x04;\r
2c9b03f2 1771 globalDeclarations.append("extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL ");\r
1772 globalDeclarations.append(driverBindingGroup[i][3]);\r
1773 globalDeclarations.append(";\r\n");\r
e425f073 1774 } else {\r
e87022aa 1775 throw new AutoGenException("DriverBinding can't be empty!!");\r
e425f073 1776 }\r
1777 }\r
1778 }\r
1779 }\r
a387de3b 1780\r
1781\r
5f907e4a 1782 //\r
1783 // Write driver module protocol bitmask.\r
1784 //\r
a387de3b 1785 fileBuffer.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverModelProtocolBitmask = ");\r
5f907e4a 1786 fileBuffer.append(Integer.toString(BitMask));\r
aacce761 1787 fileBuffer.append(";\r\n");\r
5f907e4a 1788\r
1789 //\r
1790 // Write driver module protocol list entry\r
1791 //\r
a387de3b 1792 fileBuffer.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverModelProtocolListEntries = ");\r
5f907e4a 1793\r
d8f1335e 1794 fileBuffer.append(Integer.toString(driverBindingGroup.length));\r
aacce761 1795 fileBuffer.append(";\r\n");\r
5f907e4a 1796\r
1797 //\r
1798 // Write drive module protocol list to autogen.c\r
1799 //\r
e425f073 1800 if (driverBindingGroup.length > 0) {\r
a387de3b 1801 fileBuffer.append("GLOBAL_REMOVE_IF_UNREFERENCED const EFI_DRIVER_MODEL_PROTOCOL_LIST _gDriverModelProtocolList[] = {");\r
1802 }\r
1803\r
1804\r
d8f1335e 1805 for (int i = 0; i < driverBindingGroup.length; i++) {\r
5f907e4a 1806 if (i != 0) {\r
1807 fileBuffer.append(",");\r
1808 }\r
e425f073 1809 //\r
1810 // DriverBinding\r
1811 // \r
aacce761 1812 fileBuffer.append("\r\n {\r\n");\r
5f907e4a 1813 fileBuffer.append(" &");\r
d8f1335e 1814 fileBuffer.append(driverBindingGroup[i][0]);\r
aacce761 1815 fileBuffer.append(", \r\n");\r
a387de3b 1816\r
e87022aa 1817 //\r
e425f073 1818 // ComponentName\r
1819 // \r
1820 if (driverBindingGroup[i][1] != null && componentNamePcd != true) {\r
5f907e4a 1821 fileBuffer.append(" &");\r
d8f1335e 1822 fileBuffer.append(driverBindingGroup[i][1]);\r
aacce761 1823 fileBuffer.append(", \r\n");\r
5f907e4a 1824 } else {\r
aacce761 1825 fileBuffer.append(" NULL, \r\n");\r
5f907e4a 1826 }\r
1827\r
e425f073 1828 //\r
1829 // DriverConfiguration\r
1830 // \r
d8f1335e 1831 if (driverBindingGroup[i][2] != null) {\r
5f907e4a 1832 fileBuffer.append(" &");\r
d8f1335e 1833 fileBuffer.append(driverBindingGroup[i][2]);\r
aacce761 1834 fileBuffer.append(", \r\n");\r
5f907e4a 1835 } else {\r
aacce761 1836 fileBuffer.append(" NULL, \r\n");\r
5f907e4a 1837 }\r
1838\r
e425f073 1839 //\r
1840 // DriverDiagnostic\r
1841 // \r
1842 if (driverBindingGroup[i][3] != null && driverDiagnostPcd != true) {\r
5f907e4a 1843 fileBuffer.append(" &");\r
d8f1335e 1844 fileBuffer.append(driverBindingGroup[i][3]);\r
aacce761 1845 fileBuffer.append(", \r\n");\r
5f907e4a 1846 } else {\r
aacce761 1847 fileBuffer.append(" NULL, \r\n");\r
5f907e4a 1848 }\r
1849 fileBuffer.append(" }");\r
1850 }\r
d8f1335e 1851\r
e425f073 1852 if (driverBindingGroup.length > 0) {\r
aacce761 1853 fileBuffer.append("\r\n};\r\n");\r
1854 }\r
1855 }\r
1856\r
1857 /**\r
1858 ExternCallBackToAutoGenC\r
1859 \r
1860 This function adds <SetVirtualAddressMapCallBack> and\r
1861 <ExitBootServicesCallBack> infomation to AutoGen.c\r
1862 \r
1863 @param fileBuffer\r
1864 String buffer for AutoGen.c\r
1865 @throws BuildException\r
1866 **/\r
1867 void ExternCallBackToAutoGenH(String moduleType)\r
1868 throws EdkException {\r
1869 //\r
1870 // Collect module's <SetVirtualAddressMapCallBack> and\r
1871 // <ExitBootServiceCallBack> and add to setVirtualAddList\r
1872 // exitBootServiceList.\r
1873 //\r
1874 String[] setVirtuals = saq.getSetVirtualAddressMapCallBackArray();\r
1875 String[] exitBoots = saq.getExitBootServicesCallBackArray();\r
1876 //\r
1877 // Add c code in autogen.c which relate to <SetVirtualAddressMapCallBack>\r
1878 // and <ExitBootServicesCallBack>\r
1879 //\r
1880 switch (CommonDefinition.getModuleType(moduleType)) {\r
1881 case CommonDefinition.ModuleTypeDxeDriver:\r
1882 case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
1883 case CommonDefinition.ModuleTypeDxeSalDriver:\r
1884 case CommonDefinition.ModuleTypeUefiDriver:\r
1885 case CommonDefinition.ModuleTypeUefiApplication:\r
1886 //\r
1887 // Write SetVirtualAddressMap function definition.\r
1888 //\r
1889 for (int i = 0; setVirtuals != null && i < setVirtuals.length; i++) {\r
1890 if (setVirtuals[i].equalsIgnoreCase("")) {\r
1891 continue;\r
1892 }\r
1893 functionDeclarations.append("VOID\r\n");\r
1894 functionDeclarations.append("EFIAPI\r\n");\r
1895 functionDeclarations.append(setVirtuals[i]);\r
1896 functionDeclarations.append(" (\r\n");\r
1897 functionDeclarations.append(" IN EFI_EVENT Event,\r\n");\r
1898 functionDeclarations.append(" IN VOID *Context\r\n");\r
1899 functionDeclarations.append(" );\r\n\r\n");\r
1900 }\r
1901\r
1902 //\r
1903 // Write DriverExitBootServices function definition.\r
1904 //\r
1905 for (int i = 0; exitBoots != null && i < exitBoots.length; i++) {\r
1906 if (exitBoots[i].equalsIgnoreCase("")) {\r
1907 continue;\r
1908 }\r
1909\r
1910 functionDeclarations.append("VOID\r\n");\r
1911 functionDeclarations.append("EFIAPI\r\n");\r
1912 functionDeclarations.append(exitBoots[i]);\r
1913 functionDeclarations.append(" (\r\n");\r
1914 functionDeclarations.append(" IN EFI_EVENT Event,\r\n");\r
1915 functionDeclarations.append(" IN VOID *Context\r\n");\r
1916 functionDeclarations.append(" );\r\n\r\n");\r
1917 }\r
1918 break;\r
1919 default:\r
1920 break;\r
e425f073 1921 }\r
5f907e4a 1922 }\r
1923\r
1924 /**\r
cb4d97bd 1925 ExternCallBackToAutoGenC\r
1926 \r
1927 This function adds <SetVirtualAddressMapCallBack> and\r
1928 <ExitBootServicesCallBack> infomation to AutoGen.c\r
1929 \r
1930 @param fileBuffer\r
1931 String buffer for AutoGen.c\r
1932 @throws BuildException\r
1933 **/\r
5f907e4a 1934 void ExternCallBackToAutoGenC(StringBuffer fileBuffer)\r
61528a1b 1935 throws EdkException {\r
5f907e4a 1936 //\r
1937 // Collect module's <SetVirtualAddressMapCallBack> and\r
1938 // <ExitBootServiceCallBack> and add to setVirtualAddList\r
1939 // exitBootServiceList.\r
1940 //\r
83fba802 1941 String[] setVirtuals = saq.getSetVirtualAddressMapCallBackArray();\r
1942 String[] exitBoots = saq.getExitBootServicesCallBackArray();\r
a2733a33 1943 if (setVirtuals != null) {\r
1944 for (int j = 0; j < setVirtuals.length; j++) {\r
5f907e4a 1945 this.setVirtalAddList.add(setVirtuals[j]);\r
1946 }\r
1947 }\r
1948 if (exitBoots != null) {\r
1949 for (int k = 0; k < exitBoots.length; k++) {\r
1950 this.exitBootServiceList.add(exitBoots[k]);\r
1951 }\r
1952 }\r
1953 //\r
1954 // Add c code in autogen.c which relate to <SetVirtualAddressMapCallBack>\r
1955 // and <ExitBootServicesCallBack>\r
1956 //\r
1957 String moduleType = this.moduleId.getModuleType();\r
5f907e4a 1958 switch (CommonDefinition.getModuleType(moduleType)) {\r
1959 case CommonDefinition.ModuleTypeDxeDriver:\r
1960 case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
1961 case CommonDefinition.ModuleTypeDxeSalDriver:\r
1962 case CommonDefinition.ModuleTypeUefiDriver:\r
18f95092 1963 case CommonDefinition.ModuleTypeUefiApplication:\r
e425f073 1964 //\r
1965 // If moduleType is one of above, call setVirtualAddressToAutogenC,\r
1966 // and setExitBootServiceToAutogenC.\r
1967 // \r
c60019f6 1968 setVirtualAddressToAutogenC(fileBuffer);\r
e425f073 1969 setExitBootServiceToAutogenC(fileBuffer);\r
5f907e4a 1970 break;\r
1971 default:\r
1972 break;\r
1973 }\r
5f907e4a 1974 }\r
878ddf1f 1975\r
cb4d97bd 1976 /**\r
1977 copyFlashMapHToDebugDir\r
1978 \r
1979 This function is to copy the falshmap.h to debug directory and change \r
1980 its name to TianoR8FlashMap.h\r
1981 \r
1982 @param \r
1983 @return\r
1984 **/\r
73b4e31a 1985 private void copyFlashMapHToDebugDir() throws AutoGenException{\r
ff225cbb 1986\r
cb4d97bd 1987 File inFile = new File(fvDir + File.separatorChar + CommonDefinition.FLASHMAPH);\r
73b4e31a 1988 int size = (int)inFile.length();\r
1989 byte[] buffer = new byte[size];\r
cb4d97bd 1990 File outFile = new File (this.outputPath + File.separatorChar + CommonDefinition.TIANOR8PLASHMAPH);\r
5f907e4a 1991 //\r
1992 // If TianoR8FlashMap.h existed and the flashMap.h don't change,\r
1993 // do nothing.\r
1994 //\r
31a9215c 1995 if ((!outFile.exists()) ||(inFile.lastModified() - outFile.lastModified()) >= 0) {\r
e425f073 1996 if (inFile.exists()) {\r
a387de3b 1997 try {\r
e425f073 1998 FileInputStream fis = new FileInputStream (inFile);\r
1999 fis.read(buffer);\r
2000 FileOutputStream fos = new FileOutputStream(outFile);\r
2001 fos.write(buffer);\r
2002 fis.close();\r
2003 fos.close();\r
a387de3b 2004 } catch (IOException e) {\r
61528a1b 2005 throw new AutoGenException("The file, flashMap.h can't be open!");\r
e425f073 2006 }\r
a387de3b 2007\r
e425f073 2008 } else {\r
2009 throw new AutoGenException("The file, flashMap.h doesn't exist!");\r
2010 }\r
5f907e4a 2011 }\r
73b4e31a 2012 }\r
ff225cbb 2013\r
2336382f 2014 /**\r
cb4d97bd 2015 This function first order the library instances, then collect\r
2016 library instance 's PPI, Protocol, GUID,\r
2017 SetVirtalAddressMapCallBack, ExitBootServiceCallBack, and\r
2018 Destructor, Constructor.\r
2019 \r
2020 @param\r
2021 @return \r
5f907e4a 2022 **/\r
892b0e7a 2023 private void collectLibInstanceInfo() throws EdkException{\r
5f907e4a 2024 int index;\r
2025\r
700279a9 2026 String moduleType = moduleId.getModuleType();\r
5f907e4a 2027 String libConstructName = null;\r
2028 String libDestructName = null;\r
a387de3b 2029 String libModuleType = null;\r
5f907e4a 2030 String[] setVirtuals = null;\r
2031 String[] exitBoots = null;\r
2032\r
83fba802 2033 ModuleIdentification[] libraryIdList = saq.getLibraryInstance(this.arch);\r
700279a9 2034 if (libraryIdList.length <= 0) {\r
2035 return;\r
2036 }\r
2037 //\r
2038 // Reorder library instance sequence.\r
2039 //\r
2040 AutogenLibOrder libOrder = new AutogenLibOrder(libraryIdList, this.arch);\r
2041 List<ModuleIdentification> orderList = libOrder.orderLibInstance();\r
2042 //\r
2043 // Process library instance one by one.\r
2044 //\r
2045 for (int i = 0; i < orderList.size(); i++) {\r
2046 //\r
2047 // Get library instance basename.\r
2048 //\r
2049 ModuleIdentification libInstanceId = orderList.get(i);\r
5f907e4a 2050\r
a387de3b 2051 //\r
700279a9 2052 // Get override map\r
a387de3b 2053 //\r
a387de3b 2054\r
700279a9 2055 Map<String, XmlObject> libDoc = GlobalData.getDoc(libInstanceId, this.arch);\r
2056 saq.push(libDoc);\r
2057 //\r
2058 // check if the library instance support current module\r
2059 // \r
2060 String[] libraryClassList = saq.getLibraryClasses(CommonDefinition.ALWAYSPRODUCED,\r
2061 this.arch,\r
2062 moduleType\r
2063 );\r
2064 if (libraryClassList.length <= 0) {\r
2065 throw new EdkException("Library instance " + libInstanceId.getName() \r
2066 + " doesn't support module type " + moduleType);\r
2067 }\r
2068 //\r
90a98f29 2069 // Get CName list from <PPis>, <Protocols>, <Guids>, etc. of this library\r
700279a9 2070 // instance.\r
2071 //\r
90a98f29 2072 String[] guidCNameList = saq.getCNameArray(this.arch); \r
700279a9 2073 PackageIdentification[] pkgList = saq.getDependencePkg(this.arch);\r
a387de3b 2074\r
700279a9 2075 //\r
2076 // Add those ppi, protocol, guid in global ppi,\r
2077 // protocol, guid\r
2078 // list.\r
2079 //\r
90a98f29 2080 for (index = 0; index < guidCNameList.length; index++) {\r
2081 this.mGuidCNameList.add(guidCNameList[index]);\r
700279a9 2082 }\r
a387de3b 2083\r
700279a9 2084 for (index = 0; index < pkgList.length; index++) {\r
2085 if (!this.mDepPkgList.contains(pkgList[index])) {\r
2086 this.mDepPkgList.add(pkgList[index]);\r
2087 }\r
2088 }\r
2089\r
2090 //\r
2091 // If not yet parse this library instance's constructor\r
2092 // element,parse it.\r
2093 //\r
2094 libConstructName = saq.getLibConstructorName();\r
2095 libDestructName = saq.getLibDestructorName();\r
2096 libModuleType = saq.getModuleType();\r
2097\r
2098 //\r
2099 // Collect SetVirtualAddressMapCallBack and\r
2100 // ExitBootServiceCallBack.\r
2101 //\r
2102 setVirtuals = saq.getSetVirtualAddressMapCallBackArray();\r
2103 exitBoots = saq.getExitBootServicesCallBackArray();\r
2104 if (setVirtuals != null) {\r
2105 for (int j = 0; j < setVirtuals.length; j++) {\r
2106 this.setVirtalAddList.add(setVirtuals[j]);\r
2107 }\r
2108 }\r
2109 if (exitBoots != null) {\r
2110 for (int k = 0; k < exitBoots.length; k++) {\r
2111 this.exitBootServiceList.add(exitBoots[k]);\r
a387de3b 2112 }\r
2113 }\r
700279a9 2114 saq.pop();\r
2115 //\r
2116 // Add dependent library instance constructor function.\r
2117 //\r
2118 if (libConstructName != null) {\r
2119 this.libConstructList.add(new String[] {libConstructName, libModuleType});\r
2120 }\r
2121 //\r
2122 // Add dependent library instance destructor fuction.\r
2123 //\r
2124 if (libDestructName != null) {\r
2125 this.libDestructList.add(new String[] {libDestructName, libModuleType});\r
2126 }\r
a387de3b 2127 }\r
5f907e4a 2128 }\r
aacce761 2129\r
e425f073 2130 private void setVirtualAddressToAutogenC(StringBuffer fileBuffer){\r
c60019f6 2131 //\r
2132 // Entry point lib for these module types needs to know the count\r
2133 // of entryPoint.\r
2134 //\r
aacce761 2135 fileBuffer.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverSetVirtualAddressMapEventCount = ");\r
a387de3b 2136\r
2137 //\r
2138 // If the list is not valid or has no entries set count to zero else\r
2139 // set count to the number of valid entries\r
2140 //\r
2141 int Count = 0;\r
2142 int i = 0;\r
2143 if (this.setVirtalAddList != null) {\r
2144 for (i = 0; i < this.setVirtalAddList.size(); i++) {\r
2145 if (this.setVirtalAddList.get(i).equalsIgnoreCase("")) {\r
2146 break;\r
2147 }\r
2148 }\r
2149 Count = i;\r
2150 }\r
2151\r
2152 fileBuffer.append(Integer.toString(Count));\r
aacce761 2153 fileBuffer.append(";\r\n\r\n");\r
a387de3b 2154 if (this.setVirtalAddList == null || this.setVirtalAddList.size() == 0) {\r
2155 //\r
2156 // No data so make a NULL list\r
2157 //\r
aacce761 2158 fileBuffer.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {\r\n");\r
2159 fileBuffer.append(" NULL\r\n");\r
2160 fileBuffer.append("};\r\n\r\n");\r
a387de3b 2161 } else {\r
2162 //\r
2163 // Write SetVirtualAddressMap function definition.\r
2164 //\r
2165 for (i = 0; i < this.setVirtalAddList.size(); i++) {\r
2166 if (this.setVirtalAddList.get(i).equalsIgnoreCase("")) {\r
2167 break;\r
2168 }\r
aacce761 2169 functionDeclarations.append("VOID\r\n");\r
2170 functionDeclarations.append("EFIAPI\r\n");\r
2171 functionDeclarations.append(this.setVirtalAddList.get(i));\r
2172 functionDeclarations.append(" (\r\n");\r
2173 functionDeclarations.append(" IN EFI_EVENT Event,\r\n");\r
2174 functionDeclarations.append(" IN VOID *Context\r\n");\r
2175 functionDeclarations.append(" );\r\n\r\n");\r
a387de3b 2176 }\r
2177\r
2178 //\r
2179 // Write SetVirtualAddressMap entry point array.\r
2180 //\r
aacce761 2181 fileBuffer.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {");\r
a387de3b 2182 for (i = 0; i < this.setVirtalAddList.size(); i++) {\r
2183 if (this.setVirtalAddList.get(i).equalsIgnoreCase("")) {\r
2184 break;\r
2185 }\r
2186\r
2187 if (i == 0) {\r
aacce761 2188 fileBuffer.append("\r\n ");\r
a387de3b 2189 } else {\r
aacce761 2190 fileBuffer.append(",\r\n ");\r
a387de3b 2191 }\r
2192\r
2193 fileBuffer.append(this.setVirtalAddList.get(i));\r
2194 }\r
2195 //\r
2196 // add the NULL at the end of _gDriverSetVirtualAddressMapEvent list.\r
2197 //\r
aacce761 2198 fileBuffer.append(",\r\n NULL");\r
2199 fileBuffer.append("\r\n};\r\n\r\n");\r
a387de3b 2200 }\r
2201 }\r
2202\r
2203\r
2204 private void setExitBootServiceToAutogenC(StringBuffer fileBuffer){\r
2205 //\r
2206 // Entry point lib for these module types needs to know the count.\r
2207 //\r
aacce761 2208 fileBuffer.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverExitBootServicesEventCount = ");\r
a387de3b 2209\r
2210 //\r
2211 // If the list is not valid or has no entries set count to zero else\r
2212 // set count to the number of valid entries.\r
2213 //\r
2214 int Count = 0;\r
2215 int i = 0; \r
2216 if (this.exitBootServiceList != null) {\r
2217 for (i = 0; i < this.exitBootServiceList.size(); i++) {\r
2218 if (this.exitBootServiceList.get(i).equalsIgnoreCase("")) {\r
2219 break;\r
2220 }\r
2221 }\r
2222 Count = i;\r
2223 }\r
2224 fileBuffer.append(Integer.toString(Count));\r
aacce761 2225 fileBuffer.append(";\r\n\r\n");\r
a387de3b 2226\r
2227 if (this.exitBootServiceList == null || this.exitBootServiceList.size() == 0) {\r
2228 // \r
2229 // No data so make a NULL list.\r
2230 //\r
aacce761 2231 fileBuffer.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {\r\n");\r
2232 fileBuffer.append(" NULL\r\n");\r
2233 fileBuffer.append("};\r\n\r\n");\r
a387de3b 2234 } else {\r
2235 //\r
2236 // Write DriverExitBootServices function definition.\r
2237 //\r
2238 for (i = 0; i < this.exitBootServiceList.size(); i++) {\r
2239 if (this.exitBootServiceList.get(i).equalsIgnoreCase("")) {\r
2240 break;\r
2241 }\r
2242\r
aacce761 2243 functionDeclarations.append("VOID\r\n");\r
2244 functionDeclarations.append("EFIAPI\r\n");\r
2245 functionDeclarations.append(this.exitBootServiceList.get(i));\r
2246 functionDeclarations.append(" (\r\n");\r
2247 functionDeclarations.append(" IN EFI_EVENT Event,\r\n");\r
2248 functionDeclarations.append(" IN VOID *Context\r\n");\r
2249 functionDeclarations.append(" );\r\n\r\n");\r
a387de3b 2250 }\r
2251\r
2252 //\r
2253 // Write DriverExitBootServices entry point array.\r
2254 //\r
aacce761 2255 fileBuffer.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {");\r
a387de3b 2256 for (i = 0; i < this.exitBootServiceList.size(); i++) {\r
2257 if (this.exitBootServiceList.get(i).equalsIgnoreCase("")) {\r
2258 break;\r
2259 }\r
2260\r
2261 if (i == 0) {\r
aacce761 2262 fileBuffer.append("\r\n ");\r
a387de3b 2263 } else {\r
aacce761 2264 fileBuffer.append(",\r\n ");\r
a387de3b 2265 }\r
2266 fileBuffer.append(this.exitBootServiceList.get(i));\r
2267 }\r
2268\r
aacce761 2269 fileBuffer.append(",\r\n NULL");\r
2270 fileBuffer.append("\r\n};\r\n\r\n");\r
a387de3b 2271 } \r
e425f073 2272 }\r
2273 /**\r
2274 setPcdComponentName\r
2275 \r
2276 Get the Pcd Value of ComponentName to \r
2277 decide whether need to disable the componentName. \r
2278 \r
2279 **/\r
2280 public void setPcdComponentName (){\r
a387de3b 2281 String pcdValue = null;\r
2282 pcdValue = saq.getPcdValueBycName("PcdComponentNameDisable");\r
2283 if (pcdValue != null && pcdValue.equalsIgnoreCase("true")) {\r
e425f073 2284 this.componentNamePcd = true;\r
a387de3b 2285 }\r
e425f073 2286 }\r
a387de3b 2287\r
e425f073 2288 /**\r
2289 setPcdDriverDiagnostic \r
2290 \r
2291 Get the Pcd Value of DriverDiagnostic to \r
2292 decide whether need to disable DriverDiagnostic.\r
2293 \r
2294 **/\r
2295 public void setPcdDriverDiagnostic (){\r
a387de3b 2296 String pcdValue = null;\r
e425f073 2297 pcdValue = saq.getPcdValueBycName("PcdDriverDiagnosticsDisable");\r
a387de3b 2298 if (pcdValue != null && pcdValue.equalsIgnoreCase("true")) {\r
e425f073 2299 this.driverDiagnostPcd = true;\r
a387de3b 2300 }\r
e425f073 2301 } \r
a387de3b 2302\r
2336382f 2303}\r