X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;ds=sidebyside;f=Tools%2FJava%2FSource%2FGenBuild%2Forg%2Ftianocore%2Fbuild%2Fautogen%2FAutoGen.java;h=ad69f07c132f67a73aacca9387f230a214a7e1a8;hb=18f95092d6bf694adf5ad9e7a1e8036d19ed3c8d;hp=68254e2294743f46df920326c8ca33bddc68228e;hpb=e425f0733437eb9297b84611e91e97ae41bbf270;p=mirror_edk2.git diff --git a/Tools/Java/Source/GenBuild/org/tianocore/build/autogen/AutoGen.java b/Tools/Java/Source/GenBuild/org/tianocore/build/autogen/AutoGen.java index 68254e2294..ad69f07c13 100644 --- a/Tools/Java/Source/GenBuild/org/tianocore/build/autogen/AutoGen.java +++ b/Tools/Java/Source/GenBuild/org/tianocore/build/autogen/AutoGen.java @@ -82,22 +82,10 @@ public class AutoGen { private CommonDefinition.PCD_DRIVER_TYPE pcdDriverType; /// - /// The protocl list which records in module or library surface area and - /// it's dependence on library instance surface area. + /// The Guid CName list which recoreded in module or library surface area + /// and it's dependence on library instance surface area. /// - private Set mProtocolList = new HashSet(); - - /// - /// The Ppi list which recorded in module or library surface area and its - /// dependency on library instance surface area. - /// - private Set mPpiList = new HashSet(); - - /// - /// The Guid list which recoreded in module or library surface area and it's - /// dependence on library instance surface area. - /// - private Set mGuidList = new HashSet(); + private Set mGuidCNameList = new HashSet(); /// /// The dependence package list which recoreded in module or library surface @@ -119,17 +107,20 @@ public class AutoGen { private List setVirtalAddList = new ArrayList(); private List exitBootServiceList = new ArrayList(); + private StringBuffer functionDeclarations = new StringBuffer(10240); + private StringBuffer globalDeclarations = new StringBuffer(10240); + // // flag of PcdComponentNameDisable, PcdDriverDiagnosticDisable // private boolean componentNamePcd = false; private boolean driverDiagnostPcd = false; - + // // Instance of SurfaceAreaQuery // private SurfaceAreaQuery saq = null; - + private ModuleIdentification parentId = null; /** @@ -169,7 +160,7 @@ public class AutoGen { "false" failed **/ private boolean saveFile(String fileName, StringBuffer fileBuffer) { - + File autoGenH = new File(fileName); // @@ -183,9 +174,9 @@ public class AutoGen { fIn.close(); } catch (IOException e) { EdkLog.log(EdkLog.EDK_INFO, this.moduleId.getName() - + "'s " - + fileName - + " is exist, but can't be open!!"); + + "'s " + + fileName + + " is exist, but can't be open!!"); return false; } @@ -197,7 +188,7 @@ public class AutoGen { return true; } } - + try { FileWriter fOut = new FileWriter(autoGenH); fOut.write(fileBuffer.toString()); @@ -205,11 +196,11 @@ public class AutoGen { fOut.close(); } catch (IOException e) { EdkLog.log(EdkLog.EDK_INFO, this.moduleId.getName() - + "'s " - + fileName - + " can't be create!!"); + + "'s " + + fileName + + " can't be create!!"); return false; - } + } return true; } @@ -228,7 +219,7 @@ public class AutoGen { // File path = new File(outputPath); path.mkdirs(); - + // // Check current is library or not, then call the corresponding // function. @@ -249,8 +240,8 @@ public class AutoGen { Faile to create module AutoGen.c & AutoGen.h. **/ void moduleGenAutogen() throws EdkException { - setPcdComponentName(); - setPcdDriverDiagnostic(); + setPcdComponentName(); + setPcdDriverDiagnostic(); collectLibInstanceInfo(); moduleGenAutogenC(); moduleGenAutogenH(); @@ -296,14 +287,14 @@ public class AutoGen { // #def ${BseeName}_AUTOGENH // fileBuffer.append(CommonDefinition.IFNDEF - + CommonDefinition.AUTOGENH - + this.moduleId.getGuid().replaceAll("-", "_") - + ToolDefinitions.LINE_SEPARATOR); + + CommonDefinition.AUTOGENH + + this.moduleId.getGuid().replaceAll("-", "_") + + ToolDefinitions.LINE_SEPARATOR); fileBuffer.append(CommonDefinition.DEFINE - + CommonDefinition.AUTOGENH - + this.moduleId.getGuid().replaceAll("-", "_") - + ToolDefinitions.LINE_SEPARATOR - + ToolDefinitions.LINE_SEPARATOR); + + CommonDefinition.AUTOGENH + + this.moduleId.getGuid().replaceAll("-", "_") + + ToolDefinitions.LINE_SEPARATOR + + ToolDefinitions.LINE_SEPARATOR); // // Write the specification version and release version at the begine @@ -345,23 +336,37 @@ public class AutoGen { // // Write library class's related *.h file to autogen.h. // - String[] libClassList = saq.getLibraryClasses(CommonDefinition.ALWAYSCONSUMED,this.arch); - if (libClassList != null) { - libClassIncludeH = LibraryClassToAutogenH(libClassList); - item = libClassIncludeH.iterator(); - while (item.hasNext()) { - fileBuffer.append(item.next().toString()); - } + List libClasses = new ArrayList(100); + String[] libClassList = saq.getLibraryClasses(CommonDefinition.ALWAYSCONSUMED, this.arch, null); + for (int i = 0; i < libClassList.length; ++i) { + libClasses.add(libClassList[i]); } - libClassList = saq.getLibraryClasses(CommonDefinition.ALWAYSPRODUCED, this.arch); - if (libClassList != null) { - libClassIncludeH = LibraryClassToAutogenH(libClassList); - item = libClassIncludeH.iterator(); - while (item.hasNext()) { - fileBuffer.append(item.next().toString()); + libClassList = saq.getLibraryClasses(CommonDefinition.ALWAYSPRODUCED, this.arch, null); + for (int i = 0; i < libClassList.length; ++i) { + libClasses.add(libClassList[i]); + } + // + // Add AutoGen used library class + // + int moduleTypeId = CommonDefinition.getModuleType(moduleType); + if (!libClasses.contains("DebugLib") && moduleTypeId != CommonDefinition.ModuleTypeUnknown + && moduleTypeId != CommonDefinition.ModuleTypeBase) { + libClasses.add("DebugLib"); + } + switch (moduleTypeId) { + case CommonDefinition.ModuleTypeDxeDriver: + case CommonDefinition.ModuleTypeDxeRuntimeDriver: + case CommonDefinition.ModuleTypeDxeSalDriver: + case CommonDefinition.ModuleTypeDxeSmmDriver: + case CommonDefinition.ModuleTypeUefiDriver: + case CommonDefinition.ModuleTypeUefiApplication: + if (!libClasses.contains("UefiBootServicesTableLib")) { + libClasses.add("UefiBootServicesTableLib"); } + break; } + LibraryClassToAutogenH(fileBuffer, libClasses.toArray(new String[libClasses.size()])); fileBuffer.append("\r\n"); // @@ -382,6 +387,8 @@ public class AutoGen { fileBuffer.append(this.myPcdAutogen.getHAutoGenString()); } + fileBuffer.append(globalDeclarations); + fileBuffer.append(functionDeclarations); // // Append the #endif at AutoGen.h // @@ -411,11 +418,6 @@ public class AutoGen { // fileBuffer.append(CommonDefinition.AUTOGENCNOTATION); - // - // Write #include at beginning of AutoGen.c - // - fileBuffer.append(CommonDefinition.INCLUDEAUTOGENH); - // // Get the native MSA file infomation. Since before call autogen, // the MSA native information were overrided. So before @@ -428,8 +430,9 @@ public class AutoGen { // DriverBinding/ComponentName/DriverConfiguration/DriverDialog // to AutoGen.c // - - ExternsDriverBindingToAutoGenC(fileBuffer); + if (!moduleId.getModuleType().equalsIgnoreCase("UEFI_APPLICATION")) { + ExternsDriverBindingToAutoGenC(fileBuffer); + } // // Write DriverExitBootServicesEvent/DriverSetVirtualAddressMapEvent @@ -443,8 +446,8 @@ public class AutoGen { String[] entryPointList = saq.getModuleEntryPointArray(); String[] unloadImageList = saq.getModuleUnloadImageArray(); EntryPointToAutoGen(CommonDefinition.remDupString(entryPointList), - CommonDefinition.remDupString(unloadImageList), - fileBuffer); + CommonDefinition.remDupString(unloadImageList), + fileBuffer); pcdDriverType = saq.getPcdDriverType(); @@ -458,13 +461,13 @@ public class AutoGen { // String guid = CommonDefinition.formatGuidName(saq.getModuleGuid()); if (this.moduleId.getModuleType().equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) { - fileBuffer - .append("GLOBAL_REMOVE_IF_UNREFERENCED GUID gEfiCallerIdGuid = {"); - } else { - fileBuffer - .append("GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiCallerIdGuid = {"); - } - + globalDeclarations.append("extern GUID gEfiCallerIdGuid;\r\n"); + fileBuffer.append("GLOBAL_REMOVE_IF_UNREFERENCED GUID gEfiCallerIdGuid = {"); + } else if (!this.moduleId.getModuleType().equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_USER_DEFINED)) { + globalDeclarations.append("extern EFI_GUID gEfiCallerIdGuid;\r\n"); + fileBuffer.append("GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiCallerIdGuid = {"); + } + if (guid == null) { throw new AutoGenException("Guid value must set!\n"); } @@ -498,11 +501,9 @@ public class AutoGen { } // - // Write consumed ppi, guid, protocol to autogen.c + // Write consumed ppi, guid, protocol, etc to autogen.c // - ProtocolGuidToAutogenC(fileBuffer); - PpiGuidToAutogenC(fileBuffer); - GuidGuidToAutogenC(fileBuffer); + CNameToAutogenC(fileBuffer); // // Call pcd autogen. @@ -513,7 +514,7 @@ public class AutoGen { null, pcdDriverType, parentId); - + this.myPcdAutogen.execute(); if (this.myPcdAutogen != null) { fileBuffer.append("\r\n"); @@ -552,14 +553,14 @@ public class AutoGen { // #def ${BseeName}_AUTOGENH // fileBuffer.append(CommonDefinition.IFNDEF - + CommonDefinition.AUTOGENH - + this.moduleId.getGuid().replaceAll("-", "_") - + ToolDefinitions.LINE_SEPARATOR); + + CommonDefinition.AUTOGENH + + this.moduleId.getGuid().replaceAll("-", "_") + + ToolDefinitions.LINE_SEPARATOR); fileBuffer.append(CommonDefinition.DEFINE - + CommonDefinition.AUTOGENH - + this.moduleId.getGuid().replaceAll("-", "_") - + ToolDefinitions.LINE_SEPARATOR - + ToolDefinitions.LINE_SEPARATOR); + + CommonDefinition.AUTOGENH + + this.moduleId.getGuid().replaceAll("-", "_") + + ToolDefinitions.LINE_SEPARATOR + + ToolDefinitions.LINE_SEPARATOR); // // Write EFI_SPECIFICATION_VERSION and EDK_RELEASE_VERSION @@ -570,8 +571,7 @@ public class AutoGen { fileBuffer.append(CommonDefinition.AUTOGENHBEGIN); String[] specList = saq.getExternSpecificaiton(); for (int i = 0; i < specList.length; i++) { - fileBuffer.append(CommonDefinition.DEFINE + specList[i] - + "\r\n"); + fileBuffer.append(CommonDefinition.DEFINE + specList[i] + "\r\n"); } // fileBuffer.append(CommonDefinition.autoGenHLine1); // fileBuffer.append(CommonDefinition.autoGenHLine2); @@ -580,8 +580,7 @@ public class AutoGen { // Write consumed package's mdouleInfo related *.h file to autogen.h. // moduleType = saq.getModuleType(); - PackageIdentification[] cosumedPkglist = saq - .getDependencePkg(this.arch); + PackageIdentification[] cosumedPkglist = saq.getDependencePkg(this.arch); headerFileList = depPkgToAutogenH(cosumedPkglist, moduleType); item = headerFileList.iterator(); while (item.hasNext()) { @@ -590,25 +589,37 @@ public class AutoGen { // // Write library class's related *.h file to autogen.h // - String[] libClassList = saq - .getLibraryClasses(CommonDefinition.ALWAYSCONSUMED, this.arch); - if (libClassList != null) { - libClassIncludeH = LibraryClassToAutogenH(libClassList); - item = libClassIncludeH.iterator(); - while (item.hasNext()) { - fileBuffer.append(item.next().toString()); - } + List libClasses = new ArrayList(100); + String[] libClassList = saq.getLibraryClasses(CommonDefinition.ALWAYSCONSUMED, this.arch, null); + for (int i = 0; i < libClassList.length; ++i) { + libClasses.add(libClassList[i]); } - libClassList = saq - .getLibraryClasses(CommonDefinition.ALWAYSPRODUCED, this.arch); - if (libClassList != null) { - libClassIncludeH = LibraryClassToAutogenH(libClassList); - item = libClassIncludeH.iterator(); - while (item.hasNext()) { - fileBuffer.append(item.next().toString()); + libClassList = saq.getLibraryClasses(CommonDefinition.ALWAYSPRODUCED, this.arch, null); + for (int i = 0; i < libClassList.length; ++i) { + libClasses.add(libClassList[i]); + } + // + // Add AutoGen used library class + // + int moduleTypeId = CommonDefinition.getModuleType(moduleType); + if (!libClasses.contains("DebugLib") && moduleTypeId != CommonDefinition.ModuleTypeUnknown + && moduleTypeId != CommonDefinition.ModuleTypeBase) { + libClasses.add("DebugLib"); + } + switch (moduleTypeId) { + case CommonDefinition.ModuleTypeDxeDriver: + case CommonDefinition.ModuleTypeDxeRuntimeDriver: + case CommonDefinition.ModuleTypeDxeSalDriver: + case CommonDefinition.ModuleTypeDxeSmmDriver: + case CommonDefinition.ModuleTypeUefiDriver: + case CommonDefinition.ModuleTypeUefiApplication: + if (!libClasses.contains("UefiBootServicesTableLib")) { + libClasses.add("UefiBootServicesTableLib"); } + break; } + LibraryClassToAutogenH(fileBuffer, libClasses.toArray(new String[libClasses.size()])); fileBuffer.append(ToolDefinitions.LINE_SEPARATOR); // @@ -629,12 +640,17 @@ public class AutoGen { fileBuffer.append("\r\n"); fileBuffer.append(this.myPcdAutogen.getHAutoGenString()); } - + // + // generate function prototype for constructor and destructor + // + LibConstructorToAutogenH(moduleType); + LibDestructorToAutogenH(moduleType); + ExternCallBackToAutoGenH(moduleType); + fileBuffer.append(functionDeclarations); // // Append the #endif at AutoGen.h // fileBuffer.append("#endif\r\n"); - // // Save content of string buffer to AutoGen.h file. // @@ -668,7 +684,7 @@ public class AutoGen { this.myPcdAutogen = new PCDAutoGenAction(moduleId, arch, true, - saq.getModulePcdEntryNameArray(), + saq.getModulePcdEntryNameArray(this.arch), pcdDriverType, parentId); this.myPcdAutogen.execute(); @@ -676,10 +692,6 @@ public class AutoGen { fileBuffer.append(ToolDefinitions.LINE_SEPARATOR); fileBuffer.append(this.myPcdAutogen.getCAutoGenString()); } - - if (!saveFile(outputPath + File.separatorChar + "AutoGen.c", fileBuffer)) { - throw new AutoGenException("Failed to generate AutoGen.c !!!"); - } } /** @@ -693,9 +705,8 @@ public class AutoGen { build module or library. @return includeStrList List of *.h file. **/ - Set LibraryClassToAutogenH(String[] libClassList) + void LibraryClassToAutogenH(StringBuffer fileBuffer, String[] libClassList) throws EdkException { - Set includeStrList = new LinkedHashSet(); String includeName[]; String str = ""; @@ -705,23 +716,23 @@ public class AutoGen { // for (int i = 0; i < libClassList.length; i++) { includeName = GlobalData.getLibraryClassHeaderFiles( - saq.getDependencePkg(this.arch), - libClassList[i]); - if (includeName == null) { - throw new AutoGenException("Can not find library class [" + saq.getDependencePkg(this.arch), + libClassList[i]); + if (includeName == null) { + throw new AutoGenException("Can not find library class [" + libClassList[i] + "] declaration in any SPD package. "); } for (int j = 0; j < includeName.length; j++) { String includeNameStr = includeName[j]; if (includeNameStr != null) { - str = CommonDefinition.INCLUDE + " " + "<"; - str = str + includeNameStr + ">\r\n"; - includeStrList.add(str); + fileBuffer.append(CommonDefinition.INCLUDE); + fileBuffer.append(" <"); + fileBuffer.append(includeNameStr); + fileBuffer.append(">\r\n"); includeNameStr = null; } } } - return includeStrList; } /** @@ -753,8 +764,7 @@ public class AutoGen { + packageNameList[i] + "] declaration in any SPD package. "); } else if (!pkgHeader.equalsIgnoreCase("")) { - includeStr = CommonDefinition.INCLUDE + " <" + pkgHeader - + ">\r\n"; + includeStr = CommonDefinition.INCLUDE + " <" + pkgHeader + ">\r\n"; includeStrList.add(includeStr); } } @@ -778,7 +788,8 @@ public class AutoGen { throws EdkException { String typeStr = saq.getModuleType(); - int unloadImageCount = 0; + String debugStr = "DEBUG ((EFI_D_INFO | EFI_D_LOAD, \"Module Entry Point (%s) 0x%%p\\n\", (VOID *)(UINTN)%s));\r\n"; + int unloadImageCount = 0; int entryPointCount = 0; // @@ -789,25 +800,21 @@ public class AutoGen { case CommonDefinition.ModuleTypePeiCore: if (entryPointList == null ||entryPointList.length != 1 ) { - throw new AutoGenException( - "Module type = 'PEI_CORE', can have only one module entry point!"); + throw new AutoGenException("Module type = 'PEI_CORE', can have only one module entry point!"); } else { - fileBuffer.append("EFI_STATUS\r\n"); - fileBuffer.append(entryPointList[0]); - fileBuffer.append(" (\r\n"); - fileBuffer - .append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n"); - fileBuffer - .append(" IN VOID *OldCoreData\r\n"); - fileBuffer.append(" );\r\n\r\n"); + functionDeclarations.append("EFI_STATUS\r\n"); + functionDeclarations.append("EFIAPI\r\n"); + functionDeclarations.append(entryPointList[0]); + functionDeclarations.append(" (\r\n"); + functionDeclarations.append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n"); + functionDeclarations.append(" IN VOID *OldCoreData\r\n"); + functionDeclarations.append(" );\r\n\r\n"); fileBuffer.append("EFI_STATUS\r\n"); fileBuffer.append("EFIAPI\r\n"); fileBuffer.append("ProcessModuleEntryPointList (\r\n"); - fileBuffer - .append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n"); - fileBuffer - .append(" IN VOID *OldCoreData\r\n"); + fileBuffer.append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n"); + fileBuffer.append(" IN VOID *OldCoreData\r\n"); fileBuffer.append(" )\r\n\r\n"); fileBuffer.append("{\r\n"); fileBuffer.append(" return "); @@ -820,15 +827,14 @@ public class AutoGen { case CommonDefinition.ModuleTypeDxeCore: fileBuffer.append("const UINT32 _gUefiDriverRevision = 0;\r\n"); if (entryPointList == null || entryPointList.length != 1) { - throw new AutoGenException( - "Module type = 'DXE_CORE', can have only one module entry point!"); + throw new AutoGenException("Module type = 'DXE_CORE', can have only one module entry point!"); } else { - - fileBuffer.append("VOID\r\n"); - fileBuffer.append(entryPointList[0]); - fileBuffer.append(" (\n"); - fileBuffer.append(" IN VOID *HobStart\r\n"); - fileBuffer.append(" );\r\n\r\n"); + functionDeclarations.append("VOID\r\n"); + functionDeclarations.append("EFIAPI\r\n"); + functionDeclarations.append(entryPointList[0]); + functionDeclarations.append(" (\r\n"); + functionDeclarations.append(" IN VOID *HobStart\r\n"); + functionDeclarations.append(" );\r\n\r\n"); fileBuffer.append("VOID\r\n"); fileBuffer.append("EFIAPI\r\n"); @@ -845,8 +851,7 @@ public class AutoGen { case CommonDefinition.ModuleTypePeim: entryPointCount = 0; - fileBuffer - .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = 0;\r\n"); + fileBuffer.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = 0;\r\n"); if (entryPointList == null || entryPointList.length == 0) { fileBuffer.append("EFI_STATUS\r\n"); fileBuffer.append("EFIAPI\r\n"); @@ -860,16 +865,14 @@ public class AutoGen { break; } for (int i = 0; i < entryPointList.length; i++) { - fileBuffer.append("EFI_STATUS\r\n"); - fileBuffer.append(entryPointList[i]); - fileBuffer.append(" (\r\n"); - fileBuffer - .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n"); - fileBuffer - .append(" IN EFI_PEI_SERVICES **PeiServices\r\n"); - fileBuffer.append(" );\r\n"); + functionDeclarations.append("EFI_STATUS\r\n"); + functionDeclarations.append("EFIAPI\r\n"); + functionDeclarations.append(entryPointList[i]); + functionDeclarations.append(" (\r\n"); + functionDeclarations.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n"); + functionDeclarations.append(" IN EFI_PEI_SERVICES **PeiServices\r\n"); + functionDeclarations.append(" );\r\n"); entryPointCount++; - } fileBuffer.append("EFI_STATUS\r\n"); @@ -880,6 +883,7 @@ public class AutoGen { fileBuffer.append(" )\r\n\r\n"); fileBuffer.append("{\r\n"); if (entryPointCount == 1) { + fileBuffer.append(String.format(" " + debugStr, entryPointList[0], entryPointList[0])); fileBuffer.append(" return "); fileBuffer.append(entryPointList[0]); fileBuffer.append(" (FfsHeader, PeiServices);\r\n"); @@ -889,11 +893,11 @@ public class AutoGen { fileBuffer.append(" CombinedStatus = EFI_LOAD_ERROR;\r\n\r\n"); for (int i = 0; i < entryPointList.length; i++) { if (!entryPointList[i].equals("")) { + fileBuffer.append(String.format(" " + debugStr, entryPointList[i], entryPointList[i])); fileBuffer.append(" Status = "); fileBuffer.append(entryPointList[i]); fileBuffer.append(" (FfsHeader, PeiServices);\r\n"); - fileBuffer - .append(" if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {\r\n"); + fileBuffer.append(" if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {\r\n"); fileBuffer.append(" CombinedStatus = Status;\r\n"); fileBuffer.append(" }\r\n\r\n"); } else { @@ -912,8 +916,7 @@ public class AutoGen { // function. // if (entryPointList == null || entryPointList.length == 0) { - fileBuffer - .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = "); + fileBuffer.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = "); fileBuffer.append(Integer.toString(entryPointCount)); fileBuffer.append(";\r\n"); fileBuffer.append("EFI_STATUS\r\n"); @@ -928,22 +931,20 @@ public class AutoGen { } else { for (int i = 0; i < entryPointList.length; i++) { - fileBuffer.append("EFI_STATUS\r\n"); - fileBuffer.append(entryPointList[i]); - fileBuffer.append(" (\r\n"); - fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n"); - fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n"); - fileBuffer.append(" );\r\n"); + functionDeclarations.append("EFI_STATUS\r\n"); + functionDeclarations.append("EFIAPI\r\n"); + functionDeclarations.append(entryPointList[i]); + functionDeclarations.append(" (\r\n"); + functionDeclarations.append(" IN EFI_HANDLE ImageHandle,\r\n"); + functionDeclarations.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n"); + functionDeclarations.append(" );\r\n"); entryPointCount++; } - fileBuffer - .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = "); + fileBuffer.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = "); fileBuffer.append(Integer.toString(entryPointCount)); fileBuffer.append(";\r\n"); - fileBuffer - .append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n"); - fileBuffer - .append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n\r\n"); + fileBuffer.append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n"); + fileBuffer.append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n\r\n"); fileBuffer.append("EFI_STATUS\r\n"); fileBuffer.append("EFIAPI\r\n"); @@ -953,16 +954,14 @@ public class AutoGen { fileBuffer.append(" )\r\n\r\n"); fileBuffer.append("{\r\n"); - for (int i = 0; i < entryPointList.length; i++) { - fileBuffer - .append(" if (SetJump (&mJumpContext) == 0) {\r\n"); + fileBuffer.append(" if (SetJump (&mJumpContext) == 0) {\r\n"); + fileBuffer.append(String.format(" " + debugStr, entryPointList[i], entryPointList[i])); fileBuffer.append(" ExitDriver ("); fileBuffer.append(entryPointList[i]); fileBuffer.append(" (ImageHandle, SystemTable));\r\n"); fileBuffer.append(" ASSERT (FALSE);\r\n"); fileBuffer.append(" }\r\n"); - } fileBuffer.append(" return mDriverEntryPointStatus;\r\n"); fileBuffer.append("}\r\n\r\n"); @@ -970,42 +969,35 @@ public class AutoGen { fileBuffer.append("VOID\r\n"); fileBuffer.append("EFIAPI\r\n"); fileBuffer.append("ExitDriver (\r\n"); - fileBuffer.append(" IN EFI_STATUS Status\n"); + fileBuffer.append(" IN EFI_STATUS Status\r\n"); fileBuffer.append(" )\r\n\r\n"); fileBuffer.append("{\r\n"); - fileBuffer - .append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n"); + fileBuffer.append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n"); fileBuffer.append(" mDriverEntryPointStatus = Status;\r\n"); fileBuffer.append(" }\r\n"); fileBuffer.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n"); fileBuffer.append(" ASSERT (FALSE);\r\n"); fileBuffer.append("}\r\n\r\n"); - } // // Add "ModuleUnloadImage" for DxeSmmDriver module type; // - //entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray(); - //entryPointList = CommonDefinition.remDupString(entryPointList); - //entryPointCount = 0; - unloadImageCount = 0; + unloadImageCount = 0; if (unloadImageList != null) { for (int i = 0; i < unloadImageList.length; i++) { - fileBuffer.append("EFI_STATUS\r\n"); - fileBuffer.append(unloadImageList[i]); - fileBuffer.append(" (\r\n"); - fileBuffer - .append(" IN EFI_HANDLE ImageHandle\r\n"); - fileBuffer.append(" );\r\n"); + functionDeclarations.append("EFI_STATUS\r\n"); + functionDeclarations.append(unloadImageList[i]); + functionDeclarations.append(" (\r\n"); + functionDeclarations.append(" IN EFI_HANDLE ImageHandle\r\n"); + functionDeclarations.append(" );\r\n"); unloadImageCount++; } } - fileBuffer - .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = "); + fileBuffer.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = "); fileBuffer.append(Integer.toString(unloadImageCount)); fileBuffer.append(";\r\n\r\n"); @@ -1058,8 +1050,7 @@ public class AutoGen { // If entry point is null, create a empty ProcessModuleEntryPointList function. // if (entryPointList == null || entryPointList.length == 0) { - fileBuffer - .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = 0;\r\n"); + fileBuffer.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = 0;\r\n"); fileBuffer.append("EFI_STATUS\r\n"); fileBuffer.append("EFIAPI\r\n"); fileBuffer.append("ProcessModuleEntryPointList (\r\n"); @@ -1072,27 +1063,24 @@ public class AutoGen { } else { for (int i = 0; i < entryPointList.length; i++) { - - fileBuffer.append("EFI_STATUS\r\n"); - fileBuffer.append(entryPointList[i]); - fileBuffer.append(" (\r\n"); - fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n"); - fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n"); - fileBuffer.append(" );\r\n"); + functionDeclarations.append("EFI_STATUS\r\n"); + functionDeclarations.append("EFIAPI\r\n"); + functionDeclarations.append(entryPointList[i]); + functionDeclarations.append(" (\r\n"); + functionDeclarations.append(" IN EFI_HANDLE ImageHandle,\r\n"); + functionDeclarations.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n"); + functionDeclarations.append(" );\r\n"); entryPointCount++; } - fileBuffer - .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = "); + fileBuffer.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = "); fileBuffer.append(Integer.toString(entryPointCount)); fileBuffer.append(";\r\n"); if (entryPointCount > 1) { - fileBuffer - .append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n"); - fileBuffer - .append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n"); + fileBuffer.append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n"); + fileBuffer.append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n"); } - fileBuffer.append("\n"); + fileBuffer.append("\r\n"); fileBuffer.append("EFI_STATUS\r\n"); fileBuffer.append("EFIAPI\r\n"); @@ -1103,15 +1091,20 @@ public class AutoGen { fileBuffer.append("{\r\n"); if (entryPointCount == 1) { - fileBuffer.append(" return ("); + fileBuffer.append(String.format(" " + debugStr, entryPointList[0], entryPointList[0])); + fileBuffer.append(" return "); fileBuffer.append(entryPointList[0]); - fileBuffer.append(" (ImageHandle, SystemTable));\r\n"); + fileBuffer.append(" (ImageHandle, SystemTable);\r\n"); } else { for (int i = 0; i < entryPointList.length; i++) { if (!entryPointList[i].equals("")) { - fileBuffer - .append(" if (SetJump (&mJumpContext) == 0) {\r\n"); - fileBuffer.append(" ExitDriver ("); + fileBuffer.append(" if (SetJump (&mJumpContext) == 0) {\r\n"); + fileBuffer.append(String.format(" " + debugStr, entryPointList[i], entryPointList[i])); + if (CommonDefinition.getModuleType(typeStr) == CommonDefinition.ModuleTypeUefiApplication) { + fileBuffer.append(" Exit ("); + } else { + fileBuffer.append(" ExitDriver ("); + } fileBuffer.append(entryPointList[i]); fileBuffer.append(" (ImageHandle, SystemTable));\r\n"); fileBuffer.append(" ASSERT (FALSE);\r\n"); @@ -1124,31 +1117,32 @@ public class AutoGen { } fileBuffer.append("}\r\n\r\n"); - fileBuffer.append("VOID\r\n"); - fileBuffer.append("EFIAPI\r\n"); - fileBuffer.append("ExitDriver (\r\n"); - fileBuffer.append(" IN EFI_STATUS Status\r\n"); - fileBuffer.append(" )\r\n\r\n"); - fileBuffer.append("{\r\n"); - if (entryPointCount <= 1) { - fileBuffer.append(" if (EFI_ERROR (Status)) {\r\n"); - fileBuffer - .append(" ProcessLibraryDestructorList (gImageHandle, gST);\r\n"); - fileBuffer.append(" }\r\n"); - fileBuffer - .append(" gBS->Exit (gImageHandle, Status, 0, NULL);\r\n"); - } else { - fileBuffer - .append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n"); - fileBuffer.append(" mDriverEntryPointStatus = Status;\r\n"); - fileBuffer.append(" }\r\n"); - fileBuffer.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n"); - fileBuffer.append(" ASSERT (FALSE);\r\n"); + if (CommonDefinition.getModuleType(typeStr) != CommonDefinition.ModuleTypeUefiApplication) { + fileBuffer.append("VOID\r\n"); + fileBuffer.append("EFIAPI\r\n"); + fileBuffer.append("ExitDriver (\r\n"); + fileBuffer.append(" IN EFI_STATUS Status\r\n"); + fileBuffer.append(" )\r\n\r\n"); + fileBuffer.append("{\r\n"); + if (entryPointCount <= 1) { + fileBuffer.append(" if (EFI_ERROR (Status)) {\r\n"); + fileBuffer.append(" ProcessLibraryDestructorList (gImageHandle, gST);\r\n"); + fileBuffer.append(" }\r\n"); + fileBuffer.append(" gBS->Exit (gImageHandle, Status, 0, NULL);\r\n"); + } else { + fileBuffer.append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n"); + fileBuffer.append(" mDriverEntryPointStatus = Status;\r\n"); + fileBuffer.append(" }\r\n"); + fileBuffer.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n"); + fileBuffer.append(" ASSERT (FALSE);\r\n"); + } + fileBuffer.append("}\r\n\r\n"); } - fileBuffer.append("}\r\n\r\n"); - } + if (CommonDefinition.getModuleType(typeStr) == CommonDefinition.ModuleTypeUefiApplication) { + break; + } // // Add ModuleUnloadImage for DxeDriver and UefiDriver module type. // @@ -1158,26 +1152,24 @@ public class AutoGen { // //entryPointList = CommonDefinition.remDupString(entryPointList); //entryPointCount = 0; - unloadImageCount = 0; + unloadImageCount = 0; if (unloadImageList != null) { for (int i = 0; i < unloadImageList.length; i++) { - fileBuffer.append("EFI_STATUS\r\n"); - fileBuffer.append("EFIAPI\r\n"); - fileBuffer.append(unloadImageList[i]); - fileBuffer.append(" (\r\n"); - fileBuffer - .append(" IN EFI_HANDLE ImageHandle\r\n"); - fileBuffer.append(" );\r\n"); + functionDeclarations.append("EFI_STATUS\r\n"); + functionDeclarations.append("EFIAPI\r\n"); + functionDeclarations.append(unloadImageList[i]); + functionDeclarations.append(" (\r\n"); + functionDeclarations.append(" IN EFI_HANDLE ImageHandle\r\n"); + functionDeclarations.append(" );\r\n"); unloadImageCount++; } } - fileBuffer - .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = "); + fileBuffer.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = "); fileBuffer.append(Integer.toString(unloadImageCount)); fileBuffer.append(";\r\n\r\n"); - fileBuffer.append("EFI_STATUS\n"); + fileBuffer.append("EFI_STATUS\r\n"); fileBuffer.append("EFIAPI\r\n"); fileBuffer.append("ProcessModuleUnloadList (\r\n"); fileBuffer.append(" IN EFI_HANDLE ImageHandle\r\n"); @@ -1218,182 +1210,220 @@ public class AutoGen { } /** - PpiGuidToAutogenc + CNameToAutogenc - This function gets GUIDs from SPD file accrodeing to information - and write those GUIDs to AutoGen.c. + This function gets GUIDs from SPD file accrodeing to + information and write those GUIDs to AutoGen.c. @param fileBuffer String Buffer for Autogen.c file. - @throws BuildException - Guid must set value! + **/ - void PpiGuidToAutogenC(StringBuffer fileBuffer) throws AutoGenException { + void CNameToAutogenC(StringBuffer fileBuffer) throws AutoGenException { String[] cNameGuid = null; + String guidKeyWord = null; - // - // Get the all PPI adn PPI Notify from MSA file, - // then add those PPI ,and PPI Notify name to list. - // - - String[] ppiList = saq.getPpiArray(this.arch); - for (int i = 0; i < ppiList.length; i++) { - this.mPpiList.add(ppiList[i]); + String[] cnameList = saq.getCNameArray(this.arch); + for (int i = 0; i < cnameList.length; i++) { + this.mGuidCNameList.add(cnameList[i]); } - String[] ppiNotifyList = saq.getPpiNotifyArray(this.arch); - for (int i = 0; i < ppiNotifyList.length; i++) { - this.mPpiList.add(ppiNotifyList[i]); - } - // - // Find CNAME and GUID from dependence SPD file and write to Autogen.c - // - Iterator ppiIterator = this.mPpiList.iterator(); - String ppiKeyWord = null; - while (ppiIterator.hasNext()) { - ppiKeyWord = ppiIterator.next().toString(); - cNameGuid = GlobalData.getPpiGuid(this.mDepPkgList, ppiKeyWord); - if (cNameGuid != null) { - fileBuffer - .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID "); - fileBuffer.append(cNameGuid[0]); - fileBuffer.append(" = { "); - fileBuffer.append(CommonDefinition.formatGuidName(cNameGuid[1])); - fileBuffer.append(" } ;"); - } else { - // - // If can't find Ppi GUID declaration in every package - // - throw new AutoGenException("Can not find Ppi GUID [" - + ppiKeyWord + "] declaration in any SPD package!"); + Iterator guidIterator = this.mGuidCNameList.iterator(); + while (guidIterator.hasNext()) { + guidKeyWord = guidIterator.next().toString(); + cNameGuid = GlobalData.getGuid(this.mDepPkgList, guidKeyWord); + if (cNameGuid == null) { + cNameGuid = GlobalData.getProtocolGuid(this.mDepPkgList, guidKeyWord); + if (cNameGuid == null) { + cNameGuid = GlobalData.getPpiGuid(this.mDepPkgList, guidKeyWord); + if (cNameGuid == null) { + // + // If can't find GUID declaration in every package, stop the build + // + EdkLog.log(EdkLog.EDK_INFO,"WARN: Can not find Guid [" + guidKeyWord + "] declaration in any SPD file."); + continue; + //throw new AutoGenException("Can not find Guid [" + guidKeyWord + // + "] declaration in any SPD package. "); + } + } } + + fileBuffer.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID "); + fileBuffer.append(cNameGuid[0]); + fileBuffer.append(" = { "); + fileBuffer.append(CommonDefinition.formatGuidName(cNameGuid[1])); + fileBuffer.append("} ;"); } } /** - ProtocolGuidToAutogenc + LibInstanceToAutogenC - This function gets GUIDs from SPD file accrodeing to - information and write those GUIDs to AutoGen.c. + This function adds dependent library instance to autogen.c,which + includeing library's constructor, destructor, and library dependent ppi, + protocol, guid, pcd information. @param fileBuffer - String Buffer for Autogen.c file. + String buffer for AutoGen.c @throws BuildException - Protocol name must set. **/ - void ProtocolGuidToAutogenC(StringBuffer fileBuffer) throws EdkException { - String[] cNameGuid = null; - - String[] protocolList = saq.getProtocolArray(this.arch); - + void LibInstanceToAutogenC(StringBuffer fileBuffer) throws EdkException { + String moduleType = this.moduleId.getModuleType(); // - // Add result to Autogen global list. + // Add library constructor to AutoGen.c // - for (int i = 0; i < protocolList.length; i++) { - this.mProtocolList.add(protocolList[i]); - } - - String[] protocolNotifyList = saq - .getProtocolNotifyArray(this.arch); - - for (int i = 0; i < protocolNotifyList.length; i++) { - this.mProtocolList.add(protocolNotifyList[i]); - } - + LibConstructorToAutogenC(libConstructList, moduleType, fileBuffer); // - // Get the NAME and GUID from dependence SPD and write to Autogen.c + // Add library destructor to AutoGen.c // - Iterator protocolIterator = this.mProtocolList.iterator(); - String protocolKeyWord = null; - - - while (protocolIterator.hasNext()) { - protocolKeyWord = protocolIterator.next().toString(); - cNameGuid = GlobalData.getProtocolGuid(this.mDepPkgList, protocolKeyWord); - if (cNameGuid != null) { - fileBuffer - .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID "); - fileBuffer.append(cNameGuid[0]); - fileBuffer.append(" = { "); - fileBuffer.append(CommonDefinition.formatGuidName(cNameGuid[1])); - fileBuffer.append(" } ;"); - } else { - // - // If can't find protocol GUID declaration in every package - // - throw new AutoGenException("Can not find protocol Guid [" - + protocolKeyWord + "] declaration in any SPD package!"); - } - } + LibDestructorToAutogenC(libDestructList, moduleType, fileBuffer); } /** - GuidGuidToAutogenc + LibConstructorToAutogenH - This function gets GUIDs from SPD file accrodeing to information - and write those GUIDs to AutoGen.c. + This function writes library constructor declarations AutoGen.h. The library + constructor's parameter and return value depend on module type. + @param libInstanceList + List of library construct name. + @param moduleType + Module type. @param fileBuffer - String Buffer for Autogen.c file. - + String buffer for AutoGen.c + @throws Exception **/ - void GuidGuidToAutogenC(StringBuffer fileBuffer) throws AutoGenException { - String[] cNameGuid = null; - String guidKeyWord = null; - - String[] guidList = saq.getGuidEntryArray(this.arch); + void LibConstructorToAutogenH(String moduleType) throws EdkException { + boolean isFirst = true; - for (int i = 0; i < guidList.length; i++) { - this.mGuidList.add(guidList[i]); + // + // If not yet parse this library instance's constructor + // element,parse it. + // + String libConstructName = saq.getLibConstructorName(); + if (libConstructName == null) { + return; } + // + // The library constructor's parameter and return value depend on + // module type. + // + if (moduleType.equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) { + functionDeclarations.append("RETURN_STATUS\r\n"); + functionDeclarations.append("EFIAPI\r\n"); + functionDeclarations.append(libConstructName); + functionDeclarations.append(" (\r\n"); + functionDeclarations.append(" VOID\r\n"); + functionDeclarations.append(" );\r\n"); + } else { + switch (CommonDefinition.getModuleType(moduleType)) { + case CommonDefinition.ModuleTypeBase: + functionDeclarations.append("RETURN_STATUS\r\n"); + functionDeclarations.append("EFIAPI\r\n"); + functionDeclarations.append(libConstructName); + functionDeclarations.append(" (\r\n"); + functionDeclarations.append(" VOID\r\n"); + functionDeclarations.append(" );\r\n"); + break; + + case CommonDefinition.ModuleTypePeiCore: + case CommonDefinition.ModuleTypePeim: + functionDeclarations.append("EFI_STATUS\r\n"); + functionDeclarations.append("EFIAPI\r\n"); + functionDeclarations.append(libConstructName); + functionDeclarations.append(" (\r\n"); + functionDeclarations.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n"); + functionDeclarations.append(" IN EFI_PEI_SERVICES **PeiServices\r\n"); + functionDeclarations.append(" );\r\n"); + break; - Iterator guidIterator = this.mGuidList.iterator(); - while (guidIterator.hasNext()) { - guidKeyWord = guidIterator.next().toString(); - cNameGuid = GlobalData.getGuid(this.mDepPkgList, guidKeyWord); + case CommonDefinition.ModuleTypeDxeCore: + case CommonDefinition.ModuleTypeDxeDriver: + case CommonDefinition.ModuleTypeDxeRuntimeDriver: + case CommonDefinition.ModuleTypeDxeSmmDriver: + case CommonDefinition.ModuleTypeDxeSalDriver: + case CommonDefinition.ModuleTypeUefiDriver: + case CommonDefinition.ModuleTypeUefiApplication: + functionDeclarations.append("EFI_STATUS\r\n"); + functionDeclarations.append("EFIAPI\r\n"); + functionDeclarations.append(libConstructName); + functionDeclarations.append(" (\r\n"); + functionDeclarations.append(" IN EFI_HANDLE ImageHandle,\r\n"); + functionDeclarations.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n"); + functionDeclarations.append(" );\r\n"); + break; - if (cNameGuid != null) { - fileBuffer - .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID "); - fileBuffer.append(cNameGuid[0]); - fileBuffer.append(" = { "); - fileBuffer.append(CommonDefinition.formatGuidName(cNameGuid[1])); - fileBuffer.append("} ;"); - } else { - // - // If can't find GUID declaration in every package - // - throw new AutoGenException("Can not find Guid [" + guidKeyWord - + "] declaration in any SPD package. "); } - } } /** - LibInstanceToAutogenC + LibDestructorToAutogenH - This function adds dependent library instance to autogen.c,which - includeing library's constructor, destructor, and library dependent ppi, - protocol, guid, pcd information. + This function writes library destructor declarations AutoGen.h. The library + destructor's parameter and return value depend on module type. + @param libInstanceList + List of library destructor name. + @param moduleType + Module type. @param fileBuffer String buffer for AutoGen.c - @throws BuildException + @throws Exception **/ - void LibInstanceToAutogenC(StringBuffer fileBuffer) throws EdkException { - String moduleType = this.moduleId.getModuleType(); - // - // Add library constructor to AutoGen.c - // - LibConstructorToAutogenC(libConstructList, moduleType, - fileBuffer/* autogenC */); - // - // Add library destructor to AutoGen.c - // - LibDestructorToAutogenC(libDestructList, moduleType, fileBuffer/* autogenC */); + void LibDestructorToAutogenH(String moduleType) throws EdkException { + boolean isFirst = true; + String libDestructName = saq.getLibDestructorName(); + if (libDestructName == null) { + return; + } + + if (moduleType.equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) { + functionDeclarations.append("RETURN_STATUS\r\n"); + functionDeclarations.append("EFIAPI\r\n"); + functionDeclarations.append(libDestructName); + functionDeclarations.append(" (\r\n"); + functionDeclarations.append(" VOID\r\n"); + functionDeclarations.append(" );\r\n"); + } else { + switch (CommonDefinition.getModuleType(moduleType)) { + case CommonDefinition.ModuleTypeBase: + functionDeclarations.append("RETURN_STATUS\r\n"); + functionDeclarations.append("EFIAPI\r\n"); + functionDeclarations.append(libDestructName); + functionDeclarations.append(" (\r\n"); + functionDeclarations.append(" VOID\r\n"); + functionDeclarations.append(" );\r\n"); + break; + case CommonDefinition.ModuleTypePeiCore: + case CommonDefinition.ModuleTypePeim: + functionDeclarations.append("EFI_STATUS\r\n"); + functionDeclarations.append("EFIAPI\r\n"); + functionDeclarations.append(libDestructName); + functionDeclarations.append(" (\r\n"); + functionDeclarations.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n"); + functionDeclarations.append(" IN EFI_PEI_SERVICES **PeiServices\r\n"); + functionDeclarations.append(" );\r\n"); + break; + case CommonDefinition.ModuleTypeDxeCore: + case CommonDefinition.ModuleTypeDxeDriver: + case CommonDefinition.ModuleTypeDxeRuntimeDriver: + case CommonDefinition.ModuleTypeDxeSmmDriver: + case CommonDefinition.ModuleTypeDxeSalDriver: + case CommonDefinition.ModuleTypeUefiDriver: + case CommonDefinition.ModuleTypeUefiApplication: + functionDeclarations.append("EFI_STATUS\r\n"); + functionDeclarations.append("EFIAPI\r\n"); + functionDeclarations.append(libDestructName); + functionDeclarations.append(" (\r\n"); + functionDeclarations.append(" IN EFI_HANDLE ImageHandle,\r\n"); + functionDeclarations.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n"); + functionDeclarations.append(" );\r\n"); + break; + } + } } /** @@ -1419,54 +1449,52 @@ public class AutoGen { // module type. // for (int i = 0; i < libInstanceList.size(); i++) { - if (libInstanceList.get(i)[1].equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) { - fileBuffer.append("RETURN_STATUS\r\n"); - fileBuffer.append("EFIAPI\r\n"); - fileBuffer.append(libInstanceList.get(i)[0]); - fileBuffer.append(" (\r\n"); - fileBuffer.append(" VOID\r\n"); - fileBuffer.append(" );\r\n"); - } else { - switch (CommonDefinition.getModuleType(moduleType)) { + if (libInstanceList.get(i)[1].equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) { + functionDeclarations.append("RETURN_STATUS\r\n"); + functionDeclarations.append("EFIAPI\r\n"); + functionDeclarations.append(libInstanceList.get(i)[0]); + functionDeclarations.append(" (\r\n"); + functionDeclarations.append(" VOID\r\n"); + functionDeclarations.append(" );\r\n"); + } else { + switch (CommonDefinition.getModuleType(moduleType)) { case CommonDefinition.ModuleTypeBase: - fileBuffer.append("RETURN_STATUS\r\n"); - fileBuffer.append("EFIAPI\r\n"); - fileBuffer.append(libInstanceList.get(i)[0]); - fileBuffer.append(" (\r\n"); - fileBuffer.append(" VOID\r\n"); - fileBuffer.append(" );\r\n"); + functionDeclarations.append("RETURN_STATUS\r\n"); + functionDeclarations.append("EFIAPI\r\n"); + functionDeclarations.append(libInstanceList.get(i)[0]); + functionDeclarations.append(" (\r\n"); + functionDeclarations.append(" VOID\r\n"); + functionDeclarations.append(" );\r\n"); break; case CommonDefinition.ModuleTypePeiCore: case CommonDefinition.ModuleTypePeim: - fileBuffer.append("EFI_STATUS\r\n"); - fileBuffer.append("EFIAPI\r\n"); - fileBuffer.append(libInstanceList.get(i)[0]); - fileBuffer.append(" (\r\n"); - fileBuffer - .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n"); - fileBuffer - .append(" IN EFI_PEI_SERVICES **PeiServices\r\n"); - fileBuffer.append(" );\r\n"); - break; - - case CommonDefinition.ModuleTypeDxeCore: - case CommonDefinition.ModuleTypeDxeDriver: - case CommonDefinition.ModuleTypeDxeRuntimeDriver: - case CommonDefinition.ModuleTypeDxeSmmDriver: - case CommonDefinition.ModuleTypeDxeSalDriver: - case CommonDefinition.ModuleTypeUefiDriver: - case CommonDefinition.ModuleTypeUefiApplication: - fileBuffer.append("EFI_STATUS\r\n"); - fileBuffer.append("EFIAPI\r\n"); - fileBuffer.append(libInstanceList.get(i)[0]); - fileBuffer.append(" (\r\n"); - fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n"); - fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n"); - fileBuffer.append(" );\r\n"); - break; + functionDeclarations.append("EFI_STATUS\r\n"); + functionDeclarations.append("EFIAPI\r\n"); + functionDeclarations.append(libInstanceList.get(i)[0]); + functionDeclarations.append(" (\r\n"); + functionDeclarations.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n"); + functionDeclarations.append(" IN EFI_PEI_SERVICES **PeiServices\r\n"); + functionDeclarations.append(" );\r\n"); + break; - } + case CommonDefinition.ModuleTypeDxeCore: + case CommonDefinition.ModuleTypeDxeDriver: + case CommonDefinition.ModuleTypeDxeRuntimeDriver: + case CommonDefinition.ModuleTypeDxeSmmDriver: + case CommonDefinition.ModuleTypeDxeSalDriver: + case CommonDefinition.ModuleTypeUefiDriver: + case CommonDefinition.ModuleTypeUefiApplication: + functionDeclarations.append("EFI_STATUS\r\n"); + functionDeclarations.append("EFIAPI\r\n"); + functionDeclarations.append(libInstanceList.get(i)[0]); + functionDeclarations.append(" (\r\n"); + functionDeclarations.append(" IN EFI_HANDLE ImageHandle,\r\n"); + functionDeclarations.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n"); + functionDeclarations.append(" );\r\n"); + break; + + } } } @@ -1484,8 +1512,7 @@ public class AutoGen { case CommonDefinition.ModuleTypePeiCore: case CommonDefinition.ModuleTypePeim: fileBuffer.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n"); - fileBuffer - .append(" IN EFI_PEI_SERVICES **PeiServices\r\n"); + fileBuffer.append(" IN EFI_PEI_SERVICES **PeiServices\r\n"); break; case CommonDefinition.ModuleTypeDxeCore: @@ -1505,9 +1532,6 @@ public class AutoGen { // // If no constructor function, return EFI_SUCCESS. // - //if (libInstanceList.size() == 0){ - // fileBuffer.append(" return EFI_SUCCESS;\r\n"); - //} for (int i = 0; i < libInstanceList.size(); i++) { if (isFirst) { fileBuffer.append(" EFI_STATUS Status;\r\n"); @@ -1515,38 +1539,38 @@ public class AutoGen { fileBuffer.append("\r\n"); isFirst = false; } - if (libInstanceList.get(i)[1].equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) { + if (libInstanceList.get(i)[1].equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) { fileBuffer.append(" Status = "); fileBuffer.append(libInstanceList.get(i)[0]); fileBuffer.append("();\r\n"); - } else { - switch (CommonDefinition.getModuleType(moduleType)) { - case CommonDefinition.ModuleTypeBase: - fileBuffer.append(" Status = "); - fileBuffer.append(libInstanceList.get(i)[0]); - fileBuffer.append("();\r\n"); - break; - case CommonDefinition.ModuleTypePeiCore: - case CommonDefinition.ModuleTypePeim: - fileBuffer.append(" Status = "); - fileBuffer.append(libInstanceList.get(i)[0]); - fileBuffer.append(" (FfsHeader, PeiServices);\r\n"); - break; - case CommonDefinition.ModuleTypeDxeCore: - case CommonDefinition.ModuleTypeDxeDriver: - case CommonDefinition.ModuleTypeDxeRuntimeDriver: - case CommonDefinition.ModuleTypeDxeSmmDriver: - case CommonDefinition.ModuleTypeDxeSalDriver: - case CommonDefinition.ModuleTypeUefiDriver: - case CommonDefinition.ModuleTypeUefiApplication: - fileBuffer.append(" Status = "); - fileBuffer.append(libInstanceList.get(i)[0]); - fileBuffer.append(" (ImageHandle, SystemTable);\r\n"); - break; - default: - EdkLog.log(EdkLog.EDK_INFO,"Autogen doesn't know how to deal with module type - " + moduleType + "!"); - } - + } else { + switch (CommonDefinition.getModuleType(moduleType)) { + case CommonDefinition.ModuleTypeBase: + fileBuffer.append(" Status = "); + fileBuffer.append(libInstanceList.get(i)[0]); + fileBuffer.append("();\r\n"); + break; + case CommonDefinition.ModuleTypePeiCore: + case CommonDefinition.ModuleTypePeim: + fileBuffer.append(" Status = "); + fileBuffer.append(libInstanceList.get(i)[0]); + fileBuffer.append(" (FfsHeader, PeiServices);\r\n"); + break; + case CommonDefinition.ModuleTypeDxeCore: + case CommonDefinition.ModuleTypeDxeDriver: + case CommonDefinition.ModuleTypeDxeRuntimeDriver: + case CommonDefinition.ModuleTypeDxeSmmDriver: + case CommonDefinition.ModuleTypeDxeSalDriver: + case CommonDefinition.ModuleTypeUefiDriver: + case CommonDefinition.ModuleTypeUefiApplication: + fileBuffer.append(" Status = "); + fileBuffer.append(libInstanceList.get(i)[0]); + fileBuffer.append(" (ImageHandle, SystemTable);\r\n"); + break; + default: + EdkLog.log(EdkLog.EDK_INFO,"Autogen doesn't know how to deal with module type - " + moduleType + "!"); + } + } fileBuffer.append(" ASSERT_EFI_ERROR (Status);\r\n"); } @@ -1571,51 +1595,49 @@ public class AutoGen { String moduleType, StringBuffer fileBuffer) throws EdkException { boolean isFirst = true; for (int i = 0; i < libInstanceList.size(); i++) { - if (libInstanceList.get(i)[1].equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) { - fileBuffer.append("RETURN_STATUS\r\n"); - fileBuffer.append("EFIAPI\r\n"); - fileBuffer.append(libInstanceList.get(i)[0]); - fileBuffer.append(" (\r\n"); - fileBuffer.append(" VOID\r\n"); - fileBuffer.append(" );\r\n"); - } else { - switch (CommonDefinition.getModuleType(moduleType)) { - case CommonDefinition.ModuleTypeBase: - fileBuffer.append("RETURN_STATUS\r\n"); - fileBuffer.append("EFIAPI\r\n"); - fileBuffer.append(libInstanceList.get(i)[0]); - fileBuffer.append(" (\r\n"); - fileBuffer.append(" VOID\r\n"); - fileBuffer.append(" );\r\n"); - break; - case CommonDefinition.ModuleTypePeiCore: - case CommonDefinition.ModuleTypePeim: - fileBuffer.append("EFI_STATUS\r\n"); - fileBuffer.append("EFIAPI\r\n"); - fileBuffer.append(libInstanceList.get(i)[0]); - fileBuffer.append(" (\r\n"); - fileBuffer - .append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n"); - fileBuffer - .append(" IN EFI_PEI_SERVICES **PeiServices\r\n"); - fileBuffer.append(" );\r\n"); - break; - case CommonDefinition.ModuleTypeDxeCore: - case CommonDefinition.ModuleTypeDxeDriver: - case CommonDefinition.ModuleTypeDxeRuntimeDriver: - case CommonDefinition.ModuleTypeDxeSmmDriver: - case CommonDefinition.ModuleTypeDxeSalDriver: - case CommonDefinition.ModuleTypeUefiDriver: - case CommonDefinition.ModuleTypeUefiApplication: - fileBuffer.append("EFI_STATUS\r\n"); - fileBuffer.append("EFIAPI\r\n"); - fileBuffer.append(libInstanceList.get(i)[0]); - fileBuffer.append(" (\r\n"); - fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n"); - fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n"); - fileBuffer.append(" );\r\n"); - break; - } + if (libInstanceList.get(i)[1].equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) { + functionDeclarations.append("RETURN_STATUS\r\n"); + functionDeclarations.append("EFIAPI\r\n"); + functionDeclarations.append(libInstanceList.get(i)[0]); + functionDeclarations.append(" (\r\n"); + functionDeclarations.append(" VOID\r\n"); + functionDeclarations.append(" );\r\n"); + } else { + switch (CommonDefinition.getModuleType(moduleType)) { + case CommonDefinition.ModuleTypeBase: + functionDeclarations.append("RETURN_STATUS\r\n"); + functionDeclarations.append("EFIAPI\r\n"); + functionDeclarations.append(libInstanceList.get(i)[0]); + functionDeclarations.append(" (\r\n"); + functionDeclarations.append(" VOID\r\n"); + functionDeclarations.append(" );\r\n"); + break; + case CommonDefinition.ModuleTypePeiCore: + case CommonDefinition.ModuleTypePeim: + functionDeclarations.append("EFI_STATUS\r\n"); + functionDeclarations.append("EFIAPI\r\n"); + functionDeclarations.append(libInstanceList.get(i)[0]); + functionDeclarations.append(" (\r\n"); + functionDeclarations.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n"); + functionDeclarations.append(" IN EFI_PEI_SERVICES **PeiServices\r\n"); + functionDeclarations.append(" );\r\n"); + break; + case CommonDefinition.ModuleTypeDxeCore: + case CommonDefinition.ModuleTypeDxeDriver: + case CommonDefinition.ModuleTypeDxeRuntimeDriver: + case CommonDefinition.ModuleTypeDxeSmmDriver: + case CommonDefinition.ModuleTypeDxeSalDriver: + case CommonDefinition.ModuleTypeUefiDriver: + case CommonDefinition.ModuleTypeUefiApplication: + functionDeclarations.append("EFI_STATUS\r\n"); + functionDeclarations.append("EFIAPI\r\n"); + functionDeclarations.append(libInstanceList.get(i)[0]); + functionDeclarations.append(" (\r\n"); + functionDeclarations.append(" IN EFI_HANDLE ImageHandle,\r\n"); + functionDeclarations.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n"); + functionDeclarations.append(" );\r\n"); + break; + } } } @@ -1652,17 +1674,17 @@ public class AutoGen { fileBuffer.append("\r\n"); isFirst = false; } - if (libInstanceList.get(i)[1].equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) { + if (libInstanceList.get(i)[1].equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) { fileBuffer.append(" Status = "); fileBuffer.append(libInstanceList.get(i)[0]); fileBuffer.append("();\r\n"); fileBuffer.append(" VOID\r\n"); - } else { - fileBuffer.append(" Status = "); - fileBuffer.append(libInstanceList.get(i)[0]); - fileBuffer.append("(ImageHandle, SystemTable);\r\n"); - fileBuffer.append(" ASSERT_EFI_ERROR (Status);\r\n"); - } + } else { + fileBuffer.append(" Status = "); + fileBuffer.append(libInstanceList.get(i)[0]); + fileBuffer.append("(ImageHandle, SystemTable);\r\n"); + fileBuffer.append(" ASSERT_EFI_ERROR (Status);\r\n"); + } } fileBuffer.append("}\r\n"); break; @@ -1688,20 +1710,20 @@ public class AutoGen { String[][] driverBindingGroup = this.saq.getExternProtocolGroup(); - // - // inital BitMask; - // - int BitMask = 0; + // + // inital BitMask; + // + int BitMask = 0; // // Write driver binding protocol extern to autogen.c // for (int i = 0; i < driverBindingGroup.length; i++) { if (driverBindingGroup[i][0] != null) { - fileBuffer.append("extern EFI_DRIVER_BINDING_PROTOCOL "); - fileBuffer.append(driverBindingGroup[i][0]); - fileBuffer.append(";\r\n"); - } + globalDeclarations.append("extern EFI_DRIVER_BINDING_PROTOCOL "); + globalDeclarations.append(driverBindingGroup[i][0]); + globalDeclarations.append(";\r\n"); + } } // @@ -1712,16 +1734,16 @@ public class AutoGen { if (driverBindingGroup[i][1]!= null) { if (driverBindingGroup[i][0] != null) { BitMask |= 0x01; - fileBuffer.append("extern EFI_COMPONENT_NAME_PROTOCOL "); - fileBuffer.append(driverBindingGroup[i][1]); - fileBuffer.append(";\r\n"); + globalDeclarations.append("extern EFI_COMPONENT_NAME_PROTOCOL "); + globalDeclarations.append(driverBindingGroup[i][1]); + globalDeclarations.append(";\r\n"); } else { throw new AutoGenException("DriverBinding can't be empty!!"); } - } - } - } - + } + } + } + // // Write driver configration protocol extern to autogen.c // @@ -1729,15 +1751,15 @@ public class AutoGen { if (driverBindingGroup[i][2] != null) { if (driverBindingGroup[i][0] != null) { BitMask |= 0x02; - fileBuffer.append("extern EFI_DRIVER_CONFIGURATION_PROTOCOL "); - fileBuffer.append(driverBindingGroup[i][2]); - fileBuffer.append(";\r\n"); + globalDeclarations.append("extern EFI_DRIVER_CONFIGURATION_PROTOCOL "); + globalDeclarations.append(driverBindingGroup[i][2]); + globalDeclarations.append(";\r\n"); } else { throw new AutoGenException("DriverBinding can't be empty!!"); } } } - + // // Write driver dignastic protocol extern to autogen.c // @@ -1746,30 +1768,28 @@ public class AutoGen { if (driverBindingGroup[i][3] != null) { if (driverBindingGroup[i][0] != null) { BitMask |= 0x04; - fileBuffer.append("extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL "); - fileBuffer.append(driverBindingGroup[i][3]); - fileBuffer.append(";\r\n"); + globalDeclarations.append("extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL "); + globalDeclarations.append(driverBindingGroup[i][3]); + globalDeclarations.append(";\r\n"); } else { throw new AutoGenException("DriverBinding can't be empty!!"); } } } } - - + + // // Write driver module protocol bitmask. // - fileBuffer - .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverModelProtocolBitmask = "); + fileBuffer.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverModelProtocolBitmask = "); fileBuffer.append(Integer.toString(BitMask)); fileBuffer.append(";\r\n"); // // Write driver module protocol list entry // - fileBuffer - .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverModelProtocolListEntries = "); + fileBuffer.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverModelProtocolListEntries = "); fileBuffer.append(Integer.toString(driverBindingGroup.length)); fileBuffer.append(";\r\n"); @@ -1778,11 +1798,10 @@ public class AutoGen { // Write drive module protocol list to autogen.c // if (driverBindingGroup.length > 0) { - fileBuffer - .append("GLOBAL_REMOVE_IF_UNREFERENCED const EFI_DRIVER_MODEL_PROTOCOL_LIST _gDriverModelProtocolList[] = {"); - } - - + fileBuffer.append("GLOBAL_REMOVE_IF_UNREFERENCED const EFI_DRIVER_MODEL_PROTOCOL_LIST _gDriverModelProtocolList[] = {"); + } + + for (int i = 0; i < driverBindingGroup.length; i++) { if (i != 0) { fileBuffer.append(","); @@ -1794,7 +1813,7 @@ public class AutoGen { fileBuffer.append(" &"); fileBuffer.append(driverBindingGroup[i][0]); fileBuffer.append(", \r\n"); - + // // ComponentName // @@ -1831,7 +1850,74 @@ public class AutoGen { } if (driverBindingGroup.length > 0) { - fileBuffer.append("\r\n};\r\n"); + fileBuffer.append("\r\n};\r\n"); + } + } + + /** + ExternCallBackToAutoGenC + + This function adds and + infomation to AutoGen.c + + @param fileBuffer + String buffer for AutoGen.c + @throws BuildException + **/ + void ExternCallBackToAutoGenH(String moduleType) + throws EdkException { + // + // Collect module's and + // and add to setVirtualAddList + // exitBootServiceList. + // + String[] setVirtuals = saq.getSetVirtualAddressMapCallBackArray(); + String[] exitBoots = saq.getExitBootServicesCallBackArray(); + // + // Add c code in autogen.c which relate to + // and + // + switch (CommonDefinition.getModuleType(moduleType)) { + case CommonDefinition.ModuleTypeDxeDriver: + case CommonDefinition.ModuleTypeDxeRuntimeDriver: + case CommonDefinition.ModuleTypeDxeSalDriver: + case CommonDefinition.ModuleTypeUefiDriver: + case CommonDefinition.ModuleTypeUefiApplication: + // + // Write SetVirtualAddressMap function definition. + // + for (int i = 0; setVirtuals != null && i < setVirtuals.length; i++) { + if (setVirtuals[i].equalsIgnoreCase("")) { + continue; + } + functionDeclarations.append("VOID\r\n"); + functionDeclarations.append("EFIAPI\r\n"); + functionDeclarations.append(setVirtuals[i]); + functionDeclarations.append(" (\r\n"); + functionDeclarations.append(" IN EFI_EVENT Event,\r\n"); + functionDeclarations.append(" IN VOID *Context\r\n"); + functionDeclarations.append(" );\r\n\r\n"); + } + + // + // Write DriverExitBootServices function definition. + // + for (int i = 0; exitBoots != null && i < exitBoots.length; i++) { + if (exitBoots[i].equalsIgnoreCase("")) { + continue; + } + + functionDeclarations.append("VOID\r\n"); + functionDeclarations.append("EFIAPI\r\n"); + functionDeclarations.append(exitBoots[i]); + functionDeclarations.append(" (\r\n"); + functionDeclarations.append(" IN EFI_EVENT Event,\r\n"); + functionDeclarations.append(" IN VOID *Context\r\n"); + functionDeclarations.append(" );\r\n\r\n"); + } + break; + default: + break; } } @@ -1908,17 +1994,17 @@ public class AutoGen { // if ((!outFile.exists()) ||(inFile.lastModified() - outFile.lastModified()) >= 0) { if (inFile.exists()) { - try{ + try { FileInputStream fis = new FileInputStream (inFile); fis.read(buffer); FileOutputStream fos = new FileOutputStream(outFile); fos.write(buffer); fis.close(); fos.close(); - } catch (IOException e){ + } catch (IOException e) { throw new AutoGenException("The file, flashMap.h can't be open!"); } - + } else { throw new AutoGenException("The file, flashMap.h doesn't exist!"); } @@ -1937,269 +2023,252 @@ public class AutoGen { private void collectLibInstanceInfo() throws EdkException{ int index; + String moduleType = moduleId.getModuleType(); String libConstructName = null; String libDestructName = null; - String libModuleType = null; + String libModuleType = null; String[] setVirtuals = null; String[] exitBoots = null; ModuleIdentification[] libraryIdList = saq.getLibraryInstance(this.arch); + if (libraryIdList.length <= 0) { + return; + } + // + // Reorder library instance sequence. + // + AutogenLibOrder libOrder = new AutogenLibOrder(libraryIdList, this.arch); + List orderList = libOrder.orderLibInstance(); + // + // Process library instance one by one. + // + for (int i = 0; i < orderList.size(); i++) { + // + // Get library instance basename. + // + ModuleIdentification libInstanceId = orderList.get(i); + + // + // Get override map + // + + Map libDoc = GlobalData.getDoc(libInstanceId, this.arch); + saq.push(libDoc); + // + // check if the library instance support current module + // + String[] libraryClassList = saq.getLibraryClasses(CommonDefinition.ALWAYSPRODUCED, + this.arch, + moduleType + ); + if (libraryClassList.length <= 0) { + throw new EdkException("Library instance " + libInstanceId.getName() + + " doesn't support module type " + moduleType); + } + // + // Get CName list from , , , etc. of this library + // instance. + // + String[] guidCNameList = saq.getCNameArray(this.arch); + PackageIdentification[] pkgList = saq.getDependencePkg(this.arch); - if (libraryIdList != null) { - // - // Reorder library instance sequence. - // - AutogenLibOrder libOrder = new AutogenLibOrder(libraryIdList, - this.arch); - List orderList = libOrder - .orderLibInstance(); - - if (orderList != null) { - // - // Process library instance one by one. - // - for (int i = 0; i < orderList.size(); i++) { - // - // Get library instance basename. - // - ModuleIdentification libInstanceId = orderList.get(i); - - // - // Get override map - // - - Map libDoc = GlobalData.getDoc(libInstanceId, this.arch); - saq.push(libDoc); - // - // Get , , list of this library - // instance. - // - String[] ppiList = saq.getPpiArray(this.arch); - String[] ppiNotifyList = saq.getPpiNotifyArray(this.arch); - String[] protocolList = saq.getProtocolArray(this.arch); - String[] protocolNotifyList = saq.getProtocolNotifyArray(this.arch); - String[] guidList = saq.getGuidEntryArray(this.arch); - PackageIdentification[] pkgList = saq.getDependencePkg(this.arch); - - // - // Add those ppi, protocol, guid in global ppi, - // protocol, guid - // list. - // - for (index = 0; index < ppiList.length; index++) { - this.mPpiList.add(ppiList[index]); - } - - for (index = 0; index < ppiNotifyList.length; index++) { - this.mPpiList.add(ppiNotifyList[index]); - } - - for (index = 0; index < protocolList.length; index++) { - this.mProtocolList.add(protocolList[index]); - } - - for (index = 0; index < protocolNotifyList.length; index++) { - this.mProtocolList.add(protocolNotifyList[index]); - } - - for (index = 0; index < guidList.length; index++) { - this.mGuidList.add(guidList[index]); - } - for (index = 0; index < pkgList.length; index++) { - if (!this.mDepPkgList.contains(pkgList[index])) { - this.mDepPkgList.add(pkgList[index]); - } - } - - // - // If not yet parse this library instance's constructor - // element,parse it. - // - libConstructName = saq.getLibConstructorName(); - libDestructName = saq.getLibDestructorName(); - libModuleType = saq.getModuleType(); - - // - // Collect SetVirtualAddressMapCallBack and - // ExitBootServiceCallBack. - // - setVirtuals = saq.getSetVirtualAddressMapCallBackArray(); - exitBoots = saq.getExitBootServicesCallBackArray(); - if (setVirtuals != null) { - for (int j = 0; j < setVirtuals.length; j++) { - this.setVirtalAddList.add(setVirtuals[j]); - } - } - if (exitBoots != null) { - for (int k = 0; k < exitBoots.length; k++) { - this.exitBootServiceList.add(exitBoots[k]); - } - } - saq.pop(); - // - // Add dependent library instance constructor function. - // - if (libConstructName != null) { - this.libConstructList.add(new String[] {libConstructName, libModuleType}); - } - // - // Add dependent library instance destructor fuction. - // - if (libDestructName != null) { - this.libDestructList.add(new String[] {libDestructName, libModuleType}); - } - } - } - } + // + // Add those ppi, protocol, guid in global ppi, + // protocol, guid + // list. + // + for (index = 0; index < guidCNameList.length; index++) { + this.mGuidCNameList.add(guidCNameList[index]); + } + + for (index = 0; index < pkgList.length; index++) { + if (!this.mDepPkgList.contains(pkgList[index])) { + this.mDepPkgList.add(pkgList[index]); + } + } + + // + // If not yet parse this library instance's constructor + // element,parse it. + // + libConstructName = saq.getLibConstructorName(); + libDestructName = saq.getLibDestructorName(); + libModuleType = saq.getModuleType(); + + // + // Collect SetVirtualAddressMapCallBack and + // ExitBootServiceCallBack. + // + setVirtuals = saq.getSetVirtualAddressMapCallBackArray(); + exitBoots = saq.getExitBootServicesCallBackArray(); + if (setVirtuals != null) { + for (int j = 0; j < setVirtuals.length; j++) { + this.setVirtalAddList.add(setVirtuals[j]); + } + } + if (exitBoots != null) { + for (int k = 0; k < exitBoots.length; k++) { + this.exitBootServiceList.add(exitBoots[k]); + } + } + saq.pop(); + // + // Add dependent library instance constructor function. + // + if (libConstructName != null) { + this.libConstructList.add(new String[] {libConstructName, libModuleType}); + } + // + // Add dependent library instance destructor fuction. + // + if (libDestructName != null) { + this.libDestructList.add(new String[] {libDestructName, libModuleType}); + } + } } + private void setVirtualAddressToAutogenC(StringBuffer fileBuffer){ // // Entry point lib for these module types needs to know the count // of entryPoint. // - fileBuffer - .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverSetVirtualAddressMapEventCount = "); - - // - // If the list is not valid or has no entries set count to zero else - // set count to the number of valid entries - // - int Count = 0; - int i = 0; - if (this.setVirtalAddList != null) { - for (i = 0; i < this.setVirtalAddList.size(); i++) { - if (this.setVirtalAddList.get(i).equalsIgnoreCase("")) { - break; - } - } - Count = i; - } - - fileBuffer.append(Integer.toString(Count)); - fileBuffer.append(";\r\n\r\n"); - if (this.setVirtalAddList == null || this.setVirtalAddList.size() == 0) { - // - // No data so make a NULL list - // - fileBuffer - .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {\r\n"); - fileBuffer.append(" NULL\r\n"); - fileBuffer.append("};\r\n\r\n"); - } else { - // - // Write SetVirtualAddressMap function definition. - // - for (i = 0; i < this.setVirtalAddList.size(); i++) { - if (this.setVirtalAddList.get(i).equalsIgnoreCase("")) { - break; - } - fileBuffer.append("VOID\r\n"); - fileBuffer.append("EFIAPI\r\n"); - fileBuffer.append(this.setVirtalAddList.get(i)); - fileBuffer.append(" (\r\n"); - fileBuffer.append(" IN EFI_EVENT Event,\r\n"); - fileBuffer.append(" IN VOID *Context\r\n"); - fileBuffer.append(" );\r\n\r\n"); - } - - // - // Write SetVirtualAddressMap entry point array. - // - fileBuffer - .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {"); - for (i = 0; i < this.setVirtalAddList.size(); i++) { - if (this.setVirtalAddList.get(i).equalsIgnoreCase("")) { - break; - } - - if (i == 0) { - fileBuffer.append("\r\n "); - } else { - fileBuffer.append(",\r\n "); - } - - fileBuffer.append(this.setVirtalAddList.get(i)); - } - // - // add the NULL at the end of _gDriverSetVirtualAddressMapEvent list. - // - fileBuffer.append(",\r\n NULL"); - fileBuffer.append("\r\n};\r\n\r\n"); - } - } - - - private void setExitBootServiceToAutogenC(StringBuffer fileBuffer){ - // - // Entry point lib for these module types needs to know the count. - // - fileBuffer - .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverExitBootServicesEventCount = "); - - // - // If the list is not valid or has no entries set count to zero else - // set count to the number of valid entries. - // - int Count = 0; - int i = 0; - if (this.exitBootServiceList != null) { - for (i = 0; i < this.exitBootServiceList.size(); i++) { - if (this.exitBootServiceList.get(i).equalsIgnoreCase("")) { - break; - } - } - Count = i; - } - fileBuffer.append(Integer.toString(Count)); - fileBuffer.append(";\r\n\r\n"); - - if (this.exitBootServiceList == null || this.exitBootServiceList.size() == 0) { - // - // No data so make a NULL list. - // - fileBuffer - .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {\r\n"); - fileBuffer.append(" NULL\r\n"); - fileBuffer.append("};\r\n\r\n"); - } else { - // - // Write DriverExitBootServices function definition. - // - for (i = 0; i < this.exitBootServiceList.size(); i++) { - if (this.exitBootServiceList.get(i).equalsIgnoreCase("")) { - break; - } - - fileBuffer.append("VOID\r\n"); - fileBuffer.append("EFIAPI\r\n"); - fileBuffer.append(this.exitBootServiceList.get(i)); - fileBuffer.append(" (\r\n"); - fileBuffer.append(" IN EFI_EVENT Event,\r\n"); - fileBuffer.append(" IN VOID *Context\r\n"); - fileBuffer.append(" );\r\n\r\n"); - } - - // - // Write DriverExitBootServices entry point array. - // - fileBuffer - .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {"); - for (i = 0; i < this.exitBootServiceList.size(); i++) { - if (this.exitBootServiceList.get(i).equalsIgnoreCase("")) { - break; - } - - if (i == 0) { - fileBuffer.append("\r\n "); - } else { - fileBuffer.append(",\r\n "); - } - fileBuffer.append(this.exitBootServiceList.get(i)); - } - - fileBuffer.append(",\r\n NULL"); - fileBuffer.append("\r\n};\r\n\r\n"); - } + fileBuffer.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverSetVirtualAddressMapEventCount = "); + + // + // If the list is not valid or has no entries set count to zero else + // set count to the number of valid entries + // + int Count = 0; + int i = 0; + if (this.setVirtalAddList != null) { + for (i = 0; i < this.setVirtalAddList.size(); i++) { + if (this.setVirtalAddList.get(i).equalsIgnoreCase("")) { + break; + } + } + Count = i; + } + + fileBuffer.append(Integer.toString(Count)); + fileBuffer.append(";\r\n\r\n"); + if (this.setVirtalAddList == null || this.setVirtalAddList.size() == 0) { + // + // No data so make a NULL list + // + fileBuffer.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {\r\n"); + fileBuffer.append(" NULL\r\n"); + fileBuffer.append("};\r\n\r\n"); + } else { + // + // Write SetVirtualAddressMap function definition. + // + for (i = 0; i < this.setVirtalAddList.size(); i++) { + if (this.setVirtalAddList.get(i).equalsIgnoreCase("")) { + break; + } + functionDeclarations.append("VOID\r\n"); + functionDeclarations.append("EFIAPI\r\n"); + functionDeclarations.append(this.setVirtalAddList.get(i)); + functionDeclarations.append(" (\r\n"); + functionDeclarations.append(" IN EFI_EVENT Event,\r\n"); + functionDeclarations.append(" IN VOID *Context\r\n"); + functionDeclarations.append(" );\r\n\r\n"); + } + + // + // Write SetVirtualAddressMap entry point array. + // + fileBuffer.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {"); + for (i = 0; i < this.setVirtalAddList.size(); i++) { + if (this.setVirtalAddList.get(i).equalsIgnoreCase("")) { + break; + } + + if (i == 0) { + fileBuffer.append("\r\n "); + } else { + fileBuffer.append(",\r\n "); + } + + fileBuffer.append(this.setVirtalAddList.get(i)); + } + // + // add the NULL at the end of _gDriverSetVirtualAddressMapEvent list. + // + fileBuffer.append(",\r\n NULL"); + fileBuffer.append("\r\n};\r\n\r\n"); + } + } + + + private void setExitBootServiceToAutogenC(StringBuffer fileBuffer){ + // + // Entry point lib for these module types needs to know the count. + // + fileBuffer.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverExitBootServicesEventCount = "); + + // + // If the list is not valid or has no entries set count to zero else + // set count to the number of valid entries. + // + int Count = 0; + int i = 0; + if (this.exitBootServiceList != null) { + for (i = 0; i < this.exitBootServiceList.size(); i++) { + if (this.exitBootServiceList.get(i).equalsIgnoreCase("")) { + break; + } + } + Count = i; + } + fileBuffer.append(Integer.toString(Count)); + fileBuffer.append(";\r\n\r\n"); + + if (this.exitBootServiceList == null || this.exitBootServiceList.size() == 0) { + // + // No data so make a NULL list. + // + fileBuffer.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {\r\n"); + fileBuffer.append(" NULL\r\n"); + fileBuffer.append("};\r\n\r\n"); + } else { + // + // Write DriverExitBootServices function definition. + // + for (i = 0; i < this.exitBootServiceList.size(); i++) { + if (this.exitBootServiceList.get(i).equalsIgnoreCase("")) { + break; + } + + functionDeclarations.append("VOID\r\n"); + functionDeclarations.append("EFIAPI\r\n"); + functionDeclarations.append(this.exitBootServiceList.get(i)); + functionDeclarations.append(" (\r\n"); + functionDeclarations.append(" IN EFI_EVENT Event,\r\n"); + functionDeclarations.append(" IN VOID *Context\r\n"); + functionDeclarations.append(" );\r\n\r\n"); + } + + // + // Write DriverExitBootServices entry point array. + // + fileBuffer.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {"); + for (i = 0; i < this.exitBootServiceList.size(); i++) { + if (this.exitBootServiceList.get(i).equalsIgnoreCase("")) { + break; + } + + if (i == 0) { + fileBuffer.append("\r\n "); + } else { + fileBuffer.append(",\r\n "); + } + fileBuffer.append(this.exitBootServiceList.get(i)); + } + + fileBuffer.append(",\r\n NULL"); + fileBuffer.append("\r\n};\r\n\r\n"); + } } /** setPcdComponentName @@ -2209,13 +2278,13 @@ public class AutoGen { **/ public void setPcdComponentName (){ - String pcdValue = null; - pcdValue = saq.getPcdValueBycName("PcdComponentNameDisable"); - if (pcdValue != null && pcdValue.equalsIgnoreCase("true")) { + String pcdValue = null; + pcdValue = saq.getPcdValueBycName("PcdComponentNameDisable"); + if (pcdValue != null && pcdValue.equalsIgnoreCase("true")) { this.componentNamePcd = true; - } + } } - + /** setPcdDriverDiagnostic @@ -2224,11 +2293,11 @@ public class AutoGen { **/ public void setPcdDriverDiagnostic (){ - String pcdValue = null; + String pcdValue = null; pcdValue = saq.getPcdValueBycName("PcdDriverDiagnosticsDisable"); - if (pcdValue != null && pcdValue.equalsIgnoreCase("true")) { + if (pcdValue != null && pcdValue.equalsIgnoreCase("true")) { this.driverDiagnostPcd = true; - } + } } - + }