]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Java/Source/GenBuild/org/tianocore/build/autogen/AutoGen.java
Moved the function prototype of SetVirtualAddress and ExitBootService to AutoGen...
[mirror_edk2.git] / Tools / Java / Source / GenBuild / org / tianocore / build / autogen / AutoGen.java
index 5b917b9ab499c7dc7f2893d827d1e3bdb375ac95..5925e504f63f9bb81a94fed2aeabaf1238643fe5 100644 (file)
@@ -119,6 +119,8 @@ public class AutoGen {
     private List<String> setVirtalAddList = new ArrayList<String>();\r
     private List<String> exitBootServiceList = new ArrayList<String>();\r
 \r
+    private StringBuffer functionDeclarations = new StringBuffer(10240);\r
+\r
     //\r
     // flag of PcdComponentNameDisable, PcdDriverDiagnosticDisable \r
     //\r
@@ -382,6 +384,7 @@ public class AutoGen {
             fileBuffer.append(this.myPcdAutogen.getHAutoGenString());\r
         }\r
 \r
+        fileBuffer.append(functionDeclarations);\r
         //\r
         // Append the #endif at AutoGen.h\r
         //\r
@@ -411,11 +414,6 @@ public class AutoGen {
         //\r
         fileBuffer.append(CommonDefinition.AUTOGENCNOTATION);\r
 \r
-        //\r
-        // Write #include <AutoGen.h> at beginning of AutoGen.c\r
-        //\r
-        fileBuffer.append(CommonDefinition.INCLUDEAUTOGENH);\r
-\r
         //\r
         // Get the native MSA file infomation. Since before call autogen,\r
         // the MSA native <Externs> information were overrided. So before\r
@@ -568,8 +566,7 @@ public class AutoGen {
         fileBuffer.append(CommonDefinition.AUTOGENHBEGIN);\r
         String[] specList = saq.getExternSpecificaiton();\r
         for (int i = 0; i < specList.length; i++) {\r
-            fileBuffer.append(CommonDefinition.DEFINE + specList[i]\r
-                              + "\r\n");\r
+            fileBuffer.append(CommonDefinition.DEFINE + specList[i] + "\r\n");\r
         }\r
         // fileBuffer.append(CommonDefinition.autoGenHLine1);\r
         // fileBuffer.append(CommonDefinition.autoGenHLine2);\r
@@ -578,8 +575,7 @@ public class AutoGen {
         // Write consumed package's mdouleInfo related *.h file to autogen.h.\r
         //\r
         moduleType = saq.getModuleType();\r
-        PackageIdentification[] cosumedPkglist = saq\r
-                                                 .getDependencePkg(this.arch);\r
+        PackageIdentification[] cosumedPkglist = saq.getDependencePkg(this.arch);\r
         headerFileList = depPkgToAutogenH(cosumedPkglist, moduleType);\r
         item = headerFileList.iterator();\r
         while (item.hasNext()) {\r
@@ -625,12 +621,17 @@ public class AutoGen {
             fileBuffer.append("\r\n");\r
             fileBuffer.append(this.myPcdAutogen.getHAutoGenString());\r
         }\r
-\r
+        //\r
+        // generate function prototype for constructor and destructor\r
+        // \r
+        LibConstructorToAutogenH(moduleType);\r
+        LibDestructorToAutogenH(moduleType);\r
+        ExternCallBackToAutoGenH(moduleType);\r
+        fileBuffer.append(functionDeclarations);\r
         //\r
         // Append the #endif at AutoGen.h\r
         //\r
         fileBuffer.append("#endif\r\n");\r
-\r
         //\r
         // Save content of string buffer to AutoGen.h file.\r
         //\r
@@ -749,8 +750,7 @@ public class AutoGen {
                                            + packageNameList[i]\r
                                            + "] declaration in any SPD package. ");\r
             } else if (!pkgHeader.equalsIgnoreCase("")) {\r
-                includeStr = CommonDefinition.INCLUDE + " <" + pkgHeader\r
-                             + ">\r\n";\r
+                includeStr = CommonDefinition.INCLUDE + " <" + pkgHeader + ">\r\n";\r
                 includeStrList.add(includeStr);\r
             }\r
         }\r
@@ -774,7 +774,7 @@ public class AutoGen {
     throws EdkException {\r
 \r
         String typeStr = saq.getModuleType();\r
-        String debugStr = "DEBUG ((EFI_D_INFO | EFI_D_LOAD, \"Module Entry Point (%s) 0x%%p\\n\", (VOID *)(UINTN)%s));\n";\r
+        String debugStr = "DEBUG ((EFI_D_INFO | EFI_D_LOAD, \"Module Entry Point (%s) 0x%%p\\n\", (VOID *)(UINTN)%s));\r\n";\r
         int unloadImageCount = 0;\r
         int entryPointCount  = 0;\r
 \r
@@ -786,10 +786,10 @@ public class AutoGen {
         \r
         case CommonDefinition.ModuleTypePeiCore:\r
             if (entryPointList == null ||entryPointList.length != 1 ) {\r
-                throw new AutoGenException(\r
-                                          "Module type = 'PEI_CORE', can have only one module entry point!");\r
+                throw new AutoGenException("Module type = 'PEI_CORE', can have only one module entry point!");\r
             } else {\r
                 fileBuffer.append("EFI_STATUS\r\n");\r
+                fileBuffer.append("EFIAPI\r\n");\r
                 fileBuffer.append(entryPointList[0]);\r
                 fileBuffer.append(" (\r\n");\r
                 fileBuffer.append("  IN EFI_PEI_STARTUP_DESCRIPTOR  *PeiStartupDescriptor,\r\n");\r
@@ -816,8 +816,9 @@ public class AutoGen {
                 throw new AutoGenException("Module type = 'DXE_CORE', can have only one module entry point!");\r
             } else {\r
                 fileBuffer.append("VOID\r\n");\r
+                fileBuffer.append("EFIAPI\r\n");\r
                 fileBuffer.append(entryPointList[0]);\r
-                fileBuffer.append(" (\n");\r
+                fileBuffer.append(" (\r\n");\r
                 fileBuffer.append("  IN VOID  *HobStart\r\n");\r
                 fileBuffer.append("  );\r\n\r\n");\r
 \r
@@ -851,6 +852,7 @@ public class AutoGen {
             }\r
             for (int i = 0; i < entryPointList.length; i++) {\r
                 fileBuffer.append("EFI_STATUS\r\n");\r
+                fileBuffer.append("EFIAPI\r\n");\r
                 fileBuffer.append(entryPointList[i]);\r
                 fileBuffer.append(" (\r\n");\r
                 fileBuffer.append("  IN EFI_FFS_FILE_HEADER  *FfsHeader,\r\n");\r
@@ -916,6 +918,7 @@ public class AutoGen {
             } else {\r
                 for (int i = 0; i < entryPointList.length; i++) {\r
                     fileBuffer.append("EFI_STATUS\r\n");\r
+                    fileBuffer.append("EFIAPI\r\n");\r
                     fileBuffer.append(entryPointList[i]);\r
                     fileBuffer.append(" (\r\n");\r
                     fileBuffer.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
@@ -952,7 +955,7 @@ public class AutoGen {
                 fileBuffer.append("VOID\r\n");\r
                 fileBuffer.append("EFIAPI\r\n");\r
                 fileBuffer.append("ExitDriver (\r\n");\r
-                fileBuffer.append("  IN EFI_STATUS  Status\n");\r
+                fileBuffer.append("  IN EFI_STATUS  Status\r\n");\r
                 fileBuffer.append("  )\r\n\r\n");\r
                 fileBuffer.append("{\r\n");\r
                 fileBuffer.append("  if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");\r
@@ -967,9 +970,6 @@ public class AutoGen {
             //\r
             // Add "ModuleUnloadImage" for DxeSmmDriver module type;\r
             //\r
-            //entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();\r
-            //entryPointList = CommonDefinition.remDupString(entryPointList);\r
-            //entryPointCount = 0;\r
 \r
             unloadImageCount = 0;\r
             if (unloadImageList != null) {\r
@@ -1049,8 +1049,8 @@ public class AutoGen {
 \r
             } else {\r
                 for (int i = 0; i < entryPointList.length; i++) {\r
-\r
                     fileBuffer.append("EFI_STATUS\r\n");\r
+                    fileBuffer.append("EFIAPI\r\n");\r
                     fileBuffer.append(entryPointList[i]);\r
                     fileBuffer.append(" (\r\n");\r
                     fileBuffer.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
@@ -1066,7 +1066,7 @@ public class AutoGen {
                     fileBuffer.append("static BASE_LIBRARY_JUMP_BUFFER  mJumpContext;\r\n");\r
                     fileBuffer.append("static EFI_STATUS  mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n");\r
                 }\r
-                fileBuffer.append("\n");\r
+                fileBuffer.append("\r\n");\r
 \r
                 fileBuffer.append("EFI_STATUS\r\n");\r
                 fileBuffer.append("EFIAPI\r\n");\r
@@ -1147,7 +1147,7 @@ public class AutoGen {
             fileBuffer.append(Integer.toString(unloadImageCount));\r
             fileBuffer.append(";\r\n\r\n");\r
 \r
-            fileBuffer.append("EFI_STATUS\n");\r
+            fileBuffer.append("EFI_STATUS\r\n");\r
             fileBuffer.append("EFIAPI\r\n");\r
             fileBuffer.append("ProcessModuleUnloadList (\r\n");\r
             fileBuffer.append("  IN EFI_HANDLE  ImageHandle\r\n");\r
@@ -1362,6 +1362,152 @@ public class AutoGen {
         LibDestructorToAutogenC(libDestructList, moduleType, fileBuffer/* autogenC */);\r
     }\r
 \r
+    /**\r
+      LibConstructorToAutogenH\r
+     \r
+      This function writes library constructor declarations AutoGen.h. The library\r
+      constructor's parameter and return value depend on module type.\r
+     \r
+      @param libInstanceList\r
+                 List of library construct name.\r
+      @param moduleType\r
+                 Module type.\r
+      @param fileBuffer\r
+                 String buffer for AutoGen.c\r
+      @throws Exception\r
+    **/\r
+    void LibConstructorToAutogenH(String moduleType) throws EdkException {\r
+        boolean isFirst = true;\r
+\r
+        //\r
+        // If not yet parse this library instance's constructor\r
+        // element,parse it.\r
+        //\r
+        String libConstructName = saq.getLibConstructorName();\r
+        if (libConstructName == null) {\r
+            return;\r
+        }\r
+\r
+        //\r
+        // The library constructor's parameter and return value depend on\r
+        // module type.\r
+        //\r
+        if (moduleType.equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) {\r
+            functionDeclarations.append("RETURN_STATUS\r\n");\r
+            functionDeclarations.append("EFIAPI\r\n");\r
+            functionDeclarations.append(libConstructName);\r
+            functionDeclarations.append(" (\r\n");\r
+            functionDeclarations.append("  VOID\r\n");\r
+            functionDeclarations.append("  );\r\n");\r
+        } else {\r
+            switch (CommonDefinition.getModuleType(moduleType)) {\r
+            case CommonDefinition.ModuleTypeBase:\r
+                functionDeclarations.append("RETURN_STATUS\r\n");\r
+                functionDeclarations.append("EFIAPI\r\n");\r
+                functionDeclarations.append(libConstructName);\r
+                functionDeclarations.append(" (\r\n");\r
+                functionDeclarations.append("  VOID\r\n");\r
+                functionDeclarations.append("  );\r\n");\r
+                break;\r
+\r
+            case CommonDefinition.ModuleTypePeiCore:\r
+            case CommonDefinition.ModuleTypePeim:\r
+                functionDeclarations.append("EFI_STATUS\r\n");\r
+                functionDeclarations.append("EFIAPI\r\n");\r
+                functionDeclarations.append(libConstructName);\r
+                functionDeclarations.append(" (\r\n");\r
+                functionDeclarations.append("  IN EFI_FFS_FILE_HEADER       *FfsHeader,\r\n");\r
+                functionDeclarations.append("  IN EFI_PEI_SERVICES          **PeiServices\r\n");\r
+                functionDeclarations.append("  );\r\n");\r
+                break;\r
+\r
+            case CommonDefinition.ModuleTypeDxeCore:\r
+            case CommonDefinition.ModuleTypeDxeDriver:\r
+            case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
+            case CommonDefinition.ModuleTypeDxeSmmDriver:\r
+            case CommonDefinition.ModuleTypeDxeSalDriver:\r
+            case CommonDefinition.ModuleTypeUefiDriver:\r
+            case CommonDefinition.ModuleTypeUefiApplication:\r
+                functionDeclarations.append("EFI_STATUS\r\n");\r
+                functionDeclarations.append("EFIAPI\r\n");\r
+                functionDeclarations.append(libConstructName);\r
+                functionDeclarations.append(" (\r\n");\r
+                functionDeclarations.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
+                functionDeclarations.append("  IN EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
+                functionDeclarations.append("  );\r\n");\r
+                break;\r
+\r
+            }\r
+        }\r
+    }\r
+\r
+    /**\r
+      LibDestructorToAutogenH\r
+     \r
+      This function writes library destructor declarations AutoGen.h. The library\r
+      destructor's parameter and return value depend on module type.\r
+     \r
+      @param libInstanceList\r
+                 List of library destructor name.\r
+      @param moduleType\r
+                 Module type.\r
+      @param fileBuffer\r
+                 String buffer for AutoGen.c\r
+      @throws Exception\r
+    **/\r
+    void LibDestructorToAutogenH(String moduleType) throws EdkException {\r
+        boolean isFirst = true;\r
+        String libDestructName = saq.getLibDestructorName();\r
+        if (libDestructName == null) {\r
+            return;\r
+        }\r
+\r
+        if (moduleType.equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) {\r
+            functionDeclarations.append("RETURN_STATUS\r\n");\r
+            functionDeclarations.append("EFIAPI\r\n");\r
+            functionDeclarations.append(libDestructName);\r
+            functionDeclarations.append(" (\r\n");\r
+            functionDeclarations.append("  VOID\r\n");\r
+            functionDeclarations.append("  );\r\n");\r
+        } else {\r
+            switch (CommonDefinition.getModuleType(moduleType)) {\r
+            case CommonDefinition.ModuleTypeBase:\r
+                functionDeclarations.append("RETURN_STATUS\r\n");\r
+                functionDeclarations.append("EFIAPI\r\n");\r
+                functionDeclarations.append(libDestructName);\r
+                functionDeclarations.append(" (\r\n");\r
+                functionDeclarations.append("  VOID\r\n");\r
+                functionDeclarations.append("  );\r\n");\r
+                break;\r
+            case CommonDefinition.ModuleTypePeiCore:\r
+            case CommonDefinition.ModuleTypePeim:\r
+                functionDeclarations.append("EFI_STATUS\r\n");\r
+                functionDeclarations.append("EFIAPI\r\n");\r
+                functionDeclarations.append(libDestructName);\r
+                functionDeclarations.append(" (\r\n");\r
+                functionDeclarations.append("  IN EFI_FFS_FILE_HEADER       *FfsHeader,\r\n");\r
+                functionDeclarations.append("  IN EFI_PEI_SERVICES          **PeiServices\r\n");\r
+                functionDeclarations.append("  );\r\n");\r
+                break;\r
+            case CommonDefinition.ModuleTypeDxeCore:\r
+            case CommonDefinition.ModuleTypeDxeDriver:\r
+            case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
+            case CommonDefinition.ModuleTypeDxeSmmDriver:\r
+            case CommonDefinition.ModuleTypeDxeSalDriver:\r
+            case CommonDefinition.ModuleTypeUefiDriver:\r
+            case CommonDefinition.ModuleTypeUefiApplication:\r
+                functionDeclarations.append("EFI_STATUS\r\n");\r
+                functionDeclarations.append("EFIAPI\r\n");\r
+                functionDeclarations.append(libDestructName);\r
+                functionDeclarations.append(" (\r\n");\r
+                functionDeclarations.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
+                functionDeclarations.append("  IN EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
+                functionDeclarations.append("  );\r\n");\r
+                break;\r
+            }\r
+        }\r
+    }\r
+\r
     /**\r
       LibConstructorToAutogenc\r
      \r
@@ -1386,32 +1532,32 @@ public class AutoGen {
         //\r
         for (int i = 0; i < libInstanceList.size(); i++) {\r
             if (libInstanceList.get(i)[1].equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) {\r
-                fileBuffer.append("RETURN_STATUS\r\n");\r
-                fileBuffer.append("EFIAPI\r\n");\r
-                fileBuffer.append(libInstanceList.get(i)[0]);\r
-                fileBuffer.append(" (\r\n");\r
-                fileBuffer.append("  VOID\r\n");\r
-                fileBuffer.append("  );\r\n");\r
+                functionDeclarations.append("RETURN_STATUS\r\n");\r
+                functionDeclarations.append("EFIAPI\r\n");\r
+                functionDeclarations.append(libInstanceList.get(i)[0]);\r
+                functionDeclarations.append(" (\r\n");\r
+                functionDeclarations.append("  VOID\r\n");\r
+                functionDeclarations.append("  );\r\n");\r
             } else {\r
                 switch (CommonDefinition.getModuleType(moduleType)) {\r
                 case CommonDefinition.ModuleTypeBase:\r
-                    fileBuffer.append("RETURN_STATUS\r\n");\r
-                    fileBuffer.append("EFIAPI\r\n");\r
-                    fileBuffer.append(libInstanceList.get(i)[0]);\r
-                    fileBuffer.append(" (\r\n");\r
-                    fileBuffer.append("  VOID\r\n");\r
-                    fileBuffer.append("  );\r\n");\r
+                    functionDeclarations.append("RETURN_STATUS\r\n");\r
+                    functionDeclarations.append("EFIAPI\r\n");\r
+                    functionDeclarations.append(libInstanceList.get(i)[0]);\r
+                    functionDeclarations.append(" (\r\n");\r
+                    functionDeclarations.append("  VOID\r\n");\r
+                    functionDeclarations.append("  );\r\n");\r
                     break;\r
 \r
                 case CommonDefinition.ModuleTypePeiCore:\r
                 case CommonDefinition.ModuleTypePeim:\r
-                    fileBuffer.append("EFI_STATUS\r\n");\r
-                    fileBuffer.append("EFIAPI\r\n");\r
-                    fileBuffer.append(libInstanceList.get(i)[0]);\r
-                    fileBuffer.append(" (\r\n");\r
-                    fileBuffer.append("  IN EFI_FFS_FILE_HEADER       *FfsHeader,\r\n");\r
-                    fileBuffer.append("  IN EFI_PEI_SERVICES          **PeiServices\r\n");\r
-                    fileBuffer.append("  );\r\n");\r
+                    functionDeclarations.append("EFI_STATUS\r\n");\r
+                    functionDeclarations.append("EFIAPI\r\n");\r
+                    functionDeclarations.append(libInstanceList.get(i)[0]);\r
+                    functionDeclarations.append(" (\r\n");\r
+                    functionDeclarations.append("  IN EFI_FFS_FILE_HEADER       *FfsHeader,\r\n");\r
+                    functionDeclarations.append("  IN EFI_PEI_SERVICES          **PeiServices\r\n");\r
+                    functionDeclarations.append("  );\r\n");\r
                     break;\r
 \r
                 case CommonDefinition.ModuleTypeDxeCore:\r
@@ -1421,13 +1567,13 @@ public class AutoGen {
                 case CommonDefinition.ModuleTypeDxeSalDriver:\r
                 case CommonDefinition.ModuleTypeUefiDriver:\r
                 case CommonDefinition.ModuleTypeUefiApplication:\r
-                    fileBuffer.append("EFI_STATUS\r\n");\r
-                    fileBuffer.append("EFIAPI\r\n");\r
-                    fileBuffer.append(libInstanceList.get(i)[0]);\r
-                    fileBuffer.append(" (\r\n");\r
-                    fileBuffer.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
-                    fileBuffer.append("  IN EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
-                    fileBuffer.append("  );\r\n");\r
+                    functionDeclarations.append("EFI_STATUS\r\n");\r
+                    functionDeclarations.append("EFIAPI\r\n");\r
+                    functionDeclarations.append(libInstanceList.get(i)[0]);\r
+                    functionDeclarations.append(" (\r\n");\r
+                    functionDeclarations.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
+                    functionDeclarations.append("  IN EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
+                    functionDeclarations.append("  );\r\n");\r
                     break;\r
 \r
                 }\r
@@ -1469,9 +1615,6 @@ public class AutoGen {
         //\r
         // If no constructor function, return EFI_SUCCESS.\r
         //\r
-        //if (libInstanceList.size() == 0){\r
-        //   fileBuffer.append("  return EFI_SUCCESS;\r\n");\r
-        //}\r
         for (int i = 0; i < libInstanceList.size(); i++) {\r
             if (isFirst) {\r
                 fileBuffer.append("  EFI_STATUS  Status;\r\n");\r
@@ -1536,31 +1679,31 @@ public class AutoGen {
         boolean isFirst = true;\r
         for (int i = 0; i < libInstanceList.size(); i++) {\r
             if (libInstanceList.get(i)[1].equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) {\r
-                fileBuffer.append("RETURN_STATUS\r\n");\r
-                fileBuffer.append("EFIAPI\r\n");\r
-                fileBuffer.append(libInstanceList.get(i)[0]);\r
-                fileBuffer.append(" (\r\n");\r
-                fileBuffer.append("  VOID\r\n");\r
-                fileBuffer.append("  );\r\n");\r
+                functionDeclarations.append("RETURN_STATUS\r\n");\r
+                functionDeclarations.append("EFIAPI\r\n");\r
+                functionDeclarations.append(libInstanceList.get(i)[0]);\r
+                functionDeclarations.append(" (\r\n");\r
+                functionDeclarations.append("  VOID\r\n");\r
+                functionDeclarations.append("  );\r\n");\r
             } else {\r
                 switch (CommonDefinition.getModuleType(moduleType)) {\r
                 case CommonDefinition.ModuleTypeBase:\r
-                    fileBuffer.append("RETURN_STATUS\r\n");\r
-                    fileBuffer.append("EFIAPI\r\n");\r
-                    fileBuffer.append(libInstanceList.get(i)[0]);\r
-                    fileBuffer.append(" (\r\n");\r
-                    fileBuffer.append("  VOID\r\n");\r
-                    fileBuffer.append("  );\r\n");\r
+                    functionDeclarations.append("RETURN_STATUS\r\n");\r
+                    functionDeclarations.append("EFIAPI\r\n");\r
+                    functionDeclarations.append(libInstanceList.get(i)[0]);\r
+                    functionDeclarations.append(" (\r\n");\r
+                    functionDeclarations.append("  VOID\r\n");\r
+                    functionDeclarations.append("  );\r\n");\r
                     break;\r
                 case CommonDefinition.ModuleTypePeiCore:\r
                 case CommonDefinition.ModuleTypePeim:\r
-                    fileBuffer.append("EFI_STATUS\r\n");\r
-                    fileBuffer.append("EFIAPI\r\n");\r
-                    fileBuffer.append(libInstanceList.get(i)[0]);\r
-                    fileBuffer.append(" (\r\n");\r
-                    fileBuffer.append("  IN EFI_FFS_FILE_HEADER       *FfsHeader,\r\n");\r
-                    fileBuffer.append("  IN EFI_PEI_SERVICES          **PeiServices\r\n");\r
-                    fileBuffer.append("  );\r\n");\r
+                    functionDeclarations.append("EFI_STATUS\r\n");\r
+                    functionDeclarations.append("EFIAPI\r\n");\r
+                    functionDeclarations.append(libInstanceList.get(i)[0]);\r
+                    functionDeclarations.append(" (\r\n");\r
+                    functionDeclarations.append("  IN EFI_FFS_FILE_HEADER       *FfsHeader,\r\n");\r
+                    functionDeclarations.append("  IN EFI_PEI_SERVICES          **PeiServices\r\n");\r
+                    functionDeclarations.append("  );\r\n");\r
                     break;\r
                 case CommonDefinition.ModuleTypeDxeCore:\r
                 case CommonDefinition.ModuleTypeDxeDriver:\r
@@ -1569,13 +1712,13 @@ public class AutoGen {
                 case CommonDefinition.ModuleTypeDxeSalDriver:\r
                 case CommonDefinition.ModuleTypeUefiDriver:\r
                 case CommonDefinition.ModuleTypeUefiApplication:\r
-                    fileBuffer.append("EFI_STATUS\r\n");\r
-                    fileBuffer.append("EFIAPI\r\n");\r
-                    fileBuffer.append(libInstanceList.get(i)[0]);\r
-                    fileBuffer.append(" (\r\n");\r
-                    fileBuffer.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
-                    fileBuffer.append("  IN EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
-                    fileBuffer.append("  );\r\n");\r
+                    functionDeclarations.append("EFI_STATUS\r\n");\r
+                    functionDeclarations.append("EFIAPI\r\n");\r
+                    functionDeclarations.append(libInstanceList.get(i)[0]);\r
+                    functionDeclarations.append(" (\r\n");\r
+                    functionDeclarations.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
+                    functionDeclarations.append("  IN EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
+                    functionDeclarations.append("  );\r\n");\r
                     break;\r
                 }\r
             }\r
@@ -1794,6 +1937,73 @@ public class AutoGen {
         }\r
     }\r
 \r
+    /**\r
+      ExternCallBackToAutoGenC\r
+     \r
+      This function adds <SetVirtualAddressMapCallBack> and\r
+      <ExitBootServicesCallBack> infomation to AutoGen.c\r
+     \r
+      @param fileBuffer\r
+                 String buffer for AutoGen.c\r
+      @throws BuildException\r
+    **/\r
+    void ExternCallBackToAutoGenH(String moduleType)\r
+    throws EdkException {\r
+        //\r
+        // Collect module's <SetVirtualAddressMapCallBack> and\r
+        // <ExitBootServiceCallBack> and add to setVirtualAddList\r
+        //  exitBootServiceList.\r
+        //\r
+        String[] setVirtuals = saq.getSetVirtualAddressMapCallBackArray();\r
+        String[] exitBoots = saq.getExitBootServicesCallBackArray();\r
+        //\r
+        //  Add c code in autogen.c which relate to <SetVirtualAddressMapCallBack>\r
+        //  and <ExitBootServicesCallBack>\r
+        //\r
+        switch (CommonDefinition.getModuleType(moduleType)) {\r
+        case CommonDefinition.ModuleTypeDxeDriver:\r
+        case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
+        case CommonDefinition.ModuleTypeDxeSalDriver:\r
+        case CommonDefinition.ModuleTypeUefiDriver:\r
+        case CommonDefinition.ModuleTypeUefiApplication:\r
+            //\r
+            // Write SetVirtualAddressMap function definition.\r
+            //\r
+            for (int i = 0; setVirtuals != null && i < setVirtuals.length; i++) {\r
+                if (setVirtuals[i].equalsIgnoreCase("")) {\r
+                    continue;\r
+                }\r
+                functionDeclarations.append("VOID\r\n");\r
+                functionDeclarations.append("EFIAPI\r\n");\r
+                functionDeclarations.append(setVirtuals[i]);\r
+                functionDeclarations.append(" (\r\n");\r
+                functionDeclarations.append("  IN EFI_EVENT  Event,\r\n");\r
+                functionDeclarations.append("  IN VOID       *Context\r\n");\r
+                functionDeclarations.append("  );\r\n\r\n");\r
+            }\r
+\r
+            //\r
+            // Write DriverExitBootServices function definition.\r
+            //\r
+            for (int i = 0; exitBoots != null && i < exitBoots.length; i++) {\r
+                if (exitBoots[i].equalsIgnoreCase("")) {\r
+                    continue;\r
+                }\r
+\r
+                functionDeclarations.append("VOID\r\n");\r
+                functionDeclarations.append("EFIAPI\r\n");\r
+                functionDeclarations.append(exitBoots[i]);\r
+                functionDeclarations.append(" (\r\n");\r
+                functionDeclarations.append("  IN EFI_EVENT  Event,\r\n");\r
+                functionDeclarations.append("  IN VOID       *Context\r\n");\r
+                functionDeclarations.append("  );\r\n\r\n");\r
+            }\r
+            break;\r
+        default:\r
+            break;\r
+        }\r
+    }\r
+\r
     /**\r
       ExternCallBackToAutoGenC\r
      \r
@@ -2011,6 +2221,7 @@ public class AutoGen {
             }\r
         }\r
     }\r
+\r
     private void setVirtualAddressToAutogenC(StringBuffer fileBuffer){\r
         //\r
         // Entry point lib for these module types needs to know the count\r
@@ -2050,13 +2261,13 @@ public class AutoGen {
                 if (this.setVirtalAddList.get(i).equalsIgnoreCase("")) {\r
                     break;\r
                 }\r
-                fileBuffer.append("VOID\r\n");\r
-                fileBuffer.append("EFIAPI\r\n");\r
-                fileBuffer.append(this.setVirtalAddList.get(i));\r
-                fileBuffer.append(" (\r\n");\r
-                fileBuffer.append("  IN EFI_EVENT  Event,\r\n");\r
-                fileBuffer.append("  IN VOID       *Context\r\n");\r
-                fileBuffer.append("  );\r\n\r\n");\r
+                functionDeclarations.append("VOID\r\n");\r
+                functionDeclarations.append("EFIAPI\r\n");\r
+                functionDeclarations.append(this.setVirtalAddList.get(i));\r
+                functionDeclarations.append(" (\r\n");\r
+                functionDeclarations.append("  IN EFI_EVENT  Event,\r\n");\r
+                functionDeclarations.append("  IN VOID       *Context\r\n");\r
+                functionDeclarations.append("  );\r\n\r\n");\r
             }\r
 \r
             //\r
@@ -2089,8 +2300,7 @@ public class AutoGen {
         //\r
         // Entry point lib for these module types needs to know the count.\r
         //\r
-        fileBuffer\r
-        .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED  const UINTN _gDriverExitBootServicesEventCount = ");\r
+        fileBuffer.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED  const UINTN _gDriverExitBootServicesEventCount = ");\r
 \r
         //\r
         // If the list is not valid or has no entries set count to zero else\r
@@ -2125,13 +2335,13 @@ public class AutoGen {
                     break;\r
                 }\r
 \r
-                fileBuffer.append("VOID\r\n");\r
-                fileBuffer.append("EFIAPI\r\n");\r
-                fileBuffer.append(this.exitBootServiceList.get(i));\r
-                fileBuffer.append(" (\r\n");\r
-                fileBuffer.append("  IN EFI_EVENT  Event,\r\n");\r
-                fileBuffer.append("  IN VOID       *Context\r\n");\r
-                fileBuffer.append("  );\r\n\r\n");\r
+                functionDeclarations.append("VOID\r\n");\r
+                functionDeclarations.append("EFIAPI\r\n");\r
+                functionDeclarations.append(this.exitBootServiceList.get(i));\r
+                functionDeclarations.append(" (\r\n");\r
+                functionDeclarations.append("  IN EFI_EVENT  Event,\r\n");\r
+                functionDeclarations.append("  IN VOID       *Context\r\n");\r
+                functionDeclarations.append("  );\r\n\r\n");\r
             }\r
 \r
             //\r