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