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