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