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