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