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