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