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