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