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