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