]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/GenBuild/org/tianocore/build/autogen/AutoGen.java
Translate the Arch enum to an arch directory name. This is necessary for Linux builds...
[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
411 this.myPcdAutogen = new PCDAutoGenAction(baseName, \r
412 baseName.equalsIgnoreCase("PcdEmulatorPeim"));\r
413 this.myPcdAutogen.execute();\r
414 } catch (Exception e) {\r
415 throw new BuildException("PCD Autogen failed:" + e.getMessage());\r
416 }\r
417\r
418 if (this.myPcdAutogen != null) {\r
419 fileBuffer.append(this.myPcdAutogen.OutputC());\r
420 }\r
421\r
422 if (!saveFile(outputPath + File.separatorChar + "AutoGen.c", fileBuffer)) {\r
423 throw new BuildException("Failed to generate AutoGen.c !!!");\r
424 }\r
425\r
426 }\r
427 \r
428 /**\r
429 libGenAutogenH\r
430 \r
431 This function generates AutoGen.h for library.\r
432 \r
433 @throws BuildException\r
434 Failed to generate AutoGen.c.\r
435 **/\r
436 void libGenAutogenH() throws BuildException {\r
437\r
438 List<String> libClassIncludeH;\r
439 String moduleType;\r
440 List<String> headerFileList;\r
441 StringBuffer fileBuffer = new StringBuffer(10240);\r
442\r
443 //\r
444 // Write Autogen.h header notation \r
445 //\r
446 fileBuffer.append(CommonDefinition.autogenHNotation);\r
447 \r
448 //\r
449 // Add #ifndef ${BaseName}_AUTOGENH\r
450 // #def ${BseeName}_AUTOGENH\r
451 //\r
452 fileBuffer.append("#ifndef " + this.baseName.toUpperCase() + "_AUTOGENH\r\n");\r
453 fileBuffer.append("#define " + this.baseName.toUpperCase() + "_AUTOGENH\r\n\r\n");\r
454 \r
455 //\r
456 // Write EFI_SPECIFICATION_VERSION and EDK_RELEASE_VERSION \r
457 // to autogen.h file.\r
458 // Note: the specification version and release version should\r
459 // be get from module surface area instead of hard code.\r
460 //\r
461 fileBuffer.append(CommonDefinition.autoGenHbegin);\r
462 fileBuffer.append(CommonDefinition.autoGenHLine1);\r
463 fileBuffer.append(CommonDefinition.autoGenHLine2);\r
464\r
465 //\r
466 // Write consumed package's mdouleInfo related *.h file to autogen.h.\r
467 // \r
468 moduleType = SurfaceAreaQuery.getModuleType();\r
469 List<String> cosumedPkglist = SurfaceAreaQuery\r
470 .getIncludePackageName(this.arch);\r
471 headerFileList = IncludesToAutogenH(cosumedPkglist, moduleType);\r
472 for (int i = 0; i < headerFileList.size(); i++) {\r
473 fileBuffer.append(headerFileList.get(i));\r
474 }\r
475\r
476 //\r
477 // Write library class's related *.h file to autogen.h\r
478 //\r
479 LibraryClass[] libClassList = SurfaceAreaQuery\r
480 .getLibraryClassArray(CommonDefinition.AlwaysConsumed);\r
481 if (libClassList != null) {\r
482 libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
483 for (int i = 0; i < libClassIncludeH.size(); i++) {\r
484 fileBuffer.append(libClassIncludeH.get(i));\r
485 }\r
486 }\r
487\r
488 libClassList = SurfaceAreaQuery\r
489 .getLibraryClassArray(CommonDefinition.AlwaysProduced);\r
490 if (libClassList != null) {\r
491 libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
492 for (int i = 0; i < libClassIncludeH.size(); i++) {\r
493 fileBuffer.append(libClassIncludeH.get(i));\r
494 }\r
495 }\r
496 fileBuffer.append("\r\n");\r
497 \r
498 //\r
499 // Write PCD information to library AutoGen.h.\r
500 //\r
501 if (this.myPcdAutogen != null) {\r
502 fileBuffer.append(this.myPcdAutogen.OutputH());\r
503 }\r
504\r
505 //\r
506 // Append the #endif at AutoGen.h\r
507 //\r
508 fileBuffer.append("#endif\r\n");\r
509 \r
510 //\r
511 // Save content of string buffer to AutoGen.h file.\r
512 //\r
513 if (!saveFile(outputPath + File.separatorChar + "AutoGen.h", fileBuffer)) {\r
514 throw new BuildException("Failed to generate AutoGen.h !!!");\r
515 }\r
516 }\r
517\r
518 /**\r
519 libGenAutogenC\r
520 \r
521 This function generates AutoGen.h for library.\r
522 \r
523 @throws BuildException\r
524 Failed to generate AutoGen.c.\r
525 **/\r
526 void libGenAutogenC() throws BuildException {\r
527 StringBuffer fileBuffer = new StringBuffer(10240);\r
528\r
529 //\r
530 // Write Autogen.c header notation \r
531 //\r
532 fileBuffer.append(CommonDefinition.autogenCNotation);\r
533 \r
534 fileBuffer.append(CommonDefinition.autoGenCLine1);\r
535 fileBuffer.append("\r\n");\r
536\r
537 //\r
538 // Call pcd autogen. PCDAutoGenAction tool only need module name and\r
539 // isPcdEmulatedDriver as parameter. Library inherit PCD and module's\r
540 // PCD information has been collected in FPDParser task by\r
541 // CollectPCDAction. \r
542 // Note : when PCD image tool ready,\r
543 // isPCDEmulatedDriver parameter will be removed.\r
544 //\r
545 try {\r
546 this.myPcdAutogen = new PCDAutoGenAction(baseName, baseName\r
547 .equalsIgnoreCase("PcdEmulatorPeim"));\r
548 this.myPcdAutogen.execute();\r
549 } catch (Exception e) {\r
550 throw new BuildException(e.getMessage());\r
551 }\r
552\r
553 if (this.myPcdAutogen != null) {\r
554 fileBuffer.append(this.myPcdAutogen.OutputC());\r
555 }\r
556\r
557 if (!saveFile(outputPath + File.separatorChar + "AutoGen.c", fileBuffer)) {\r
558 throw new BuildException("Failed to generate AutoGen.c !!!");\r
559 }\r
560 }\r
561\r
562 /**\r
563 LibraryClassToAutogenH\r
564 \r
565 This function returns *.h files declared by library classes which are \r
566 consumed or produced by current build module or library.\r
567 \r
568 @param libClassList List of library class which consumed or produce\r
569 by current build module or library.\r
570 @return includeStrList List of *.h file. \r
571 **/\r
572 List<String> LibraryClassToAutogenH(LibraryClass[] libClassList) {\r
573 List<String> includStrList = new ArrayList<String>();\r
574 String includerName;\r
575 String str = "";\r
576 \r
577 //\r
578 // Get include file from GlobalData's SPDTable according to \r
579 // library class name.\r
580 //\r
581 for (int i = 0; i < libClassList.length; i++) {\r
582 includerName = GlobalData.getLibClassIncluder(libClassList[i]\r
583 .getStringValue());\r
584 if (includerName != null) {\r
585 str = CommonDefinition.include + " " + "<";\r
586 str = str + includerName + ">\r\n";\r
587 includStrList.add(str);\r
588 includerName = null;\r
589 }\r
590 }\r
591 return includStrList;\r
592 }\r
593\r
594 /**\r
595 IncludesToAutogenH\r
596 \r
597 This function add include file in AutoGen.h file.\r
598 @param packageNameList List of module depended package.\r
599 @param moduleType Module type.\r
600 @return \r
601 **/\r
602 List<String> IncludesToAutogenH(List<String> packageNameList,\r
603 String moduleType) {\r
604\r
605 List<String> includeStrList = new ArrayList<String>();\r
606 String packageName = "";\r
607 String includeStr = "";\r
608\r
609 //\r
610 // Get include file from moduleInfo file\r
611 //\r
612 for (int i = 0; i < packageNameList.size(); i++) {\r
613 packageName = packageNameList.get(i);\r
614 includeStr = GlobalData.getModuleInfoByPackageName(packageName,\r
615 moduleType);\r
616 includeStrList.add(includeStr);\r
617 }\r
618 return includeStrList;\r
619 }\r
620\r
621 /**\r
622 EntryPointToAutoGen \r
623 \r
624 This function convert <ModuleEntryPoint> & <ModuleUnloadImage> information\r
625 in mas to AutoGen.c\r
626 \r
627 @param entryPointList List of entry point. \r
628 @param fileBuffer String buffer fo AutoGen.c.\r
629 @throws Exception\r
630 **/\r
631 void EntryPointToAutoGen(String[] entryPointList, StringBuffer fileBuffer)\r
632 throws BuildException {\r
633\r
634 String typeStr = SurfaceAreaQuery.getModuleType();\r
635 \r
636 //\r
637 // The parameters and return value of entryPoint is difference\r
638 // for difference module type.\r
639 //\r
640 switch (CommonDefinition.getModuleType(typeStr)) {\r
641\r
642 case CommonDefinition.ModuleTypePeiCore:\r
643 if (entryPointList.length != 1 || entryPointList[0].equals("")) {\r
644 throw new BuildException(\r
645 "Module type = 'PEI_CORE', only have one module entry point!");\r
646 } else {\r
647 fileBuffer.append("EFI_STATUS\r\n");\r
648 fileBuffer.append("EFIAPI\r\n");\r
649 fileBuffer.append(entryPointList[0]);\r
650 fileBuffer.append(" (\r\n");\r
651 fileBuffer\r
652 .append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n");\r
653 fileBuffer\r
654 .append(" IN VOID *OldCoreData\r\n");\r
655 fileBuffer.append(" );\r\n\r\n");\r
656\r
657 fileBuffer.append("EFI_STATUS\r\n");\r
658 fileBuffer.append("EFIAPI\r\n");\r
659 fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r
660 fileBuffer\r
661 .append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n");\r
662 fileBuffer\r
663 .append(" IN VOID *OldCoreData\r\n");\r
664 fileBuffer.append(" )\r\n\r\n");\r
665 fileBuffer.append("{\r\n");\r
666 fileBuffer.append(" return ");\r
667 fileBuffer.append(entryPointList[0]);\r
668 fileBuffer.append(" (PeiStartupDescriptor, OldCoreData);\r\n");\r
669 fileBuffer.append("}\r\n\r\n");\r
670 }\r
671 break;\r
672\r
673 case CommonDefinition.ModuleTypeDxeCore:\r
674 fileBuffer.append("const UINT32 _gUefiDriverRevision = 0;\r\n");\r
675 if (entryPointList.length != 1 || entryPointList[0].equals("")) {\r
676 throw new BuildException(\r
677 "Module type = 'DXE_CORE', only have one module entry point!");\r
678 } else {\r
679\r
680 fileBuffer.append("VOID\r\n");\r
681 fileBuffer.append("EFIAPI\r\n");\r
682 fileBuffer.append(entryPointList[0]);\r
683 fileBuffer.append(" (\n");\r
684 fileBuffer.append(" IN VOID *HobStart\r\n");\r
685 fileBuffer.append(" );\r\n\r\n");\r
686\r
687 fileBuffer.append("VOID\r\n");\r
688 fileBuffer.append("EFIAPI\r\n");\r
689 fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r
690 fileBuffer.append(" IN VOID *HobStart\r\n");\r
691 fileBuffer.append(" )\r\n\r\n");\r
692 fileBuffer.append("{\r\n");\r
693 fileBuffer.append(" ");\r
694 fileBuffer.append(entryPointList[0]);\r
695 fileBuffer.append(" (HobStart);\r\n");\r
696 fileBuffer.append("}\r\n\r\n");\r
697 }\r
698 break;\r
699\r
700 case CommonDefinition.ModuleTypePeim:\r
701 int entryPointCount = 0;\r
702 fileBuffer\r
703 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = 0;\r\n");\r
704 for (int i = 0; i < entryPointList.length; i++) {\r
705 if (!entryPointList[i].equals("")) {\r
706 fileBuffer.append("EFI_STATUS\r\n");\r
707 fileBuffer.append("EFIAPI\r\n");\r
708 fileBuffer.append(entryPointList[i]);\r
709 fileBuffer.append(" (\r\n");\r
710 fileBuffer\r
711 .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");\r
712 fileBuffer\r
713 .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");\r
714 fileBuffer.append(" );\r\n");\r
715 entryPointCount++;\r
716 } else {\r
717 break;\r
718 }\r
719 }\r
720\r
721 fileBuffer.append("EFI_STATUS\r\n");\r
722 fileBuffer.append("EFIAPI\r\n");\r
723 fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r
724 fileBuffer.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");\r
725 fileBuffer.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");\r
726 fileBuffer.append(" )\r\n\r\n");\r
727 fileBuffer.append("{\r\n");\r
728\r
729 if (entryPointCount == 0) {\r
730 fileBuffer.append(" return EFI_SUCCESS;\r\n");\r
731 } else if (entryPointCount == 1) {\r
732 fileBuffer.append(" return ");\r
733 fileBuffer.append(entryPointList[0]);\r
734 fileBuffer.append(" (FfsHeader, PeiServices);\r\n");\r
735 } else {\r
736 fileBuffer.append(" EFI_STATUS Status;\r\n");\r
737 fileBuffer.append(" EFI_STATUS CombinedStatus;\r\n\r\n");\r
738 fileBuffer.append(" CombinedStatus = EFI_LOAD_ERROR;\r\n\r\n");\r
739 for (int i = 0; i < entryPointList.length; i++) {\r
740 if (!entryPointList[i].equals("")) {\r
741 fileBuffer.append(" Status = ");\r
742 fileBuffer.append(entryPointList[i]);\r
743 fileBuffer.append(" (FfsHeader, PeiServices)\r\n");\r
744 fileBuffer\r
745 .append(" if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {\r\n");\r
746 fileBuffer.append(" CombinedStatus = Status;\r\n");\r
747 fileBuffer.append(" }\r\n\r\n");\r
748 } else {\r
749 break;\r
750 }\r
751 }\r
752 fileBuffer.append(" return CombinedStatus;\r\n");\r
753 }\r
754 fileBuffer.append("}\r\n\r\n");\r
755 break;\r
756\r
757 case CommonDefinition.ModuleTypeDxeSmmDriver:\r
758 entryPointCount = 0;\r
759 for (int i = 0; i < entryPointList.length; i++) {\r
760 if (!entryPointList[i].equals("")) {\r
761 fileBuffer.append("EFI_STATUS\r\n");\r
762 fileBuffer.append("EFIAPI\r\n");\r
763 fileBuffer.append(entryPointList[i]);\r
764 fileBuffer.append(" (\r\n");\r
765 fileBuffer.append(" EFI_HANDLE ImageHandle,\r\n");\r
766 fileBuffer.append(" EFI_SYSTEM_TABLE *SystemTable\r\n");\r
767 fileBuffer.append(" );\r\n");\r
768 entryPointCount++;\r
769 } else {\r
770 break;\r
771 }\r
772 }\r
773 fileBuffer\r
774 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");\r
775 fileBuffer.append(Integer.toString(entryPointCount));\r
776 fileBuffer.append(";\r\n");\r
777 fileBuffer\r
778 .append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");\r
779 fileBuffer\r
780 .append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n\r\n");\r
781\r
782 fileBuffer.append("EFI_STATUS\r\n");\r
783 fileBuffer.append("EFIAPI\r\n");\r
784 fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r
785 fileBuffer.append(" EFI_HANDLE ImageHandle,\r\n");\r
786 fileBuffer.append(" EFI_SYSTEM_TABLE *SystemTable\r\n");\r
787 fileBuffer.append(" )\r\n\r\n");\r
788 fileBuffer.append("{\r\n");\r
789\r
790 for (int i = 0; i < entryPointList.length; i++) {\r
791 if (!entryPointList[i].equals("")) {\r
792 fileBuffer\r
793 .append(" if (SetJump (&mJumpContext) == 0) {\r\n");\r
794 fileBuffer.append(" ExitDriver (");\r
795 fileBuffer.append(entryPointList[i]);\r
796 fileBuffer.append(" (ImageHandle, SystemTable));\r\n");\r
797 fileBuffer.append(" ASSERT (FALSE);\r\n");\r
798 fileBuffer.append(" }\r\n");\r
799 } else {\r
800 break;\r
801 }\r
802 }\r
803 fileBuffer.append(" return mDriverEntryPointStatus;\r\n");\r
804 fileBuffer.append("}\r\n\r\n");\r
805\r
806 fileBuffer.append("VOID\r\n");\r
807 fileBuffer.append("EFIAPI\r\n");\r
808 fileBuffer.append("ExitDriver (\r\n");\r
809 fileBuffer.append(" IN EFI_STATUS Status\n");\r
810 fileBuffer.append(" )\r\n\r\n");\r
811 fileBuffer.append("{\r\n");\r
812 fileBuffer\r
813 .append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");\r
814 fileBuffer.append(" mDriverEntryPointStatus = Status;\r\n");\r
815 fileBuffer.append(" }\r\n");\r
816 fileBuffer.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");\r
817 fileBuffer.append(" ASSERT (FALSE);\r\n");\r
818 fileBuffer.append("}\r\n\r\n");\r
819\r
820 //\r
821 // Add "ModuleUnloadImage" for DxeSmmDriver module type;\r
822 //\r
823 entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();\r
824 entryPointCount = 0;\r
825 if (entryPointList != null) {\r
826 for (int i = 0; i < entryPointList.length; i++) {\r
827 if (!entryPointList[i].equals("")) {\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(" EFI_HANDLE ImageHandle\r\n");\r
834 fileBuffer.append(" );\r\n");\r
835 entryPointCount++;\r
836 } else {\r
837 break;\r
838 }\r
839 }\r
840 }\r
841\r
842 fileBuffer\r
843 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");\r
844 fileBuffer.append(Integer.toString(entryPointCount));\r
845 fileBuffer.append(";\r\n\r\n");\r
846\r
847 if (entryPointList != null) {\r
848 for (int i = 0; i < entryPointList.length; i++) {\r
849 if (!entryPointList[i].equals("")) {\r
850 fileBuffer.append("EFI_STATUS\r\n");\r
851 fileBuffer.append("EFIAPI\r\n");\r
852 fileBuffer.append(entryPointList[i]);\r
853 fileBuffer.append(" (\r\n");\r
854 fileBuffer\r
855 .append(" EFI_HANDLE ImageHandle\r\n");\r
856 fileBuffer.append(" );\r\n");\r
857 } else {\r
858 break;\r
859 }\r
860 }\r
861 }\r
862\r
863 fileBuffer.append("EFI_STATUS\r\n");\r
864 fileBuffer.append("EFIAPI\r\n");\r
865 fileBuffer.append("ProcessModuleUnloadList (\r\n");\r
866 fileBuffer.append(" EFI_HANDLE ImageHandle\r\n");\r
867 fileBuffer.append(" )\r\n");\r
868 fileBuffer.append("{\r\n");\r
869\r
870 if (entryPointCount == 0) {\r
871 fileBuffer.append(" return EFI_SUCCESS;\r\n");\r
872 } else if (entryPointCount == 1) {\r
873 fileBuffer.append(" return ");\r
874 fileBuffer.append(entryPointList[0]);\r
875 fileBuffer.append("(ImageHandle);\r\n");\r
876 } else {\r
877 fileBuffer.append(" EFI_STATUS Status;\r\n\r\n");\r
878 fileBuffer.append(" Status = EFI_SUCCESS;\r\n\r\n");\r
879 for (int i = 0; i < entryPointList.length; i++) {\r
880 if (!entryPointList[i].equals("")) {\r
881 fileBuffer.append(" if (EFI_ERROR (Status)) {\r\n");\r
882 fileBuffer.append(" ");\r
883 fileBuffer.append(entryPointList[i]);\r
884 fileBuffer.append("(ImageHandle);\r\n");\r
885 fileBuffer.append(" } else {\r\n");\r
886 fileBuffer.append(" Status = ");\r
887 fileBuffer.append(entryPointList[i]);\r
888 fileBuffer.append("(ImageHandle);\r\n");\r
889 fileBuffer.append(" }\r\n");\r
890 } else {\r
891 break;\r
892 }\r
893 }\r
894 fileBuffer.append(" return Status;\r\n");\r
895 }\r
896 fileBuffer.append("}\r\n\r\n");\r
897 break;\r
898\r
899 case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
900 case CommonDefinition.ModuleTypeDxeDriver:\r
901 case CommonDefinition.ModuleTypeDxeSalDriver:\r
902 case CommonDefinition.ModuleTypeUefiDriver:\r
903 case CommonDefinition.ModuleTypeUefiApplication:\r
904 entryPointCount = 0;\r
905 fileBuffer.append("const UINT32 _gUefiDriverRevision = 0;\r\n");\r
906 for (int i = 0; i < entryPointList.length; i++) {\r
907 if (!entryPointList[i].equals("")) {\r
908 fileBuffer.append("EFI_STATUS\r\n");\r
909 fileBuffer.append("EFIAPI\r\n");\r
910 fileBuffer.append(entryPointList[i]);\r
911 fileBuffer.append(" (\r\n");\r
912 fileBuffer.append(" EFI_HANDLE ImageHandle,\r\n");\r
913 fileBuffer.append(" EFI_SYSTEM_TABLE *SystemTable\r\n");\r
914 fileBuffer.append(" );\r\n");\r
915 entryPointCount++;\r
916 } else {\r
917 break;\r
918 }\r
919 }\r
920\r
921 fileBuffer\r
922 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");\r
923 fileBuffer.append(Integer.toString(entryPointCount));\r
924 fileBuffer.append(";\r\n");\r
925 if (entryPointCount > 1) {\r
926 fileBuffer\r
927 .append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");\r
928 fileBuffer\r
929 .append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n");\r
930 }\r
931 fileBuffer.append("\n");\r
932\r
933 fileBuffer.append("EFI_STATUS\r\n");\r
934 fileBuffer.append("EFIAPI\r\n");\r
935 fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r
936 fileBuffer.append(" EFI_HANDLE ImageHandle,\r\n");\r
937 fileBuffer.append(" EFI_SYSTEM_TABLE *SystemTable\r\n");\r
938 fileBuffer.append(" )\r\n\r\n");\r
939 fileBuffer.append("{\r\n");\r
940\r
941 if (entryPointCount == 0) {\r
942 fileBuffer.append(" return EFI_SUCCESS;\r\n");\r
943 } else if (entryPointCount == 1) {\r
944 fileBuffer.append(" return (");\r
945 fileBuffer.append(entryPointList[0]);\r
946 fileBuffer.append(" (ImageHandle, SystemTable));\r\n");\r
947 } else {\r
948 for (int i = 0; i < entryPointList.length; i++) {\r
949 if (!entryPointList[i].equals("")) {\r
950 fileBuffer\r
951 .append(" if (SetJump (&mJumpContext) == 0) {\r\n");\r
952 fileBuffer.append(" ExitDriver (");\r
953 fileBuffer.append(entryPointList[i]);\r
954 fileBuffer.append(" (ImageHandle, SystemTable));\r\n");\r
955 fileBuffer.append(" ASSERT (FALSE);\r\n");\r
956 fileBuffer.append(" }\r\n");\r
957 } else {\r
958 break;\r
959 }\r
960 }\r
961 fileBuffer.append(" return mDriverEntryPointStatus;\r\n");\r
962 }\r
963 fileBuffer.append("}\r\n\r\n");\r
964\r
965 fileBuffer.append("VOID\n");\r
966 fileBuffer.append("EFIAPI\n");\r
967 fileBuffer.append("ExitDriver (\r\n");\r
968 fileBuffer.append(" IN EFI_STATUS Status\n");\r
969 fileBuffer.append(" )\r\n\r\n");\r
970 fileBuffer.append("{\r\n");\r
971 if (entryPointCount <= 1) {\r
972 fileBuffer.append(" if (EFI_ERROR (Status)) {\r\n");\r
973 fileBuffer\r
974 .append(" ProcessLibraryDestructorList (gImageHandle, gST);\r\n");\r
975 fileBuffer.append(" }\r\n");\r
976 fileBuffer\r
977 .append(" gBS->Exit (gImageHandle, Status, 0, NULL);\r\n");\r
978 } else {\r
979 fileBuffer\r
980 .append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");\r
981 fileBuffer.append(" mDriverEntryPointStatus = Status;\r\n");\r
982 fileBuffer.append(" }\r\n");\r
983 fileBuffer.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");\r
984 fileBuffer.append(" ASSERT (FALSE);\r\n");\r
985 }\r
986 fileBuffer.append("}\r\n\r\n");\r
987\r
988 //\r
989 // Add ModuleUnloadImage for DxeDriver and UefiDriver module type.\r
990 //\r
991 entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();\r
992 entryPointCount = 0;\r
993 if (entryPointList != null) {\r
994 for (int i = 0; i < entryPointList.length; i++) {\r
995 if (!entryPointList[i].equals("")) {\r
996 fileBuffer.append("EFI_STATUS\r\n");\r
997 fileBuffer.append("EFIAPI\r\n");\r
998 fileBuffer.append(entryPointList[i]);\r
999 fileBuffer.append(" (\r\n");\r
1000 fileBuffer\r
1001 .append(" EFI_HANDLE ImageHandle\r\n");\r
1002 fileBuffer.append(" );\r\n");\r
1003 entryPointCount++;\r
1004 } else {\r
1005 break;\r
1006 }\r
1007 }\r
1008 }\r
1009\r
1010 fileBuffer\r
1011 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");\r
1012 fileBuffer.append(Integer.toString(entryPointCount));\r
1013 fileBuffer.append(";\r\n\r\n");\r
1014\r
1015 if (entryPointList != null) {\r
1016 for (int i = 0; i < entryPointList.length; i++) {\r
1017 if (!entryPointList[i].equals("")) {\r
1018 fileBuffer.append("EFI_STATUS\r\n");\r
1019 fileBuffer.append("EFIAPI\r\n");\r
1020 fileBuffer.append(entryPointList[i]);\r
1021 fileBuffer.append(" (\r\n");\r
1022 fileBuffer\r
1023 .append(" EFI_HANDLE ImageHandle\r\n");\r
1024 fileBuffer.append(" );\r\n");\r
1025 } else {\r
1026 break;\r
1027 }\r
1028 }\r
1029 }\r
1030\r
1031 fileBuffer.append("EFI_STATUS\n");\r
1032 fileBuffer.append("EFIAPI\n");\r
1033 fileBuffer.append("ProcessModuleUnloadList (\r\n");\r
1034 fileBuffer.append(" EFI_HANDLE ImageHandle\r\n");\r
1035 fileBuffer.append(" )\r\n");\r
1036 fileBuffer.append("{\r\n");\r
1037\r
1038 if (entryPointCount == 0) {\r
1039 fileBuffer.append(" return EFI_SUCCESS;\r\n");\r
1040 } else if (entryPointCount == 1) {\r
1041 fileBuffer.append(" return ");\r
1042 fileBuffer.append(entryPointList[0]);\r
1043 fileBuffer.append("(ImageHandle);\r\n");\r
1044 } else {\r
1045 fileBuffer.append(" EFI_STATUS Status;\r\n\r\n");\r
1046 fileBuffer.append(" Status = EFI_SUCCESS;\r\n\r\n");\r
1047 for (int i = 0; i < entryPointList.length; i++) {\r
1048 if (!entryPointList[i].equals("")) {\r
1049 fileBuffer.append(" if (EFI_ERROR (Status)) {\r\n");\r
1050 fileBuffer.append(" ");\r
1051 fileBuffer.append(entryPointList[i]);\r
1052 fileBuffer.append("(ImageHandle);\r\n");\r
1053 fileBuffer.append(" } else {\r\n");\r
1054 fileBuffer.append(" Status = ");\r
1055 fileBuffer.append(entryPointList[i]);\r
1056 fileBuffer.append("(ImageHandle);\r\n");\r
1057 fileBuffer.append(" }\r\n");\r
1058 } else {\r
1059 break;\r
1060 }\r
1061 }\r
1062 fileBuffer.append(" return Status;\r\n");\r
1063 }\r
1064 fileBuffer.append("}\r\n\r\n");\r
1065 break;\r
1066 }\r
1067 }\r
1068\r
1069 /**\r
1070 PpiGuidToAutogenc \r
1071 \r
1072 This function gets GUIDs from SPD file accrodeing to <PPIs> information and \r
1073 write those GUIDs to AutoGen.c.\r
1074 \r
1075 @param fileBuffer String Buffer for Autogen.c file.\r
1076 @throws BuildException Guid must set value!\r
1077 **/\r
1078 void PpiGuidToAutogenC(StringBuffer fileBuffer) throws BuildException {\r
1079 String[] cNameGuid = null;\r
1080 boolean isEqual = false;\r
1081\r
1082 PPIsDocument.PPIs.Ppi[] ppiList = SurfaceAreaQuery.getPpiArray(null);\r
1083 if (ppiList != null) {\r
1084 for (int i = 0; i < ppiList.length; i++) {\r
1085 isEqual = false;\r
1086 for (int j = 0; j < this.mPpiList.size(); j++) {\r
1087 if (this.mPpiList.get(j).equalsIgnoreCase(\r
1088 ppiList[i].getStringValue())) {\r
1089 isEqual = true;\r
1090 }\r
1091 }\r
1092 if (!isEqual) {\r
1093 this.mPpiList.add(ppiList[i].getStringValue());\r
1094 }\r
1095 }\r
1096 }\r
1097\r
1098 PPIsDocument.PPIs.PpiNotify[] ppiNotifyList = SurfaceAreaQuery\r
1099 .getPpiNotifyArray(null);\r
1100 if (ppiNotifyList != null) {\r
1101 for (int i = 0; i < ppiNotifyList.length; i++) {\r
1102 isEqual = false;\r
1103 for (int j = 0; j < this.mPpiList.size(); j++) {\r
1104 if (this.mPpiList.get(j).equalsIgnoreCase(\r
1105 ppiNotifyList[i].getStringValue())) {\r
1106 isEqual = true;\r
1107 }\r
1108 }\r
1109 if (!isEqual) {\r
1110 this.mPpiList.add(ppiNotifyList[i].getStringValue());\r
1111 }\r
1112 }\r
1113 }\r
1114\r
1115 for (int i = 0; i < this.mPpiList.size(); i++) {\r
1116 if (this.mPpiList.get(i) != null) {\r
1117 cNameGuid = GlobalData.getPpiInfoGuid(this.mPpiList.get(i));\r
1118 if (cNameGuid != null) {\r
1119 fileBuffer\r
1120 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r
1121 fileBuffer.append(cNameGuid[0]);\r
1122 fileBuffer.append(" = { ");\r
1123 fileBuffer.append(cNameGuid[1]);\r
1124 fileBuffer.append(" } ;");\r
1125 }\r
1126 } else {\r
1127 throw new BuildException("Guid must set value!");\r
1128 }\r
1129 }\r
1130 }\r
1131\r
1132 /**\r
1133 ProtocolGuidToAutogenc \r
1134 \r
1135 This function gets GUIDs from SPD file accrodeing to <Protocol> \r
1136 information and write those GUIDs to AutoGen.c.\r
1137 \r
1138 @param fileBuffer String Buffer for Autogen.c file.\r
1139 @throws BuildException Protocol name must set.\r
1140 **/\r
1141 void ProtocolGuidToAutogenC(StringBuffer fileBuffer) throws BuildException {\r
1142 String[] cNameGuid = null;\r
1143 boolean isEqual = false;\r
1144\r
1145 ProtocolsDocument.Protocols.Protocol[] protocolList = SurfaceAreaQuery\r
1146 .getProtocolArray(null);\r
1147 if (protocolList != null) {\r
1148 for (int i = 0; i < protocolList.length; i++) {\r
1149 isEqual = false;\r
1150 for (int j = 0; j < this.mProtocolList.size(); j++) {\r
1151 if (this.mProtocolList.get(j).equalsIgnoreCase(\r
1152 protocolList[i].getStringValue())) {\r
1153 isEqual = true;\r
1154 }\r
1155 }\r
1156 if (!isEqual) {\r
1157 this.mProtocolList.add(protocolList[i].getStringValue());\r
1158\r
1159 }\r
1160 }\r
1161 }\r
1162\r
1163 ProtocolsDocument.Protocols.ProtocolNotify[] protocolNotifyList = SurfaceAreaQuery\r
1164 .getProtocolNotifyArray(null);\r
1165 if (protocolNotifyList != null) {\r
1166 for (int i = 0; i < protocolNotifyList.length; i++) {\r
1167 isEqual = false;\r
1168 for (int j = 0; j < this.mProtocolList.size(); j++) {\r
1169 if (this.mProtocolList.get(j).equalsIgnoreCase(\r
1170 protocolNotifyList[i].getStringValue())) {\r
1171 isEqual = true;\r
1172 }\r
1173 }\r
1174 if (!isEqual) {\r
1175 this.mProtocolList.add(protocolNotifyList[i]\r
1176 .getStringValue());\r
1177\r
1178 }\r
1179 }\r
1180 }\r
1181 if (this.mProtocolList.size() > 0) {\r
1182 for (int i = 0; i < this.mProtocolList.size(); i++) {\r
1183 if (this.mProtocolList.get(i) != null) {\r
1184 cNameGuid = GlobalData\r
1185 .getProtocolInfoGuid(this.mProtocolList.get(i));\r
1186 if (cNameGuid != null) {\r
1187 fileBuffer\r
1188 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r
1189 fileBuffer.append(cNameGuid[0]);\r
1190 fileBuffer.append(" = { ");\r
1191 fileBuffer.append(cNameGuid[1]);\r
1192 fileBuffer.append(" } ;");\r
1193 }\r
1194 } else {\r
1195 throw new BuildException("Protocol name must set!");\r
1196 }\r
1197 }\r
1198 }\r
1199 }\r
1200\r
1201 /**\r
1202 GuidGuidToAutogenc\r
1203 \r
1204 This function gets GUIDs from SPD file accrodeing to <Guids> information\r
1205 and write those GUIDs to AutoGen.c.\r
1206 \r
1207 @param fileBuffer String Buffer for Autogen.c file.\r
1208 \r
1209 **/\r
1210 void GuidGuidToAutogenC(StringBuffer fileBuffer) {\r
1211 String[] cNameGuid = null;\r
1212 boolean isEqual = false;\r
1213 GuidsDocument.Guids.GuidEntry[] guidList = SurfaceAreaQuery\r
1214 .getGuidEntryArray(null);\r
1215\r
1216 if (guidList != null) {\r
1217 for (int i = 0; i < guidList.length; i++) {\r
1218 for (int j = 0; j < this.mGuidList.size(); j++) {\r
1219 isEqual = false;\r
1220 if (this.mGuidList.get(j).getCName().equalsIgnoreCase(\r
1221 guidList[i].getCName().toString())) {\r
1222 isEqual = true;\r
1223 break;\r
1224 }\r
1225 }\r
1226 if (!isEqual) {\r
1227 this.mGuidList.add(guidList[i]);\r
1228\r
1229 }\r
1230\r
1231 }\r
1232 }\r
1233\r
1234 for (int i = 0; i < this.mGuidList.size(); i++) {\r
1235 if (this.mGuidList.get(i).getCName() != null) {\r
1236 cNameGuid = GlobalData.getGuidInfoGuid(this.mGuidList.get(i)\r
1237 .getCName());\r
1238 if (cNameGuid != null) {\r
1239 fileBuffer\r
1240 .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r
1241 fileBuffer.append(cNameGuid[0]);\r
1242 fileBuffer.append(" = { ");\r
1243 fileBuffer.append(cNameGuid[1]);\r
1244 fileBuffer.append("} ;");\r
1245 }\r
1246 }\r
1247 }\r
1248 }\r
1249\r
1250 /**\r
1251 LibInstanceToAutogenC\r
1252 \r
1253 This function adds dependent library instance to autogen.c,which includeing \r
1254 library's constructor, destructor, and library dependent ppi, protocol, guid,\r
1255 pcd information.\r
1256 \r
1257 @param fileBuffer String buffer for AutoGen.c\r
1258 @throws BuildException \r
1259 **/\r
1260 void LibInstanceToAutogenC(StringBuffer fileBuffer) throws BuildException {\r
1261 int index;\r
1262 boolean isEqual = false;\r
1263\r
1264 String moduleType = SurfaceAreaQuery.getModuleType();\r
1265 List<String> libConstructList = new ArrayList<String>();\r
1266 List<String> libDestructList = new ArrayList<String>();\r
1267\r
1268 String libConstructName = null;\r
1269 String libDestructName = null;\r
1270 List<String> libraryList = SurfaceAreaQuery.getLibraryInstance(\r
1271 this.arch, CommonDefinition.AlwaysConsumed);\r
1272\r
1273 try {\r
1274 if (libraryList != null) {\r
1275 //\r
1276 // Reorder library instance sequence.\r
1277 //\r
1278 AutogenLibOrder libOrder = new AutogenLibOrder(libraryList);\r
1279 List orderList = libOrder.orderLibInstance();\r
1280 \r
1281 if (orderList != null) {\r
1282 //\r
1283 // Process library instance one by one.\r
1284 //\r
1285 for (int i = 0; i < orderList.size(); i++) {\r
1286 \r
1287 //\r
1288 // Get library instance basename.\r
1289 //\r
1290 String libInstanceName = orderList.get(i).toString();\r
1291 \r
1292 //\r
1293 // Get override map\r
1294 //\r
1295 Map<String, XmlObject> libDoc = GlobalData\r
1296 .getDoc(libInstanceName);\r
1297 SurfaceAreaQuery.push(libDoc);\r
1298 \r
1299 //\r
1300 // Get <PPis>, <Protocols>, <Guids> list of this library\r
1301 // instance.\r
1302 //\r
1303 PPIsDocument.PPIs.Ppi[] ppiList = SurfaceAreaQuery\r
1304 .getPpiArray(null);\r
1305 PPIsDocument.PPIs.PpiNotify[] ppiNotifyList = SurfaceAreaQuery\r
1306 .getPpiNotifyArray(null);\r
1307 ProtocolsDocument.Protocols.Protocol[] protocolList = SurfaceAreaQuery\r
1308 .getProtocolArray(null);\r
1309 ProtocolsDocument.Protocols.ProtocolNotify[] protocolNotifyList = SurfaceAreaQuery\r
1310 .getProtocolNotifyArray(null);\r
1311 GuidsDocument.Guids.GuidEntry[] guidList = SurfaceAreaQuery\r
1312 .getGuidEntryArray(null);\r
1313\r
1314 //\r
1315 // Add those ppi, protocol, guid in global ppi, protocol, guid\r
1316 // list.\r
1317 //\r
1318 if (ppiList != null) {\r
1319 for (index = 0; index < ppiList.length; index++) {\r
1320 isEqual = false;\r
1321 for (int j = 0; j < this.mPpiList.size(); j++) {\r
1322 if (this.mPpiList.get(j).equalsIgnoreCase(\r
1323 ppiList[index].getStringValue())) {\r
1324 isEqual = true;\r
1325 }\r
1326 }\r
1327 if (!isEqual) {\r
1328 this.mPpiList.add(ppiList[index]\r
1329 .getStringValue());\r
1330 }\r
1331 }\r
1332 }\r
1333 if (ppiNotifyList != null) {\r
1334 for (index = 0; index < ppiNotifyList.length; index++) {\r
1335 isEqual = false;\r
1336 for (int j = 0; j < this.mPpiList.size(); j++) {\r
1337 if (this.mPpiList.get(j).equalsIgnoreCase(\r
1338 ppiNotifyList[index]\r
1339 .getStringValue())) {\r
1340 isEqual = true;\r
1341 }\r
1342 }\r
1343 if (!isEqual) {\r
1344 this.mPpiList.add(ppiNotifyList[index]\r
1345 .getStringValue());\r
1346 }\r
1347 }\r
1348 }\r
1349 if (protocolList != null) {\r
1350 for (index = 0; index < protocolList.length; index++) {\r
1351 isEqual = false;\r
1352 for (int j = 0; j < this.mProtocolList.size(); j++) {\r
1353 if (this.mProtocolList.get(j)\r
1354 .equalsIgnoreCase(\r
1355 protocolList[index]\r
1356 .getStringValue())) {\r
1357 isEqual = true;\r
1358 }\r
1359 }\r
1360 if (!isEqual) {\r
1361 this.mProtocolList.add(protocolList[index]\r
1362 .getStringValue());\r
1363 }\r
1364 }\r
1365 }\r
1366 if (protocolNotifyList != null) {\r
1367 for (index = 0; index < protocolNotifyList.length; index++) {\r
1368 isEqual = false;\r
1369 for (int j = 0; j < this.mProtocolList.size(); j++) {\r
1370 if (this.mProtocolList.get(j)\r
1371 .equalsIgnoreCase(\r
1372 protocolNotifyList[index]\r
1373 .getStringValue())) {\r
1374 isEqual = true;\r
1375 }\r
1376 }\r
1377 if (!isEqual) {\r
1378 this.mProtocolList\r
1379 .add(protocolNotifyList[index]\r
1380 .getStringValue());\r
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
2006}