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