]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/GenBuild/org/tianocore/build/autogen/AutoGen.java
New tool.
[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
885 fileBuffer\r
886 .append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");\r
887 fileBuffer\r
888 .append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n\r\n");\r
889 \r
890 fileBuffer.append("EFI_STATUS\r\n");\r
891 fileBuffer.append("EFIAPI\r\n");\r
892 fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r
893 fileBuffer.append(" EFI_HANDLE ImageHandle,\r\n");\r
894 fileBuffer.append(" EFI_SYSTEM_TABLE *SystemTable\r\n");\r
895 fileBuffer.append(" )\r\n\r\n");\r
896 fileBuffer.append("{\r\n");\r
897 fileBuffer.append(" return EFI_SUCCESS;\r\n");\r
898 fileBuffer.append("}\r\n\r\n");\r
899 break;\r
900 } else {\r
878ddf1f 901 for (int i = 0; i < entryPointList.length; i++) {\r
902 if (!entryPointList[i].equals("")) {\r
903 fileBuffer.append("EFI_STATUS\r\n");\r
904 fileBuffer.append("EFIAPI\r\n");\r
905 fileBuffer.append(entryPointList[i]);\r
906 fileBuffer.append(" (\r\n");\r
136adffc 907 fileBuffer.append(" EFI_HANDLE ImageHandle,\r\n");\r
908 fileBuffer.append(" EFI_SYSTEM_TABLE *SystemTable\r\n");\r
878ddf1f 909 fileBuffer.append(" );\r\n");\r
136adffc 910 entryPointCount++;\r
878ddf1f 911 } else {\r
912 break;\r
913 }\r
914 }\r
136adffc 915 fileBuffer\r
916 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");\r
917 fileBuffer.append(Integer.toString(entryPointCount));\r
918 fileBuffer.append(";\r\n");\r
919 fileBuffer\r
920 .append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");\r
921 fileBuffer\r
922 .append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n\r\n");\r
923\r
924 fileBuffer.append("EFI_STATUS\r\n");\r
925 fileBuffer.append("EFIAPI\r\n");\r
926 fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r
927 fileBuffer.append(" EFI_HANDLE ImageHandle,\r\n");\r
928 fileBuffer.append(" EFI_SYSTEM_TABLE *SystemTable\r\n");\r
929 fileBuffer.append(" )\r\n\r\n");\r
930 fileBuffer.append("{\r\n");\r
878ddf1f 931\r
136adffc 932 \r
878ddf1f 933 for (int i = 0; i < entryPointList.length; i++) {\r
136adffc 934 fileBuffer\r
935 .append(" if (SetJump (&mJumpContext) == 0) {\r\n");\r
936 fileBuffer.append(" ExitDriver (");\r
937 fileBuffer.append(entryPointList[i]);\r
938 fileBuffer.append(" (ImageHandle, SystemTable));\r\n");\r
939 fileBuffer.append(" ASSERT (FALSE);\r\n");\r
940 fileBuffer.append(" }\r\n");\r
941 \r
942 }\r
943 fileBuffer.append(" return mDriverEntryPointStatus;\r\n");\r
944 fileBuffer.append("}\r\n\r\n");\r
945\r
946 fileBuffer.append("VOID\r\n");\r
947 fileBuffer.append("EFIAPI\r\n");\r
948 fileBuffer.append("ExitDriver (\r\n");\r
949 fileBuffer.append(" IN EFI_STATUS Status\n");\r
950 fileBuffer.append(" )\r\n\r\n");\r
951 fileBuffer.append("{\r\n");\r
952 fileBuffer\r
953 .append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");\r
954 fileBuffer.append(" mDriverEntryPointStatus = Status;\r\n");\r
955 fileBuffer.append(" }\r\n");\r
956 fileBuffer.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");\r
957 fileBuffer.append(" ASSERT (FALSE);\r\n");\r
958 fileBuffer.append("}\r\n\r\n");\r
959 \r
960 }\r
961 \r
962 \r
963 //\r
964 // Add "ModuleUnloadImage" for DxeSmmDriver module type;\r
965 //\r
966 entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();\r
967 entryPointList = CommonDefinition.remDupString(entryPointList);\r
968 entryPointCount = 0;\r
969\r
970 fileBuffer\r
971 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");\r
972 fileBuffer.append(Integer.toString(entryPointCount));\r
973 fileBuffer.append(";\r\n\r\n");\r
974\r
975 if (entryPointList != null) {\r
976 for (int i = 0; i < entryPointList.length; i++) {\r
977 if (!entryPointList[i].equals("")) {\r
978 fileBuffer.append("EFI_STATUS\r\n");\r
979 fileBuffer.append("EFIAPI\r\n");\r
980 fileBuffer.append(entryPointList[i]);\r
981 fileBuffer.append(" (\r\n");\r
982 fileBuffer\r
983 .append(" EFI_HANDLE ImageHandle\r\n");\r
984 fileBuffer.append(" );\r\n");\r
985 } else {\r
986 break;\r
987 }\r
988 }\r
989 }\r
990\r
991 fileBuffer.append("EFI_STATUS\r\n");\r
992 fileBuffer.append("EFIAPI\r\n");\r
993 fileBuffer.append("ProcessModuleUnloadList (\r\n");\r
994 fileBuffer.append(" EFI_HANDLE ImageHandle\r\n");\r
995 fileBuffer.append(" )\r\n");\r
996 fileBuffer.append("{\r\n");\r
997\r
998 if (entryPointCount == 0) {\r
999 fileBuffer.append(" return EFI_SUCCESS;\r\n");\r
1000 } else if (entryPointCount == 1) {\r
1001 fileBuffer.append(" return ");\r
1002 fileBuffer.append(entryPointList[0]);\r
1003 fileBuffer.append("(ImageHandle);\r\n");\r
1004 } else {\r
1005 fileBuffer.append(" EFI_STATUS Status;\r\n\r\n");\r
1006 fileBuffer.append(" Status = EFI_SUCCESS;\r\n\r\n");\r
1007 for (int i = 0; i < entryPointList.length; i++) {\r
1008 if (i == 0){\r
1009 fileBuffer.append(" Status = ");\r
1010 fileBuffer.append(entryPointList[i]);\r
1011 fileBuffer.append("(ImageHandle);\r\n");\r
1012 }else{\r
878ddf1f 1013 fileBuffer.append(" if (EFI_ERROR (Status)) {\r\n");\r
1014 fileBuffer.append(" ");\r
1015 fileBuffer.append(entryPointList[i]);\r
1016 fileBuffer.append("(ImageHandle);\r\n");\r
1017 fileBuffer.append(" } else {\r\n");\r
1018 fileBuffer.append(" Status = ");\r
1019 fileBuffer.append(entryPointList[i]);\r
1020 fileBuffer.append("(ImageHandle);\r\n");\r
1021 fileBuffer.append(" }\r\n");\r
878ddf1f 1022 }\r
136adffc 1023 }\r
1024 fileBuffer.append(" return Status;\r\n");\r
1025 }\r
1026 fileBuffer.append("}\r\n\r\n");\r
1027 break;\r
1028\r
1029 case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
1030 case CommonDefinition.ModuleTypeDxeDriver:\r
1031 case CommonDefinition.ModuleTypeDxeSalDriver:\r
1032 case CommonDefinition.ModuleTypeUefiDriver:\r
1033 case CommonDefinition.ModuleTypeUefiApplication:\r
1034 entryPointCount = 0;\r
1035 fileBuffer.append("const UINT32 _gUefiDriverRevision = 0;\r\n");\r
1036 //\r
1037 // If entry point is null, create a empty ProcessModuleEntryPointList function.\r
1038 //\r
1039 if (entryPointList == null || entryPointList.length == 0){\r
a29c47e0 1040 fileBuffer\r
136adffc 1041 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = 0;\r\n");\r
1042 fileBuffer.append("EFI_STATUS\r\n");\r
1043 fileBuffer.append("EFIAPI\r\n");\r
1044 fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r
1045 fileBuffer.append(" EFI_HANDLE ImageHandle,\r\n");\r
1046 fileBuffer.append(" EFI_SYSTEM_TABLE *SystemTable\r\n");\r
1047 fileBuffer.append(" )\r\n\r\n");\r
1048 fileBuffer.append("{\r\n");\r
1049 fileBuffer.append(" return EFI_SUCCESS;\r\n");\r
1050 fileBuffer.append("}\r\n");\r
1051 \r
1052 }else {\r
1053 for (int i = 0; i < entryPointList.length; i++) {\r
1054 \r
1055 fileBuffer.append("EFI_STATUS\r\n");\r
1056 fileBuffer.append("EFIAPI\r\n");\r
1057 fileBuffer.append(entryPointList[i]);\r
1058 fileBuffer.append(" (\r\n");\r
1059 fileBuffer.append(" EFI_HANDLE ImageHandle,\r\n");\r
1060 fileBuffer.append(" EFI_SYSTEM_TABLE *SystemTable\r\n");\r
1061 fileBuffer.append(" );\r\n");\r
1062 entryPointCount++;\r
878ddf1f 1063 }\r
1064\r
878ddf1f 1065 fileBuffer\r
136adffc 1066 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");\r
1067 fileBuffer.append(Integer.toString(entryPointCount));\r
878ddf1f 1068 fileBuffer.append(";\r\n");\r
136adffc 1069 if (entryPointCount > 1) {\r
1070 fileBuffer\r
1071 .append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");\r
1072 fileBuffer\r
1073 .append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n");\r
1074 }\r
1075 fileBuffer.append("\n");\r
878ddf1f 1076\r
136adffc 1077 fileBuffer.append("EFI_STATUS\r\n");\r
1078 fileBuffer.append("EFIAPI\r\n");\r
1079 fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r
1080 fileBuffer.append(" EFI_HANDLE ImageHandle,\r\n");\r
1081 fileBuffer.append(" EFI_SYSTEM_TABLE *SystemTable\r\n");\r
1082 fileBuffer.append(" )\r\n\r\n");\r
1083 fileBuffer.append("{\r\n");\r
878ddf1f 1084\r
136adffc 1085 if (entryPointCount == 1) {\r
1086 fileBuffer.append(" return (");\r
1087 fileBuffer.append(entryPointList[0]);\r
1088 fileBuffer.append(" (ImageHandle, SystemTable));\r\n");\r
1089 } else {\r
1090 for (int i = 0; i < entryPointList.length; i++) {\r
1091 if (!entryPointList[i].equals("")) {\r
1092 fileBuffer\r
1093 .append(" if (SetJump (&mJumpContext) == 0) {\r\n");\r
1094 fileBuffer.append(" ExitDriver (");\r
1095 fileBuffer.append(entryPointList[i]);\r
1096 fileBuffer.append(" (ImageHandle, SystemTable));\r\n");\r
1097 fileBuffer.append(" ASSERT (FALSE);\r\n");\r
1098 fileBuffer.append(" }\r\n");\r
1099 } else {\r
1100 break;\r
1101 }\r
878ddf1f 1102 }\r
136adffc 1103 fileBuffer.append(" return mDriverEntryPointStatus;\r\n");\r
878ddf1f 1104 }\r
136adffc 1105 fileBuffer.append("}\r\n\r\n");\r
878ddf1f 1106\r
136adffc 1107 fileBuffer.append("VOID\n");\r
878ddf1f 1108 fileBuffer.append("EFIAPI\n");\r
136adffc 1109 fileBuffer.append("ExitDriver (\r\n");\r
1110 fileBuffer.append(" IN EFI_STATUS Status\n");\r
1111 fileBuffer.append(" )\r\n\r\n");\r
1112 fileBuffer.append("{\r\n");\r
1113 if (entryPointCount <= 1) {\r
1114 fileBuffer.append(" if (EFI_ERROR (Status)) {\r\n");\r
1115 fileBuffer\r
1116 .append(" ProcessLibraryDestructorList (gImageHandle, gST);\r\n");\r
1117 fileBuffer.append(" }\r\n");\r
1118 fileBuffer\r
1119 .append(" gBS->Exit (gImageHandle, Status, 0, NULL);\r\n");\r
878ddf1f 1120 } else {\r
136adffc 1121 fileBuffer\r
1122 .append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");\r
1123 fileBuffer.append(" mDriverEntryPointStatus = Status;\r\n");\r
1124 fileBuffer.append(" }\r\n");\r
1125 fileBuffer.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");\r
1126 fileBuffer.append(" ASSERT (FALSE);\r\n");\r
878ddf1f 1127 }\r
136adffc 1128 fileBuffer.append("}\r\n\r\n");\r
878ddf1f 1129\r
878ddf1f 1130 }\r
136adffc 1131 \r
1132 //\r
1133 // Add ModuleUnloadImage for DxeDriver and UefiDriver module type.\r
1134 //\r
1135 entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();\r
878ddf1f 1136 //\r
136adffc 1137 // Remover duplicate unload entry point.\r
878ddf1f 1138 //\r
136adffc 1139 entryPointList = CommonDefinition.remDupString(entryPointList);\r
1140 entryPointCount = 0;\r
1141 if (entryPointList != null) {\r
1142 for (int i = 0; i < entryPointList.length; i++) {\r
1143 if (!entryPointList[i].equals("")) {\r
1144 fileBuffer.append("EFI_STATUS\r\n");\r
1145 fileBuffer.append("EFIAPI\r\n");\r
1146 fileBuffer.append(entryPointList[i]);\r
1147 fileBuffer.append(" (\r\n");\r
1148 fileBuffer\r
1149 .append(" EFI_HANDLE ImageHandle\r\n");\r
1150 fileBuffer.append(" );\r\n");\r
1151 entryPointCount++;\r
1152 } else {\r
1153 break;\r
1154 }\r
1155 }\r
1156 }\r
1157\r
1158 fileBuffer\r
1159 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");\r
1160 fileBuffer.append(Integer.toString(entryPointCount));\r
1161 fileBuffer.append(";\r\n\r\n");\r
1162\r
1163 if (entryPointList != null) {\r
1164 for (int i = 0; i < entryPointList.length; i++) {\r
1165 if (!entryPointList[i].equals("")) {\r
1166 fileBuffer.append("EFI_STATUS\r\n");\r
1167 fileBuffer.append("EFIAPI\r\n");\r
1168 fileBuffer.append(entryPointList[i]);\r
1169 fileBuffer.append(" (\r\n");\r
1170 fileBuffer\r
1171 .append(" EFI_HANDLE ImageHandle\r\n");\r
1172 fileBuffer.append(" );\r\n");\r
1173 } else {\r
1174 break;\r
1175 }\r
1176 }\r
1177 }\r
1178\r
1179 fileBuffer.append("EFI_STATUS\n");\r
1180 fileBuffer.append("EFIAPI\r\n");\r
1181 fileBuffer.append("ProcessModuleUnloadList (\r\n");\r
1182 fileBuffer.append(" EFI_HANDLE ImageHandle\r\n");\r
1183 fileBuffer.append(" )\r\n");\r
1184 fileBuffer.append("{\r\n");\r
1185\r
1186 if (entryPointCount == 0) {\r
1187 fileBuffer.append(" return EFI_SUCCESS;\r\n");\r
1188 } else if (entryPointCount == 1) {\r
1189 fileBuffer.append(" return ");\r
1190 fileBuffer.append(entryPointList[0]);\r
1191 fileBuffer.append("(ImageHandle);\r\n");\r
1192 } else {\r
1193 fileBuffer.append(" EFI_STATUS Status;\r\n\r\n");\r
1194 fileBuffer.append(" Status = EFI_SUCCESS;\r\n\r\n");\r
1195 for (int i = 0; i < entryPointList.length; i++) {\r
1196 if (!entryPointList[i].equals("")) {\r
1197 fileBuffer.append(" if (EFI_ERROR (Status)) {\r\n");\r
1198 fileBuffer.append(" ");\r
1199 fileBuffer.append(entryPointList[i]);\r
1200 fileBuffer.append("(ImageHandle);\r\n");\r
1201 fileBuffer.append(" } else {\r\n");\r
1202 fileBuffer.append(" Status = ");\r
1203 fileBuffer.append(entryPointList[i]);\r
1204 fileBuffer.append("(ImageHandle);\r\n");\r
1205 fileBuffer.append(" }\r\n");\r
1206 } else {\r
1207 break;\r
1208 }\r
1209 }\r
1210 fileBuffer.append(" return Status;\r\n");\r
1211 }\r
1212 fileBuffer.append("}\r\n\r\n");\r
1213 break;\r
1214 }\r
1215 }\r
1216\r
1217 /**\r
1218 * PpiGuidToAutogenc\r
1219 * \r
1220 * This function gets GUIDs from SPD file accrodeing to <PPIs> information\r
1221 * and write those GUIDs to AutoGen.c.\r
1222 * \r
1223 * @param fileBuffer\r
1224 * String Buffer for Autogen.c file.\r
1225 * @throws BuildException\r
1226 * Guid must set value!\r
1227 */\r
1228 void PpiGuidToAutogenC(StringBuffer fileBuffer) throws AutoGenException {\r
1229 String[] cNameGuid = null;\r
1230\r
1231 //\r
1232 // Get the all PPI adn PPI Notify from MSA file,\r
1233 // then add those PPI ,and PPI Notify name to list.\r
1234 //\r
1235 \r
1236 String[] ppiList = SurfaceAreaQuery.getPpiArray(this.arch);\r
1237 for (int i = 0; i < ppiList.length; i++) {\r
1238 this.mPpiList.add(ppiList[i]);\r
1239 }\r
1240\r
1241 String[] ppiNotifyList = SurfaceAreaQuery.getPpiNotifyArray(this.arch);\r
1242 for (int i = 0; i < ppiNotifyList.length; i++) {\r
1243 this.mPpiList.add(ppiNotifyList[i]);\r
1244 }\r
1245\r
1246 //\r
1247 // Find CNAME and GUID from dependence SPD file and write to Autogen.c\r
1248 //\r
1249 Iterator ppiIterator = this.mPpiList.iterator();\r
1250 String ppiKeyWord = null;\r
1251 while (ppiIterator.hasNext()) {\r
1252 ppiKeyWord = ppiIterator.next().toString();\r
1253 cNameGuid = GlobalData.getPpiGuid(this.mDepPkgList, ppiKeyWord);\r
1254 if (cNameGuid != null) {\r
1255 fileBuffer\r
1256 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r
1257 fileBuffer.append(cNameGuid[0]);\r
1258 fileBuffer.append(" = { ");\r
1259 fileBuffer.append(CommonDefinition.formatGuidName(cNameGuid[1]));\r
1260 fileBuffer.append(" } ;");\r
1261 } else {\r
1262 //\r
1263 // If can't find Ppi GUID declaration in every package\r
1264 //\r
1265 throw new AutoGenException("Can not find Ppi GUID ["\r
1266 + ppiKeyWord + "] declaration in every packages. ");\r
1267 }\r
1268 }\r
1269 }\r
1270\r
1271 /**\r
1272 * ProtocolGuidToAutogenc\r
1273 * \r
1274 * This function gets GUIDs from SPD file accrodeing to <Protocol>\r
1275 * information and write those GUIDs to AutoGen.c.\r
1276 * \r
1277 * @param fileBuffer\r
1278 * String Buffer for Autogen.c file.\r
1279 * @throws BuildException\r
1280 * Protocol name must set.\r
1281 */\r
1282 void ProtocolGuidToAutogenC(StringBuffer fileBuffer) throws BuildException {\r
1283 String[] cNameGuid = null;\r
1284\r
1285 String[] protocolList = SurfaceAreaQuery.getProtocolArray(this.arch);\r
1286\r
1287 //\r
1288 // Add result to Autogen global list.\r
1289 //\r
1290 for (int i = 0; i < protocolList.length; i++) {\r
1291 this.mProtocolList.add(protocolList[i]);\r
1292 }\r
1293\r
1294 String[] protocolNotifyList = SurfaceAreaQuery\r
1295 .getProtocolNotifyArray(this.arch);\r
1296\r
1297 for (int i = 0; i < protocolNotifyList.length; i++) {\r
1298 this.mProtocolList.add(protocolNotifyList[i]);\r
1299 }\r
1300\r
1301 //\r
1302 // Get the NAME and GUID from dependence SPD and write to Autogen.c\r
1303 //\r
1304 Iterator protocolIterator = this.mProtocolList.iterator();\r
1305 String protocolKeyWord = null;\r
1306 \r
1307 \r
1308 while (protocolIterator.hasNext()) {\r
1309 protocolKeyWord = protocolIterator.next().toString();\r
1310 cNameGuid = GlobalData.getProtocolGuid(this.mDepPkgList, protocolKeyWord);\r
1311 if (cNameGuid != null) {\r
1312 fileBuffer\r
1313 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r
1314 fileBuffer.append(cNameGuid[0]);\r
1315 fileBuffer.append(" = { ");\r
1316 fileBuffer.append(CommonDefinition.formatGuidName(cNameGuid[1]));\r
1317 fileBuffer.append(" } ;");\r
1318 } else {\r
1319 //\r
1320 // If can't find protocol GUID declaration in every package\r
1321 //\r
1322 throw new BuildException("Can not find protocol Guid ["\r
1323 + protocolKeyWord + "] declaration in every packages. ");\r
1324 }\r
1325 }\r
1326 }\r
1327\r
1328 /**\r
1329 * GuidGuidToAutogenc\r
1330 * \r
1331 * This function gets GUIDs from SPD file accrodeing to <Guids> information\r
1332 * and write those GUIDs to AutoGen.c.\r
1333 * \r
1334 * @param fileBuffer\r
1335 * String Buffer for Autogen.c file.\r
1336 * \r
1337 */\r
1338 void GuidGuidToAutogenC(StringBuffer fileBuffer) throws AutoGenException {\r
1339 String[] cNameGuid = null;\r
1340 String guidKeyWord = null;\r
1341\r
1342 String[] guidList = SurfaceAreaQuery.getGuidEntryArray(this.arch);\r
1343\r
1344 for (int i = 0; i < guidList.length; i++) {\r
1345 this.mGuidList.add(guidList[i]);\r
1346 }\r
1347\r
1348\r
1349 Iterator guidIterator = this.mGuidList.iterator();\r
1350 while (guidIterator.hasNext()) {\r
1351 guidKeyWord = guidIterator.next().toString();\r
1352 cNameGuid = GlobalData.getGuid(this.mDepPkgList, guidKeyWord);\r
1353\r
1354 if (cNameGuid != null) {\r
1355 fileBuffer\r
1356 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r
1357 fileBuffer.append(cNameGuid[0]);\r
1358 fileBuffer.append(" = { ");\r
1359 fileBuffer.append(CommonDefinition.formatGuidName(cNameGuid[1]));\r
1360 fileBuffer.append("} ;");\r
1361 } else {\r
1362 //\r
1363 // If can't find GUID declaration in every package\r
1364 //\r
1365 throw new AutoGenException("Can not find Guid [" + guidKeyWord\r
1366 + "] declaration in every packages. ");\r
1367 }\r
1368\r
1369 }\r
1370 }\r
1371\r
1372 /**\r
1373 * LibInstanceToAutogenC\r
1374 * \r
1375 * This function adds dependent library instance to autogen.c,which\r
1376 * includeing library's constructor, destructor, and library dependent ppi,\r
1377 * protocol, guid, pcd information.\r
1378 * \r
1379 * @param fileBuffer\r
1380 * String buffer for AutoGen.c\r
1381 * @throws BuildException\r
1382 */\r
1383 void LibInstanceToAutogenC(StringBuffer fileBuffer) throws BuildException {\r
1384 int index;\r
1385\r
1386 String moduleType = SurfaceAreaQuery.getModuleType();\r
1387 List<String> libConstructList = new ArrayList<String>();\r
1388 List<String> libDestructList = new ArrayList<String>();\r
1389\r
1390 String libConstructName = null;\r
1391 String libDestructName = null;\r
1392 ModuleIdentification[] libraryIdList = SurfaceAreaQuery\r
1393 .getLibraryInstance(this.arch);\r
1394\r
1395 try {\r
1396 if (libraryIdList != null) {\r
1397 //\r
1398 // Reorder library instance sequence.\r
1399 //\r
1400 AutogenLibOrder libOrder = new AutogenLibOrder(libraryIdList,\r
1401 this.arch);\r
1402 List<ModuleIdentification> orderList = libOrder\r
1403 .orderLibInstance();\r
1404\r
1405 if (orderList != null) {\r
1406 //\r
1407 // Process library instance one by one.\r
1408 //\r
1409 for (int i = 0; i < orderList.size(); i++) {\r
1410\r
1411 //\r
1412 // Get library instance basename.\r
1413 //\r
1414 ModuleIdentification libInstanceId = orderList.get(i);\r
1415\r
1416 //\r
1417 // Get override map\r
1418 //\r
1419 \r
1420 Map<String, XmlObject> libDoc = GlobalData.getDoc(\r
1421 libInstanceId, this.arch);\r
1422 SurfaceAreaQuery.push(libDoc);\r
1423\r
1424 //\r
1425 // Get <PPis>, <Protocols>, <Guids> list of this library\r
1426 // instance.\r
1427 //\r
1428 String[] ppiList = SurfaceAreaQuery.getPpiArray(this.arch);\r
1429 String[] ppiNotifyList = SurfaceAreaQuery\r
1430 .getPpiNotifyArray(this.arch);\r
1431 String[] protocolList = SurfaceAreaQuery\r
1432 .getProtocolArray(this.arch);\r
1433 String[] protocolNotifyList = SurfaceAreaQuery\r
1434 .getProtocolNotifyArray(this.arch);\r
1435 String[] guidList = SurfaceAreaQuery\r
1436 .getGuidEntryArray(this.arch);\r
1437 PackageIdentification[] pkgList = SurfaceAreaQuery.getDependencePkg(this.arch);\r
1438\r
1439 //\r
1440 // Add those ppi, protocol, guid in global ppi,\r
1441 // protocol, guid\r
1442 // list.\r
1443 //\r
1444 for (index = 0; index < ppiList.length; index++) {\r
1445 this.mPpiList.add(ppiList[index]);\r
1446 }\r
1447\r
1448 for (index = 0; index < ppiNotifyList.length; index++) {\r
1449 this.mPpiList.add(ppiNotifyList[index]);\r
1450 }\r
1451\r
1452 for (index = 0; index < protocolList.length; index++) {\r
1453 this.mProtocolList.add(protocolList[index]);\r
1454 }\r
1455\r
1456 for (index = 0; index < protocolNotifyList.length; index++) {\r
1457 this.mProtocolList.add(protocolNotifyList[index]);\r
1458 }\r
1459\r
1460 for (index = 0; index < guidList.length; index++) {\r
1461 this.mGuidList.add(guidList[index]);\r
1462 }\r
1463 for (index = 0; index < pkgList.length; index++){\r
1464 if (!this.mDepPkgList.contains(pkgList[index])){\r
1465 this.mDepPkgList.add(pkgList[index]);\r
1466 }\r
878ddf1f 1467 }\r
878ddf1f 1468\r
136adffc 1469 //\r
1470 // If not yet parse this library instance's constructor\r
1471 // element,parse it.\r
1472 //\r
1473 libConstructName = SurfaceAreaQuery\r
1474 .getLibConstructorName();\r
1475 libDestructName = SurfaceAreaQuery\r
1476 .getLibDestructorName();\r
1477\r
1478 SurfaceAreaQuery.pop();\r
1479 //\r
1480 // Add dependent library instance constructor function.\r
1481 //\r
1482 if (libConstructName != null) {\r
1483 libConstructList.add(libConstructName);\r
1484 }\r
1485 //\r
1486 // Add dependent library instance destructor fuction.\r
1487 //\r
1488 if (libDestructName != null) {\r
1489 libDestructList.add(libDestructName);\r
1490 }\r
1491 }\r
1492\r
1493 }\r
1494\r
1495 //\r
1496 // Add library constructor to AutoGen.c\r
1497 //\r
1498 LibConstructorToAutogenC(libConstructList, moduleType,\r
1499 fileBuffer/* autogenC */);\r
1500 //\r
1501 // Add library destructor to AutoGen.c\r
1502 //\r
1503 LibDestructorToAutogenC(libDestructList, moduleType, fileBuffer/* autogenC */);\r
1504 }\r
1505\r
1506 } catch (Exception e) {\r
1507 throw new BuildException(e.getMessage());\r
1508 }\r
1509 }\r
1510\r
1511 /**\r
1512 * LibConstructorToAutogenc\r
1513 * \r
1514 * This function writes library constructor list to AutoGen.c. The library\r
1515 * constructor's parameter and return value depend on module type.\r
1516 * \r
1517 * @param libInstanceList\r
1518 * List of library construct name.\r
1519 * @param moduleType\r
1520 * Module type.\r
1521 * @param fileBuffer\r
1522 * String buffer for AutoGen.c\r
1523 * @throws Exception\r
1524 */\r
1525 void LibConstructorToAutogenC(List<String> libInstanceList,\r
1526 String moduleType, StringBuffer fileBuffer) throws Exception {\r
1527 boolean isFirst = true;\r
1528\r
1529 //\r
1530 // The library constructor's parameter and return value depend on\r
1531 // module type.\r
1532 //\r
1533 for (int i = 0; i < libInstanceList.size(); i++) {\r
1534 switch (CommonDefinition.getModuleType(moduleType)) {\r
1535 case CommonDefinition.ModuleTypeBase:\r
1536 fileBuffer.append("RETURN_STATUS\r\n");\r
1537 fileBuffer.append(libInstanceList.get(i));\r
1538 fileBuffer.append(" (\r\n");\r
1539 fileBuffer.append(" VOID\r\n");\r
1540 fileBuffer.append(" );\r\n");\r
1541 break;\r
1542\r
1543 case CommonDefinition.ModuleTypePeiCore:\r
1544 case CommonDefinition.ModuleTypePeim:\r
1545 fileBuffer.append("EFI_STATUS\r\n");\r
1546 fileBuffer.append(libInstanceList.get(i));\r
1547 fileBuffer.append(" (\r\n");\r
1548 fileBuffer\r
1549 .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");\r
1550 fileBuffer\r
1551 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");\r
1552 fileBuffer.append(" );\r\n");\r
1553 break;\r
1554\r
1555 case CommonDefinition.ModuleTypeDxeCore:\r
1556 case CommonDefinition.ModuleTypeDxeDriver:\r
1557 case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
1558 case CommonDefinition.ModuleTypeDxeSmmDriver:\r
1559 case CommonDefinition.ModuleTypeDxeSalDriver:\r
1560 case CommonDefinition.ModuleTypeUefiDriver:\r
1561 case CommonDefinition.ModuleTypeUefiApplication:\r
1562 fileBuffer.append("EFI_STATUS\r\n");\r
1563 fileBuffer.append(libInstanceList.get(i));\r
1564 fileBuffer.append(" (\r\n");\r
1565 fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");\r
1566 fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r
1567 fileBuffer.append(" );\r\n");\r
1568 break;\r
1569 }\r
1570 }\r
1571\r
1572 //\r
1573 // Add ProcessLibraryConstructorList in AutoGen.c\r
1574 //\r
1575 fileBuffer.append("VOID\r\n");\r
1576 fileBuffer.append("ProcessLibraryConstructorList (\r\n");\r
1577 switch (CommonDefinition.getModuleType(moduleType)) {\r
1578 case CommonDefinition.ModuleTypeBase:\r
1579 fileBuffer.append(" VOID\r\n");\r
1580 break;\r
1581\r
1582 case CommonDefinition.ModuleTypePeiCore:\r
1583 case CommonDefinition.ModuleTypePeim:\r
1584 fileBuffer.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");\r
1585 fileBuffer\r
1586 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");\r
1587 break;\r
1588\r
1589 case CommonDefinition.ModuleTypeDxeCore:\r
1590 case CommonDefinition.ModuleTypeDxeDriver:\r
1591 case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
1592 case CommonDefinition.ModuleTypeDxeSmmDriver:\r
1593 case CommonDefinition.ModuleTypeDxeSalDriver:\r
1594 case CommonDefinition.ModuleTypeUefiDriver:\r
1595 case CommonDefinition.ModuleTypeUefiApplication:\r
1596 fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");\r
1597 fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r
1598 break;\r
1599 }\r
1600\r
1601 fileBuffer.append(" )\r\n");\r
1602 fileBuffer.append("{\r\n");\r
1603 //\r
1604 // If no constructor function, return EFI_SUCCESS.\r
1605 //\r
1606 //if (libInstanceList.size() == 0){\r
1607 // fileBuffer.append(" return EFI_SUCCESS;\r\n");\r
1608 //}\r
1609 for (int i = 0; i < libInstanceList.size(); i++) {\r
1610 if (isFirst) {\r
1611 fileBuffer.append(" EFI_STATUS Status;\r\n");\r
1612 fileBuffer.append(" Status = EFI_SUCCESS;\r\n");\r
1613 fileBuffer.append("\r\n");\r
1614 isFirst = false;\r
1615 }\r
1616 switch (CommonDefinition.getModuleType(moduleType)) {\r
1617 case CommonDefinition.ModuleTypeBase:\r
1618 fileBuffer.append(" Status = ");\r
1619 fileBuffer.append(libInstanceList.get(i));\r
1620 fileBuffer.append("();\r\n");\r
1621 fileBuffer.append(" VOID\r\n");\r
1622 break;\r
1623 case CommonDefinition.ModuleTypePeiCore:\r
1624 case CommonDefinition.ModuleTypePeim:\r
1625 fileBuffer.append(" Status = ");\r
1626 fileBuffer.append(libInstanceList.get(i));\r
1627 fileBuffer.append(" (FfsHeader, PeiServices);\r\n");\r
1628 break;\r
1629 case CommonDefinition.ModuleTypeDxeCore:\r
1630 case CommonDefinition.ModuleTypeDxeDriver:\r
1631 case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
1632 case CommonDefinition.ModuleTypeDxeSmmDriver:\r
1633 case CommonDefinition.ModuleTypeDxeSalDriver:\r
1634 case CommonDefinition.ModuleTypeUefiDriver:\r
1635 case CommonDefinition.ModuleTypeUefiApplication:\r
1636 fileBuffer.append(" Status = ");\r
1637 fileBuffer.append(libInstanceList.get(i));\r
1638 fileBuffer.append(" (ImageHandle, SystemTable);\r\n");\r
1639 break;\r
1640 default:\r
1641 EdkLog.log(EdkLog.EDK_INFO,"Autogen don't know how to deal with module type -"+ moduleType + " !");\r
1642 }\r
1643 fileBuffer.append(" ASSERT_EFI_ERROR (Status);\r\n");\r
1644 }\r
1645 fileBuffer.append("}\r\n");\r
1646 }\r
1647\r
1648 /**\r
1649 * LibDestructorToAutogenc\r
1650 * \r
1651 * This function writes library destructor list to AutoGen.c. The library\r
1652 * destructor's parameter and return value depend on module type.\r
1653 * \r
1654 * @param libInstanceList\r
1655 * List of library destructor name.\r
1656 * @param moduleType\r
1657 * Module type.\r
1658 * @param fileBuffer\r
1659 * String buffer for AutoGen.c\r
1660 * @throws Exception\r
1661 */\r
1662 void LibDestructorToAutogenC(List<String> libInstanceList,\r
1663 String moduleType, StringBuffer fileBuffer) throws Exception {\r
1664 boolean isFirst = true;\r
1665 for (int i = 0; i < libInstanceList.size(); i++) {\r
1666 switch (CommonDefinition.getModuleType(moduleType)) {\r
1667 case CommonDefinition.ModuleTypeBase:\r
1668 fileBuffer.append("RETURN_STATUS\n");\r
1669 fileBuffer.append(libInstanceList.get(i));\r
1670 fileBuffer.append(" (\r\n");\r
1671 fileBuffer.append(" VOID\r\n");\r
1672 fileBuffer.append(" );\r\n");\r
1673 break;\r
1674 case CommonDefinition.ModuleTypePeiCore:\r
1675 case CommonDefinition.ModuleTypePeim:\r
1676 fileBuffer.append("EFI_STATUS\r\n");\r
1677 fileBuffer.append(libInstanceList.get(i));\r
1678 fileBuffer.append(" (\r\n");\r
1679 fileBuffer\r
1680 .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");\r
1681 fileBuffer\r
1682 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");\r
1683 fileBuffer.append(" );\r\n");\r
1684 break;\r
1685 case CommonDefinition.ModuleTypeDxeCore:\r
1686 case CommonDefinition.ModuleTypeDxeDriver:\r
1687 case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
1688 case CommonDefinition.ModuleTypeDxeSmmDriver:\r
1689 case CommonDefinition.ModuleTypeDxeSalDriver:\r
1690 case CommonDefinition.ModuleTypeUefiDriver:\r
1691 case CommonDefinition.ModuleTypeUefiApplication:\r
1692 fileBuffer.append("EFI_STATUS\r\n");\r
1693 fileBuffer.append(libInstanceList.get(i));\r
1694 fileBuffer.append(" (\r\n");\r
1695 fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");\r
1696 fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r
1697 fileBuffer.append(" );\r\n");\r
1698 break;\r
1699 }\r
1700 }\r
1701\r
1702 //\r
1703 // Write ProcessLibraryDestructor list to autogen.c\r
1704 //\r
1705 switch (CommonDefinition.getModuleType(moduleType)) {\r
1706 case CommonDefinition.ModuleTypeBase:\r
1707 case CommonDefinition.ModuleTypePeiCore:\r
1708 case CommonDefinition.ModuleTypePeim:\r
1709 break;\r
1710 case CommonDefinition.ModuleTypeDxeCore:\r
1711 case CommonDefinition.ModuleTypeDxeDriver:\r
1712 case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
1713 case CommonDefinition.ModuleTypeDxeSmmDriver:\r
1714 case CommonDefinition.ModuleTypeDxeSalDriver:\r
1715 case CommonDefinition.ModuleTypeUefiDriver:\r
1716 case CommonDefinition.ModuleTypeUefiApplication:\r
1717 fileBuffer.append("VOID\r\n");\r
1718 fileBuffer.append("ProcessLibraryDestructorList (\r\n");\r
1719 fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");\r
1720 fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r
1721 fileBuffer.append(" )\r\n");\r
1722 fileBuffer.append("{\r\n");\r
878ddf1f 1723 //\r
136adffc 1724 // If no library destructor function, return EFI_SUCCESS.\r
878ddf1f 1725 //\r
136adffc 1726 \r
1727 for (int i = 0; i < libInstanceList.size(); i++) {\r
1728 if (isFirst) {\r
1729 fileBuffer.append(" EFI_STATUS Status;\r\n");\r
1730 fileBuffer.append(" Status = EFI_SUCCESS;\r\n");\r
1731 fileBuffer.append("\r\n");\r
1732 isFirst = false;\r
1733 }\r
1734 fileBuffer.append(" Status = ");\r
1735 fileBuffer.append(libInstanceList.get(i));\r
1736 fileBuffer.append("(ImageHandle, SystemTable);\r\n");\r
1737 fileBuffer.append(" ASSERT_EFI_ERROR (Status);\r\n");\r
1738 }\r
1739 fileBuffer.append("}\r\n");\r
1740 break;\r
1741 }\r
1742 }\r
1743\r
1744 /**\r
1745 * ExternsDriverBindingToAutoGenC\r
1746 * \r
1747 * This function is to write DRIVER_BINDING, COMPONENT_NAME,\r
1748 * DRIVER_CONFIGURATION, DRIVER_DIAGNOSTIC in AutoGen.c.\r
1749 * \r
1750 * @param fileBuffer\r
1751 * String buffer for AutoGen.c\r
1752 */\r
1753 void ExternsDriverBindingToAutoGenC(StringBuffer fileBuffer)\r
1754 throws BuildException {\r
1755\r
1756 //\r
1757 // Check what <extern> contains. And the number of following elements\r
1758 // under <extern> should be same. 1. DRIVER_BINDING 2. COMPONENT_NAME\r
1759 // 3.DRIVER_CONFIGURATION 4. DRIVER_DIAGNOSTIC\r
1760 //\r
1761\r
1762 String[] drvBindList = SurfaceAreaQuery.getDriverBindingArray();\r
1763\r
1764 //\r
1765 // If component name protocol,component configuration protocol,\r
1766 // component diagnostic protocol is not null or empty, check\r
1767 // if every one have the same number of the driver binding protocol.\r
1768 //\r
1769 if (drvBindList == null || drvBindList.length == 0) {\r
1770 return;\r
1771 }\r
1772\r
1773 String[] compNamList = SurfaceAreaQuery.getComponentNameArray();\r
1774 String[] compConfList = SurfaceAreaQuery.getDriverConfigArray();\r
1775 String[] compDiagList = SurfaceAreaQuery.getDriverDiagArray();\r
1776\r
1777 int BitMask = 0;\r
1778\r
1779 //\r
1780 // Write driver binding protocol extern to autogen.c\r
1781 //\r
1782 for (int i = 0; i < drvBindList.length; i++) {\r
1783 fileBuffer.append("extern EFI_DRIVER_BINDING_PROTOCOL ");\r
1784 fileBuffer.append(drvBindList[i]);\r
1785 fileBuffer.append(";\r\n");\r
1786 }\r
1787\r
1788 //\r
1789 // Write component name protocol extern to autogen.c\r
1790 //\r
1791 if (compNamList != null && compNamList.length != 0) {\r
1792 if (drvBindList.length != compNamList.length) {\r
1793 throw new BuildException(\r
1794 "Different number of Driver Binding and Component Name protocols!");\r
1795 }\r
1796\r
1797 BitMask |= 0x01;\r
1798 for (int i = 0; i < compNamList.length; i++) {\r
1799 fileBuffer.append("extern EFI_COMPONENT_NAME_PROTOCOL ");\r
1800 fileBuffer.append(compNamList[i]);\r
1801 fileBuffer.append(";\r\n");\r
1802 }\r
1803 }\r
1804\r
1805 //\r
1806 // Write driver configration protocol extern to autogen.c\r
1807 //\r
1808 if (compConfList != null && compConfList.length != 0) {\r
1809 if (drvBindList.length != compConfList.length) {\r
1810 throw new BuildException(\r
1811 "Different number of Driver Binding and Driver Configuration protocols!");\r
1812 }\r
1813\r
1814 BitMask |= 0x02;\r
1815 for (int i = 0; i < compConfList.length; i++) {\r
1816 fileBuffer.append("extern EFI_DRIVER_CONFIGURATION_PROTOCOL ");\r
1817 fileBuffer.append(compConfList[i]);\r
1818 fileBuffer.append(";\r\n");\r
1819 }\r
1820 }\r
1821\r
1822 //\r
1823 // Write driver dignastic protocol extern to autogen.c\r
1824 //\r
1825 if (compDiagList != null && compDiagList.length != 0) {\r
1826 if (drvBindList.length != compDiagList.length) {\r
1827 throw new BuildException(\r
1828 "Different number of Driver Binding and Driver Configuration protocols!");\r
1829 }\r
1830\r
1831 BitMask |= 0x04;\r
1832 for (int i = 0; i < compDiagList.length; i++) {\r
1833 fileBuffer.append("extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL ");\r
1834 fileBuffer.append(compDiagList[i]);\r
1835 fileBuffer.append(";\r\n");\r
1836 }\r
1837 }\r
1838\r
1839 //\r
1840 // Write driver module protocol bitmask.\r
1841 //\r
1842 fileBuffer\r
1843 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverModelProtocolBitmask = ");\r
1844 fileBuffer.append(Integer.toString(BitMask));\r
1845 fileBuffer.append(";\r\n");\r
1846\r
1847 //\r
1848 // Write driver module protocol list entry\r
1849 //\r
1850 fileBuffer\r
1851 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverModelProtocolListEntries = ");\r
1852\r
1853 fileBuffer.append(Integer.toString(drvBindList.length));\r
1854 fileBuffer.append(";\r\n");\r
1855\r
1856 //\r
1857 // Write drive module protocol list to autogen.c\r
1858 //\r
1859 fileBuffer\r
1860 .append("GLOBAL_REMOVE_IF_UNREFERENCED const EFI_DRIVER_MODEL_PROTOCOL_LIST _gDriverModelProtocolList[] = {");\r
1861 for (int i = 0; i < drvBindList.length; i++) {\r
1862 if (i != 0) {\r
1863 fileBuffer.append(",");\r
1864 }\r
1865 fileBuffer.append("\r\n {\r\n");\r
1866 fileBuffer.append(" &");\r
1867 fileBuffer.append(drvBindList[i]);\r
1868 fileBuffer.append(", \r\n");\r
1869\r
1870 if (compNamList != null) {\r
1871 fileBuffer.append(" &");\r
1872 fileBuffer.append(compNamList[i]);\r
1873 fileBuffer.append(", \r\n");\r
1874 } else {\r
1875 fileBuffer.append(" NULL, \r\n");\r
1876 }\r
1877\r
1878 if (compConfList != null) {\r
1879 fileBuffer.append(" &");\r
1880 fileBuffer.append(compConfList[i]);\r
1881 fileBuffer.append(", \r\n");\r
1882 } else {\r
1883 fileBuffer.append(" NULL, \r\n");\r
1884 }\r
1885\r
1886 if (compDiagList != null) {\r
1887 fileBuffer.append(" &");\r
1888 fileBuffer.append(compDiagList[i]);\r
1889 fileBuffer.append(", \r\n");\r
1890 } else {\r
1891 fileBuffer.append(" NULL, \r\n");\r
1892 }\r
1893 fileBuffer.append(" }");\r
1894 }\r
1895 fileBuffer.append("\r\n};\r\n");\r
1896 }\r
1897\r
1898 /**\r
1899 * ExternCallBackToAutoGenC\r
1900 * \r
1901 * This function adds <SetVirtualAddressMapCallBack> and\r
1902 * <ExitBootServicesCallBack> infomation to AutoGen.c\r
1903 * \r
1904 * @param fileBuffer\r
1905 * String buffer for AutoGen.c\r
1906 * @throws BuildException\r
1907 */\r
1908 void ExternCallBackToAutoGenC(StringBuffer fileBuffer)\r
1909 throws BuildException {\r
1910 String[] setVirtualList = SurfaceAreaQuery\r
1911 .getSetVirtualAddressMapCallBackArray();\r
1912 String[] exitBootList = SurfaceAreaQuery\r
1913 .getExitBootServicesCallBackArray();\r
1914 String moduleType = SurfaceAreaQuery.getModuleType();\r
1915 boolean UefiOrDxeModule = false;\r
1916 int Count = 0;\r
1917 int i;\r
1918\r
1919 switch (CommonDefinition.getModuleType(moduleType)) {\r
1920 case CommonDefinition.ModuleTypeDxeDriver:\r
1921 case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
1922 case CommonDefinition.ModuleTypeDxeSalDriver:\r
1923 case CommonDefinition.ModuleTypeUefiDriver:\r
1924 case CommonDefinition.ModuleTypeUefiApplication:\r
1925 //\r
1926 // Entry point lib for these module types needs to know the count\r
1927 // of entryPoint.\r
1928 //\r
1929 UefiOrDxeModule = true;\r
1930 fileBuffer\r
1931 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverSetVirtualAddressMapEventCount = ");\r
1932\r
1933 //\r
1934 // If the list is not valid or has no entries set count to zero else\r
1935 // set count to the number of valid entries\r
1936 //\r
1937 Count = 0;\r
1938 if (setVirtualList != null) {\r
1939 for (i = 0; i < setVirtualList.length; i++) {\r
1940 if (setVirtualList[i].equalsIgnoreCase("")) {\r
1941 break;\r
1942 }\r
1943 }\r
1944 Count = i;\r
1945 }\r
1946\r
1947 fileBuffer.append(Integer.toString(Count));\r
1948 fileBuffer.append(";\r\n\r\n");\r
1949 break;\r
1950 default:\r
1951 break;\r
1952 }\r
1953\r
1954 if (setVirtualList == null) {\r
1955 if (UefiOrDxeModule) {\r
1956 //\r
1957 // No data so make a NULL list\r
1958 //\r
1959 fileBuffer\r
1960 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {\r\n");\r
1961 fileBuffer.append(" NULL\r\n");\r
1962 fileBuffer.append("};\r\n\r\n");\r
1963 }\r
1964 } else {\r
1965 //\r
1966 // Write SetVirtualAddressMap function definition.\r
1967 //\r
1968 for (i = 0; i < setVirtualList.length; i++) {\r
1969 if (setVirtualList[i].equalsIgnoreCase("")) {\r
1970 break;\r
1971 }\r
1972 fileBuffer.append("VOID\r\n");\r
1973 fileBuffer.append("EFIAPI\r\n");\r
1974 fileBuffer.append(setVirtualList[i]);\r
1975 fileBuffer.append(" (\r\n");\r
1976 fileBuffer.append(" IN EFI_EVENT Event,\r\n");\r
1977 fileBuffer.append(" IN VOID *Context\r\n");\r
1978 fileBuffer.append(" );\r\n\r\n");\r
1979 }\r
1980\r
1981 //\r
1982 // Write SetVirtualAddressMap entry point array.\r
1983 //\r
1984 fileBuffer\r
1985 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {");\r
1986 for (i = 0; i < setVirtualList.length; i++) {\r
1987 if (setVirtualList[i].equalsIgnoreCase("")) {\r
1988 break;\r
1989 }\r
1990\r
1991 if (i == 0) {\r
1992 fileBuffer.append("\r\n ");\r
1993 } else {\r
1994 fileBuffer.append(",\r\n ");\r
1995 }\r
1996\r
1997 fileBuffer.append(setVirtualList[i]);\r
1998 }\r
1999 //\r
2000 // If module is not DXE_DRIVER, DXE_RUNTIME_DIRVER, UEFI_DRIVER\r
2001 // UEFI_APPLICATION and DXE_SAL_DRIVER add the NULL at the end of \r
2002 // _gDriverSetVirtualAddressMapEvent list. \r
2003 //\r
2004 if (!UefiOrDxeModule) {\r
2005 fileBuffer.append(",\r\n NULL");\r
2006 }\r
2007 fileBuffer.append("\r\n};\r\n\r\n");\r
2008 }\r
2009\r
2010 if (UefiOrDxeModule) {\r
2011 //\r
2012 // Entry point lib for these module types needs to know the count.\r
2013 //\r
2014 fileBuffer\r
2015 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverExitBootServicesEventCount = ");\r
2016\r
2017 //\r
2018 // If the list is not valid or has no entries set count to zero else\r
2019 // set count to the number of valid entries.\r
2020 //\r
2021 Count = 0;\r
2022 if (exitBootList != null) {\r
2023 if (setVirtualList != null) {\r
2024 for (i = 0; i < exitBootList.length; i++) {\r
2025 if (exitBootList[i].equalsIgnoreCase("")) {\r
2026 break;\r
2027 }\r
2028 }\r
2029 Count = i;\r
2030 }\r
2031 }\r
2032 fileBuffer.append(Integer.toString(Count));\r
2033 fileBuffer.append(";\r\n\r\n");\r
2034 }\r
2035\r
2036 if (exitBootList == null) {\r
2037 if (UefiOrDxeModule) {\r
2038 //\r
2039 // No data so make a NULL list.\r
2040 //\r
2041 fileBuffer\r
2042 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {\r\n");\r
2043 fileBuffer.append(" NULL\r\n");\r
2044 fileBuffer.append("};\r\n\r\n");\r
2045 }\r
2046 } else {\r
2047 //\r
2048 // Write DriverExitBootServices function definition.\r
2049 //\r
2050 for (i = 0; i < exitBootList.length; i++) {\r
2051 if (exitBootList[i].equalsIgnoreCase("")) {\r
2052 break;\r
2053 }\r
2054\r
2055 fileBuffer.append("VOID\r\n");\r
2056 fileBuffer.append("EFIAPI\r\n");\r
2057 fileBuffer.append(exitBootList[i]);\r
2058 fileBuffer.append(" (\r\n");\r
2059 fileBuffer.append(" IN EFI_EVENT Event,\r\n");\r
2060 fileBuffer.append(" IN VOID *Context\r\n");\r
2061 fileBuffer.append(" );\r\n\r\n");\r
2062 }\r
2063\r
2064 //\r
2065 // Write DriverExitBootServices entry point array.\r
2066 //\r
2067 fileBuffer\r
2068 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {");\r
2069 for (i = 0; i < exitBootList.length; i++) {\r
2070 if (exitBootList[i].equalsIgnoreCase("")) {\r
2071 break;\r
2072 }\r
2073\r
2074 if (i == 0) {\r
2075 fileBuffer.append("\r\n ");\r
2076 } else {\r
2077 fileBuffer.append(",\r\n ");\r
2078 }\r
2079 fileBuffer.append(exitBootList[i]);\r
2080 }\r
2081 if (!UefiOrDxeModule) {\r
2082 fileBuffer.append(",\r\n NULL");\r
2083 }\r
2084 fileBuffer.append("\r\n};\r\n\r\n");\r
2085 }\r
2086\r
2087 }\r
878ddf1f 2088\r
a29c47e0 2089}