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