Fix the bug that using hardcode driver name to judge whether current driver is PCD...
authorklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 15 Aug 2006 17:11:06 +0000 (17:11 +0000)
committerklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 15 Aug 2006 17:11:06 +0000 (17:11 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1281 6f19259b-4bc3-4df7-8a09-765794883524

EdkModulePkg/Universal/PCD/Dxe/Pcd.msa
EdkModulePkg/Universal/PCD/Pei/Pcd.msa
Tools/Source/GenBuild/org/tianocore/build/autogen/AutoGen.java
Tools/Source/GenBuild/org/tianocore/build/autogen/CommonDefinition.java
Tools/Source/GenBuild/org/tianocore/build/global/SurfaceAreaQuery.java
Tools/Source/GenBuild/org/tianocore/build/pcd/action/PCDAutoGenAction.java

index 071c184..b2a9d42 100644 (file)
@@ -88,6 +88,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.-->
     </GuidCNames>\r
   </Guids>\r
   <Externs>\r
+    <PcdIsDriver>DXE_PCD_DRIVER</PcdIsDriver>\r
     <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
     <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
     <Extern>\r
index 594aeb3..9510738 100644 (file)
@@ -85,6 +85,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.-->
     </GuidCNames>\r
   </Guids>\r
   <Externs>\r
+    <PcdIsDriver>PEI_PCD_DRIVER</PcdIsDriver>\r
     <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
     <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
     <Extern>\r
index c3d371e..ad4a5c7 100644 (file)
@@ -52,47 +52,54 @@ import org.tianocore.common.logger.EdkLog;
  * area or library surface area.\r
  */\r
 public class AutoGen {\r
-       // /\r
-       // / The output path of Autogen.h and Autogen.c\r
-       // /\r
-       private String outputPath;\r
+    ///\r
+    /// The output path of Autogen.h and Autogen.c\r
+    ///\r
+    private String outputPath;\r
+\r
     ///\r
     /// The name of FV directory\r
     ///\r
     private String fvDir;\r
-       // /\r
-       // / The base name of module or library.\r
-       // /\r
-       private ModuleIdentification moduleId;\r
-\r
-       // /\r
-       // / The build architecture\r
-       // /\r
-       private String arch;\r
-\r
-       // /\r
-       // / PcdAutogen instance which is used to manage how to generate the PCD\r
-       // / information.\r
-       // /\r
-       private PCDAutoGenAction myPcdAutogen;\r
-\r
-       // /\r
-       // / The protocl list which records in module or library surface area and\r
-       // / it's dependence on library instance surface area.\r
-       // /\r
-       private Set<String> mProtocolList = new HashSet<String>();\r
-\r
-       // /\r
-       // / The Ppi list which recorded in module or library surface area and its\r
-       // / dependency on library instance surface area.\r
-       // /\r
-       private Set<String> mPpiList = new HashSet<String>();\r
-\r
-       // /\r
-       // / The Guid list which recoreded in module or library surface area and it's\r
-       // / dependence on library instance surface area.\r
-       // /\r
-       private Set<String> mGuidList = new HashSet<String>();\r
+\r
+    ///\r
+    /// The base name of module or library.\r
+    ///\r
+    private ModuleIdentification moduleId;\r
+\r
+    ///\r
+    /// The build architecture\r
+    ///\r
+    private String arch;\r
+\r
+    ///\r
+    /// PcdAutogen instance which is used to manage how to generate the PCD\r
+    /// information.\r
+    ///\r
+    private PCDAutoGenAction myPcdAutogen;\r
+\r
+    ///\r
+    /// the one of type : NOT_PCD_DRIVER, PEI_PCD_DRIVER, DXE_PCD_DRIVER\r
+    /// \r
+    private CommonDefinition.PCD_DRIVER_TYPE pcdDriverType;\r
+\r
+    ///\r
+    /// The protocl list which records in module or library surface area and\r
+    /// it's dependence on library instance surface area.\r
+    ///\r
+    private Set<String> mProtocolList = new HashSet<String>();\r
+\r
+    ///\r
+    /// The Ppi list which recorded in module or library surface area and its\r
+    /// dependency on library instance surface area.\r
+    ///\r
+    private Set<String> mPpiList = new HashSet<String>();\r
+\r
+    ///\r
+    /// The Guid list which recoreded in module or library surface area and it's\r
+    /// dependence on library instance surface area.\r
+    ///\r
+    private Set<String> mGuidList = new HashSet<String>();\r
 \r
     //\r
     // The dependence package list which recoreded in module or library surface\r
@@ -100,198 +107,198 @@ public class AutoGen {
     //\r
     private List<PackageIdentification> mDepPkgList = new LinkedList<PackageIdentification>();\r
 \r
-       //\r
-       //  For non library module, add its library instance's construct and destructor to\r
-       //  list.\r
-       //\r
-       private List<String> libConstructList = new ArrayList<String>();\r
-       private List<String> libDestructList = new ArrayList<String>();\r
-\r
-       //\r
-       // List to store SetVirtalAddressMapCallBack, ExitBootServiceCallBack\r
-       //\r
-       private List<String> setVirtalAddList = new ArrayList<String>();\r
-       private List<String> exitBootServiceList = new ArrayList<String>();\r
-\r
-\r
-       /**\r
-        * Construct function\r
-        *\r
-        * This function mainly initialize some member variable.\r
-        *\r
-        * @param outputPath\r
-        *            Output path of AutoGen file.\r
-        * @param baseName\r
-        *            Module base name.\r
-        * @param arch\r
-        *            Target architecture.\r
-        */\r
-       public AutoGen(String fvDir, String outputPath, ModuleIdentification moduleId, String arch) {\r
-               this.outputPath = outputPath;\r
-               this.moduleId = moduleId;\r
-               this.arch = arch;\r
+    //\r
+    //  For non library module, add its library instance's construct and destructor to\r
+    //  list.\r
+    //\r
+    private List<String> libConstructList = new ArrayList<String>();\r
+    private List<String> libDestructList = new ArrayList<String>();\r
+\r
+    //\r
+    // List to store SetVirtalAddressMapCallBack, ExitBootServiceCallBack\r
+    //\r
+    private List<String> setVirtalAddList = new ArrayList<String>();\r
+    private List<String> exitBootServiceList = new ArrayList<String>();\r
+\r
+\r
+    /**\r
+     * Construct function\r
+     *\r
+     * This function mainly initialize some member variable.\r
+     *\r
+     * @param outputPath\r
+     *            Output path of AutoGen file.\r
+     * @param baseName\r
+     *            Module base name.\r
+     * @param arch\r
+     *            Target architecture.\r
+     */\r
+    public AutoGen(String fvDir, String outputPath, ModuleIdentification moduleId, String arch) {\r
+        this.outputPath = outputPath;\r
+        this.moduleId = moduleId;\r
+        this.arch = arch;\r
         this.fvDir = fvDir;\r
 \r
-       }\r
-\r
-       /**\r
-        * saveFile function\r
-        *\r
-        * This function save the content in stringBuffer to file.\r
-        *\r
-        * @param fileName\r
-        *            The name of file.\r
-        * @param fileBuffer\r
-        *            The content of AutoGen file in buffer.\r
-        * @return "true" successful, "false" failed.\r
-        */\r
-       private boolean saveFile(String fileName, StringBuffer fileBuffer) {\r
-               try {\r
-                       File autoGenH = new File(fileName);\r
-\r
-                       //\r
-                       // if the file exists, compare their content\r
-                       //\r
-                       if (autoGenH.exists()) {\r
-                               FileReader fIn = new FileReader(autoGenH);\r
-                               char[] oldFileBuffer = new char[(int) autoGenH.length()];\r
-                               fIn.read(oldFileBuffer, 0, (int) autoGenH.length());\r
-                               fIn.close();\r
-\r
-                               //\r
-                               // if we got the same file, don't re-generate it to prevent\r
-                               // sources depending on it from re-building\r
-                               //\r
-                               if (fileBuffer.toString().compareTo(new String(oldFileBuffer)) == 0) {\r
-                                       return true;\r
-                               }\r
-                       }\r
-                       FileWriter fOut = new FileWriter(autoGenH);\r
-                       fOut.write(fileBuffer.toString());\r
-                       fOut.close();\r
-               } catch (Exception e) {\r
-                       return false;\r
-               }\r
-               return true;\r
-       }\r
-\r
-       /**\r
-        * genAutogen function\r
-        *\r
-        * This function call libGenAutoGen or moduleGenAutogen function, which\r
-        * dependence on generate library autogen or module autogen.\r
-        *\r
-        * @throws BuildException\r
-        *             Failed to creat AutoGen.c & AutoGen.h.\r
-        */\r
-       public void genAutogen() throws BuildException {\r
-               try {\r
-                       //\r
-                       // If outputPath do not exist, create it.\r
-                       //\r
-                       File path = new File(outputPath);\r
-                       path.mkdirs();\r
-\r
-                       //\r
-                       // Check current is library or not, then call the corresponding\r
-                       // function.\r
-                       //\r
-                       if (this.moduleId.isLibrary()) {\r
-                               libGenAutogen();\r
-                       } else {\r
-                               moduleGenAutogen();\r
-                       }\r
-\r
-               } catch (Exception e) {\r
-                       throw new BuildException(\r
-                                       "Failed to create AutoGen.c & AutoGen.h!\n"\r
-                                                       + e.getMessage());\r
-               }\r
-       }\r
-\r
-       /**\r
-        * moduleGenAutogen function\r
-        *\r
-        * This function generates AutoGen.c & AutoGen.h for module.\r
-        *\r
-        * @throws BuildException\r
-        *             Faile to create module AutoGen.c & AutoGen.h.\r
-        */\r
-       void moduleGenAutogen() throws BuildException {\r
-\r
-               try {\r
-                       collectLibInstanceInfo();\r
-                       moduleGenAutogenC();\r
-                       moduleGenAutogenH();\r
-               } catch (Exception e) {\r
-                       throw new BuildException(\r
-                                       "Faile to create module AutoGen.c & AutoGen.h!\n"\r
-                                                       + e.getMessage());\r
-               }\r
-       }\r
-\r
-       /**\r
-        * libGenAutogen function\r
-        *\r
-        * This function generates AutoGen.c & AutoGen.h for library.\r
-        *\r
-        * @throws BuildException\r
-        *             Faile to create library AutoGen.c & AutoGen.h\r
-        */\r
-       void libGenAutogen() throws BuildException {\r
-               try {\r
-                       libGenAutogenC();\r
-                       libGenAutogenH();\r
-               } catch (Exception e) {\r
-                       throw new BuildException(\r
-                                       "Failed to create library AutoGen.c & AutoGen.h!\n"\r
-                                                       + e.getMessage());\r
-               }\r
-       }\r
-\r
-       /**\r
-        * moduleGenAutogenH\r
-        *\r
-        * This function generates AutoGen.h for module.\r
-        *\r
-        * @throws BuildException\r
-        *             Failed to generate AutoGen.h.\r
-        */\r
-       void moduleGenAutogenH() throws AutoGenException {\r
-\r
-               Set<String> libClassIncludeH;\r
-               String moduleType;\r
-               // List<String> headerFileList;\r
-               List<String> headerFileList;\r
-               Iterator item;\r
-               StringBuffer fileBuffer = new StringBuffer(8192);\r
-\r
-               //\r
-               // Write Autogen.h header notation\r
-               //\r
-               fileBuffer.append(CommonDefinition.autogenHNotation);\r
-\r
-               //\r
-               // Add #ifndef ${BaseName}_AUTOGENH\r
-               // #def ${BseeName}_AUTOGENH\r
-               //\r
-               fileBuffer.append("#ifndef    " + "_AUTOGENH_" + this.moduleId.getGuid().replaceAll("-", "_") +"\r\n");\r
-               fileBuffer.append("#define    " + "_AUTOGENH_" + this.moduleId.getGuid().replaceAll("-", "_") +"\r\n\r\n");\r
-\r
-               //\r
-               // Write the specification version and release version at the begine\r
-               // of autogen.h file.\r
-               // Note: the specification version and release version should\r
-               // be got from module surface area instead of hard code by it's\r
-               // moduleType.\r
-               //\r
-               moduleType = SurfaceAreaQuery.getModuleType();\r
-\r
-               //\r
-               // Add "extern int __make_me_compile_correctly;" at begin of\r
-               // AutoGen.h.\r
-               //\r
-               fileBuffer.append(CommonDefinition.autoGenHbegin);\r
+    }\r
+\r
+    /**\r
+     * saveFile function\r
+     *\r
+     * This function save the content in stringBuffer to file.\r
+     *\r
+     * @param fileName\r
+     *            The name of file.\r
+     * @param fileBuffer\r
+     *            The content of AutoGen file in buffer.\r
+     * @return "true" successful, "false" failed.\r
+     */\r
+    private boolean saveFile(String fileName, StringBuffer fileBuffer) {\r
+        try {\r
+            File autoGenH = new File(fileName);\r
+\r
+            //\r
+            // if the file exists, compare their content\r
+            //\r
+            if (autoGenH.exists()) {\r
+                FileReader fIn = new FileReader(autoGenH);\r
+                char[] oldFileBuffer = new char[(int) autoGenH.length()];\r
+                fIn.read(oldFileBuffer, 0, (int) autoGenH.length());\r
+                fIn.close();\r
+\r
+                //\r
+                // if we got the same file, don't re-generate it to prevent\r
+                // sources depending on it from re-building\r
+                //\r
+                if (fileBuffer.toString().compareTo(new String(oldFileBuffer)) == 0) {\r
+                    return true;\r
+                }\r
+            }\r
+            FileWriter fOut = new FileWriter(autoGenH);\r
+            fOut.write(fileBuffer.toString());\r
+            fOut.close();\r
+        } catch (Exception e) {\r
+            return false;\r
+        }\r
+        return true;\r
+    }\r
+\r
+    /**\r
+     * genAutogen function\r
+     *\r
+     * This function call libGenAutoGen or moduleGenAutogen function, which\r
+     * dependence on generate library autogen or module autogen.\r
+     *\r
+     * @throws BuildException\r
+     *             Failed to creat AutoGen.c & AutoGen.h.\r
+     */\r
+    public void genAutogen() throws BuildException {\r
+        try {\r
+            //\r
+            // If outputPath do not exist, create it.\r
+            //\r
+            File path = new File(outputPath);\r
+            path.mkdirs();\r
+\r
+            //\r
+            // Check current is library or not, then call the corresponding\r
+            // function.\r
+            //\r
+            if (this.moduleId.isLibrary()) {\r
+                libGenAutogen();\r
+            } else {\r
+                moduleGenAutogen();\r
+            }\r
+\r
+        } catch (Exception e) {\r
+            throw new BuildException(\r
+                                    "Failed to create AutoGen.c & AutoGen.h!\n"\r
+                                    + e.getMessage());\r
+        }\r
+    }\r
+\r
+    /**\r
+     * moduleGenAutogen function\r
+     *\r
+     * This function generates AutoGen.c & AutoGen.h for module.\r
+     *\r
+     * @throws BuildException\r
+     *             Faile to create module AutoGen.c & AutoGen.h.\r
+     */\r
+    void moduleGenAutogen() throws BuildException {\r
+\r
+        try {\r
+            collectLibInstanceInfo();\r
+            moduleGenAutogenC();\r
+            moduleGenAutogenH();\r
+        } catch (Exception e) {\r
+            throw new BuildException(\r
+                                    "Faile to create module AutoGen.c & AutoGen.h!\n"\r
+                                    + e.getMessage());\r
+        }\r
+    }\r
+\r
+    /**\r
+     * libGenAutogen function\r
+     *\r
+     * This function generates AutoGen.c & AutoGen.h for library.\r
+     *\r
+     * @throws BuildException\r
+     *             Faile to create library AutoGen.c & AutoGen.h\r
+     */\r
+    void libGenAutogen() throws BuildException {\r
+        try {\r
+            libGenAutogenC();\r
+            libGenAutogenH();\r
+        } catch (Exception e) {\r
+            throw new BuildException(\r
+                                    "Failed to create library AutoGen.c & AutoGen.h!\n"\r
+                                    + e.getMessage());\r
+        }\r
+    }\r
+\r
+    /**\r
+     * moduleGenAutogenH\r
+     *\r
+     * This function generates AutoGen.h for module.\r
+     *\r
+     * @throws BuildException\r
+     *             Failed to generate AutoGen.h.\r
+     */\r
+    void moduleGenAutogenH() throws AutoGenException {\r
+\r
+        Set<String> libClassIncludeH;\r
+        String moduleType;\r
+        // List<String> headerFileList;\r
+        List<String> headerFileList;\r
+        Iterator item;\r
+        StringBuffer fileBuffer = new StringBuffer(8192);\r
+\r
+        //\r
+        // Write Autogen.h header notation\r
+        //\r
+        fileBuffer.append(CommonDefinition.autogenHNotation);\r
+\r
+        //\r
+        // Add #ifndef ${BaseName}_AUTOGENH\r
+        // #def ${BseeName}_AUTOGENH\r
+        //\r
+        fileBuffer.append("#ifndef    " + "_AUTOGENH_" + this.moduleId.getGuid().replaceAll("-", "_") +"\r\n");\r
+        fileBuffer.append("#define    " + "_AUTOGENH_" + this.moduleId.getGuid().replaceAll("-", "_") +"\r\n\r\n");\r
+\r
+        //\r
+        // Write the specification version and release version at the begine\r
+        // of autogen.h file.\r
+        // Note: the specification version and release version should\r
+        // be got from module surface area instead of hard code by it's\r
+        // moduleType.\r
+        //\r
+        moduleType = SurfaceAreaQuery.getModuleType();\r
+\r
+        //\r
+        // Add "extern int __make_me_compile_correctly;" at begin of\r
+        // AutoGen.h.\r
+        //\r
+        fileBuffer.append(CommonDefinition.autoGenHbegin);\r
 \r
         //\r
         // Put EFI_SPECIFICATION_VERSION, and EDK_RELEASE_VERSION.\r
@@ -299,46 +306,46 @@ public class AutoGen {
         String[] specList = SurfaceAreaQuery.getExternSpecificaiton();\r
         for (int i = 0; i < specList.length; i++) {\r
             fileBuffer.append(CommonDefinition.marcDefineStr + specList[i]\r
-                    + "\r\n");\r
+                              + "\r\n");\r
+        }\r
+        //\r
+        // Write consumed package's mdouleInfo related .h file to autogen.h\r
+        //\r
+        // PackageIdentification[] consumedPkgIdList = SurfaceAreaQuery\r
+        // .getDependencePkg(this.arch);\r
+        PackageIdentification[] consumedPkgIdList = SurfaceAreaQuery\r
+                                                    .getDependencePkg(this.arch);\r
+        if (consumedPkgIdList != null) {\r
+            headerFileList = depPkgToAutogenH(consumedPkgIdList, moduleType);\r
+            item = headerFileList.iterator();\r
+            while (item.hasNext()) {\r
+                fileBuffer.append(item.next().toString());\r
+            }\r
+        }\r
+\r
+        //\r
+        // Write library class's related *.h file to autogen.h.\r
+        //\r
+        String[] libClassList = SurfaceAreaQuery\r
+                                .getLibraryClasses(CommonDefinition.AlwaysConsumed,this.arch);\r
+        if (libClassList != null) {\r
+            libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
+            item = libClassIncludeH.iterator();\r
+            while (item.hasNext()) {\r
+                fileBuffer.append(item.next().toString());\r
+            }\r
         }\r
-               //\r
-               // Write consumed package's mdouleInfo related .h file to autogen.h\r
-               //\r
-               // PackageIdentification[] consumedPkgIdList = SurfaceAreaQuery\r
-               // .getDependencePkg(this.arch);\r
-               PackageIdentification[] consumedPkgIdList = SurfaceAreaQuery\r
-                               .getDependencePkg(this.arch);\r
-               if (consumedPkgIdList != null) {\r
-                       headerFileList = depPkgToAutogenH(consumedPkgIdList, moduleType);\r
-                       item = headerFileList.iterator();\r
-                       while (item.hasNext()) {\r
-                               fileBuffer.append(item.next().toString());\r
-                       }\r
-               }\r
-\r
-               //\r
-               // Write library class's related *.h file to autogen.h.\r
-               //\r
-               String[] libClassList = SurfaceAreaQuery\r
-                               .getLibraryClasses(CommonDefinition.AlwaysConsumed,this.arch);\r
-               if (libClassList != null) {\r
-                       libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
-                       item = libClassIncludeH.iterator();\r
-                       while (item.hasNext()) {\r
-                               fileBuffer.append(item.next().toString());\r
-                       }\r
-               }\r
-\r
-               libClassList = SurfaceAreaQuery\r
-                               .getLibraryClasses(CommonDefinition.AlwaysProduced, this.arch);\r
-               if (libClassList != null) {\r
-                       libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
-                       item = libClassIncludeH.iterator();\r
-                       while (item.hasNext()) {\r
-                               fileBuffer.append(item.next().toString());\r
-                       }\r
-               }\r
-               fileBuffer.append("\r\n");\r
+\r
+        libClassList = SurfaceAreaQuery\r
+                       .getLibraryClasses(CommonDefinition.AlwaysProduced, this.arch);\r
+        if (libClassList != null) {\r
+            libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
+            item = libClassIncludeH.iterator();\r
+            while (item.hasNext()) {\r
+                fileBuffer.append(item.next().toString());\r
+            }\r
+        }\r
+        fileBuffer.append("\r\n");\r
 \r
         //\r
         //  If is TianoR8FlashMap, copy {Fv_DIR}/FlashMap.h to\r
@@ -351,225 +358,230 @@ public class AutoGen {
             copyFlashMapHToDebugDir();\r
         }\r
 \r
-               // Write PCD autogen information to AutoGen.h.\r
-               //\r
-               if (this.myPcdAutogen != null) {\r
+        // Write PCD autogen information to AutoGen.h.\r
+        //\r
+        if (this.myPcdAutogen != null) {\r
             fileBuffer.append("\r\n");\r
-                       fileBuffer.append(this.myPcdAutogen.OutputH());\r
-               }\r
-\r
-               //\r
-               // Append the #endif at AutoGen.h\r
-               //\r
-               fileBuffer.append("#endif\r\n");\r
-\r
-               //\r
-               // Save string buffer content in AutoGen.h.\r
-               //\r
-               if (!saveFile(outputPath + File.separatorChar + "AutoGen.h", fileBuffer)) {\r
-                       throw new BuildException("Failed to generate AutoGen.h !!!");\r
-               }\r
-       }\r
-\r
-       /**\r
-        * moduleGenAutogenC\r
-        *\r
-        * This function generates AutoGen.c for module.\r
-        *\r
-        * @throws BuildException\r
-        *             Failed to generate AutoGen.c.\r
-        */\r
-       void moduleGenAutogenC() throws AutoGenException {\r
-\r
-               StringBuffer fileBuffer = new StringBuffer(8192);\r
-               //\r
-               // Write Autogen.c header notation\r
-               //\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
-               // process <Externs> it should be set the DOC as the Native MSA info.\r
-               //\r
-               Map<String, XmlObject> doc = GlobalData.getNativeMsa(this.moduleId);\r
-               SurfaceAreaQuery.push(doc);\r
-               //\r
-               // Write <Extern>\r
-               // DriverBinding/ComponentName/DriverConfiguration/DriverDialog\r
-               // to AutoGen.c\r
-               //\r
-\r
-               ExternsDriverBindingToAutoGenC(fileBuffer);\r
-\r
-               //\r
-               // Write DriverExitBootServicesEvent/DriverSetVirtualAddressMapEvent\r
-               // to Autogen.c\r
-               //\r
-               ExternCallBackToAutoGenC(fileBuffer);\r
-\r
-               //\r
-               // Write EntryPoint to autgoGen.c\r
-               //\r
-               String[] entryPointList = SurfaceAreaQuery.getModuleEntryPointArray();\r
-               EntryPointToAutoGen(CommonDefinition.remDupString(entryPointList), fileBuffer);\r
-\r
-\r
-               //\r
-               // Restore the DOC which include the FPD module info.\r
-               //\r
-               SurfaceAreaQuery.pop();\r
-\r
-               //\r
-               // Write Guid to autogen.c\r
-               //\r
-               String guid = CommonDefinition.formatGuidName(SurfaceAreaQuery\r
-                               .getModuleGuid());\r
-\r
-               fileBuffer\r
-                               .append("GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiCallerIdGuid = {");\r
-               if (guid == null) {\r
-                       throw new AutoGenException("Guid value must set!\n");\r
-               }\r
-\r
-               //\r
-               // Formate Guid as ANSI c form.Example:\r
-               // {0xd2b2b828, 0x826, 0x48a7,{0xb3, 0xdf, 0x98, 0x3c, 0x0, 0x60, 0x24,\r
-               // 0xf0}}\r
-               //\r
-\r
-               fileBuffer.append(guid);\r
-               fileBuffer.append("};\r\n");\r
-\r
-               //\r
-               // Generate library instance consumed protocol, guid, ppi, pcd list.\r
-               // Save those to this.protocolList, this.ppiList, this.pcdList,\r
-               // this.guidList. Write Consumed library constructor and desconstuct to\r
-               // autogen.c\r
-               //\r
+            fileBuffer.append(this.myPcdAutogen.OutputH());\r
+        }\r
+\r
+        //\r
+        // Append the #endif at AutoGen.h\r
+        //\r
+        fileBuffer.append("#endif\r\n");\r
+\r
+        //\r
+        // Save string buffer content in AutoGen.h.\r
+        //\r
+        if (!saveFile(outputPath + File.separatorChar + "AutoGen.h", fileBuffer)) {\r
+            throw new BuildException("Failed to generate AutoGen.h !!!");\r
+        }\r
+    }\r
+\r
+    /**\r
+     * moduleGenAutogenC\r
+     *\r
+     * This function generates AutoGen.c for module.\r
+     *\r
+     * @throws BuildException\r
+     *             Failed to generate AutoGen.c.\r
+     */\r
+    void moduleGenAutogenC() throws AutoGenException {\r
+\r
+        StringBuffer fileBuffer = new StringBuffer(8192);\r
+        //\r
+        // Write Autogen.c header notation\r
+        //\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
+        // process <Externs> it should be set the DOC as the Native MSA info.\r
+        //\r
+        Map<String, XmlObject> doc = GlobalData.getNativeMsa(this.moduleId);\r
+        SurfaceAreaQuery.push(doc);\r
+        //\r
+        // Write <Extern>\r
+        // DriverBinding/ComponentName/DriverConfiguration/DriverDialog\r
+        // to AutoGen.c\r
+        //\r
+\r
+        ExternsDriverBindingToAutoGenC(fileBuffer);\r
+\r
+        //\r
+        // Write DriverExitBootServicesEvent/DriverSetVirtualAddressMapEvent\r
+        // to Autogen.c\r
+        //\r
+        ExternCallBackToAutoGenC(fileBuffer);\r
+\r
+        //\r
+        // Write EntryPoint to autgoGen.c\r
+        //\r
+        String[] entryPointList = SurfaceAreaQuery.getModuleEntryPointArray();\r
+        EntryPointToAutoGen(CommonDefinition.remDupString(entryPointList), fileBuffer);\r
+\r
+        pcdDriverType = SurfaceAreaQuery.getPcdDriverType();\r
+\r
+        //\r
+        // Restore the DOC which include the FPD module info.\r
+        //\r
+        SurfaceAreaQuery.pop();\r
+\r
+        //\r
+        // Write Guid to autogen.c\r
+        //\r
+        String guid = CommonDefinition.formatGuidName(SurfaceAreaQuery\r
+                                                      .getModuleGuid());\r
+\r
+        fileBuffer\r
+        .append("GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiCallerIdGuid = {");\r
+        if (guid == null) {\r
+            throw new AutoGenException("Guid value must set!\n");\r
+        }\r
+\r
+        //\r
+        // Formate Guid as ANSI c form.Example:\r
+        // {0xd2b2b828, 0x826, 0x48a7,{0xb3, 0xdf, 0x98, 0x3c, 0x0, 0x60, 0x24,\r
+        // 0xf0}}\r
+        //\r
+\r
+        fileBuffer.append(guid);\r
+        fileBuffer.append("};\r\n");\r
+\r
+        //\r
+        // Generate library instance consumed protocol, guid, ppi, pcd list.\r
+        // Save those to this.protocolList, this.ppiList, this.pcdList,\r
+        // this.guidList. Write Consumed library constructor and desconstuct to\r
+        // autogen.c\r
+        //\r
         LibInstanceToAutogenC(fileBuffer);\r
 \r
         //\r
         // Get module dependent Package identification.\r
         //\r
         PackageIdentification[] packages = SurfaceAreaQuery.getDependencePkg(this.arch);\r
-        for (int i = 0; i < packages.length; i++){\r
-            if (!this.mDepPkgList.contains(packages[i])){\r
+        for (int i = 0; i < packages.length; i++) {\r
+            if (!this.mDepPkgList.contains(packages[i])) {\r
                 this.mDepPkgList.add(packages[i]);\r
             }\r
 \r
         }\r
 \r
-               //\r
-               // Write consumed ppi, guid, protocol to autogen.c\r
-               //\r
-               ProtocolGuidToAutogenC(fileBuffer);\r
-               PpiGuidToAutogenC(fileBuffer);\r
-               GuidGuidToAutogenC(fileBuffer);\r
-\r
-               //\r
-               // Call pcd autogen.\r
-               //\r
-                this.myPcdAutogen = new PCDAutoGenAction(moduleId, this.arch, false, null);\r
-                try {\r
-                    this.myPcdAutogen.execute();\r
-                } catch (Exception exp) {\r
-                    throw new PcdAutogenException (exp.getMessage());\r
-                }\r
+        //\r
+        // Write consumed ppi, guid, protocol to autogen.c\r
+        //\r
+        ProtocolGuidToAutogenC(fileBuffer);\r
+        PpiGuidToAutogenC(fileBuffer);\r
+        GuidGuidToAutogenC(fileBuffer);\r
 \r
-               if (this.myPcdAutogen != null) {\r
-                    fileBuffer.append("\r\n");\r
-                    fileBuffer.append(this.myPcdAutogen.OutputC());\r
-               }\r
-\r
-               if (!saveFile(outputPath + File.separatorChar + "AutoGen.c", fileBuffer)) {\r
-                       throw new BuildException("Failed to generate AutoGen.c !!!");\r
-               }\r
-\r
-       }\r
-\r
-       /**\r
-        * libGenAutogenH\r
-        *\r
-        * This function generates AutoGen.h for library.\r
-        *\r
-        * @throws BuildException\r
-        *             Failed to generate AutoGen.c.\r
-        */\r
-       void libGenAutogenH() throws AutoGenException {\r
-\r
-               Set<String> libClassIncludeH;\r
-               String moduleType;\r
-               List<String> headerFileList;\r
-               Iterator item;\r
-               StringBuffer fileBuffer = new StringBuffer(10240);\r
-\r
-               //\r
-               // Write Autogen.h header notation\r
-               //\r
-               fileBuffer.append(CommonDefinition.autogenHNotation);\r
-\r
-               //\r
-               // Add #ifndef ${BaseName}_AUTOGENH\r
-               // #def ${BseeName}_AUTOGENH\r
-               //\r
-               fileBuffer.append("#ifndef    " + "_AUTOGENH_" + this.moduleId.getGuid().replaceAll("-", "_") + "\r\n");\r
-               fileBuffer.append("#define    " + "_AUTOGENH_" + this.moduleId.getGuid().replaceAll("-", "_") + "\r\n\r\n");\r
-\r
-               //\r
-               // Write EFI_SPECIFICATION_VERSION and EDK_RELEASE_VERSION\r
-               // to autogen.h file.\r
-               // Note: the specification version and release version should\r
-               // be get from module surface area instead of hard code.\r
-               //\r
-               fileBuffer.append(CommonDefinition.autoGenHbegin);\r
-               String[] specList = SurfaceAreaQuery.getExternSpecificaiton();\r
-               for (int i = 0; i < specList.length; i++) {\r
-                       fileBuffer.append(CommonDefinition.marcDefineStr + specList[i]\r
-                                       + "\r\n");\r
-               }\r
-               // fileBuffer.append(CommonDefinition.autoGenHLine1);\r
-               // fileBuffer.append(CommonDefinition.autoGenHLine2);\r
-\r
-               //\r
-               // Write consumed package's mdouleInfo related *.h file to autogen.h.\r
-               //\r
-               moduleType = SurfaceAreaQuery.getModuleType();\r
-               PackageIdentification[] cosumedPkglist = SurfaceAreaQuery\r
-                               .getDependencePkg(this.arch);\r
-               headerFileList = depPkgToAutogenH(cosumedPkglist, moduleType);\r
-               item = headerFileList.iterator();\r
-               while (item.hasNext()) {\r
-                       fileBuffer.append(item.next().toString());\r
-               }\r
-               //\r
-               // Write library class's related *.h file to autogen.h\r
-               //\r
-               String[] libClassList = SurfaceAreaQuery\r
-                               .getLibraryClasses(CommonDefinition.AlwaysConsumed, this.arch);\r
-               if (libClassList != null) {\r
-                       libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
-                       item = libClassIncludeH.iterator();\r
-                       while (item.hasNext()) {\r
-                               fileBuffer.append(item.next().toString());\r
-                       }\r
-               }\r
-\r
-               libClassList = SurfaceAreaQuery\r
-                               .getLibraryClasses(CommonDefinition.AlwaysProduced, this.arch);\r
-               if (libClassList != null) {\r
-                       libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
-                       item = libClassIncludeH.iterator();\r
-                       while (item.hasNext()) {\r
-                               fileBuffer.append(item.next().toString());\r
-                       }\r
-               }\r
-               fileBuffer.append("\r\n");\r
+        //\r
+        // Call pcd autogen.\r
+        //\r
+        this.myPcdAutogen = new PCDAutoGenAction(moduleId, \r
+                                                 arch, \r
+                                                 false, \r
+                                                 null,\r
+                                                 pcdDriverType);\r
+        try {\r
+            this.myPcdAutogen.execute();\r
+        } catch (Exception exp) {\r
+            throw new PcdAutogenException (exp.getMessage());\r
+        }\r
+\r
+        if (this.myPcdAutogen != null) {\r
+            fileBuffer.append("\r\n");\r
+            fileBuffer.append(this.myPcdAutogen.OutputC());\r
+        }\r
+\r
+        if (!saveFile(outputPath + File.separatorChar + "AutoGen.c", fileBuffer)) {\r
+            throw new BuildException("Failed to generate AutoGen.c !!!");\r
+        }\r
+\r
+    }\r
+\r
+    /**\r
+     * libGenAutogenH\r
+     *\r
+     * This function generates AutoGen.h for library.\r
+     *\r
+     * @throws BuildException\r
+     *             Failed to generate AutoGen.c.\r
+     */\r
+    void libGenAutogenH() throws AutoGenException {\r
+\r
+        Set<String> libClassIncludeH;\r
+        String moduleType;\r
+        List<String> headerFileList;\r
+        Iterator item;\r
+        StringBuffer fileBuffer = new StringBuffer(10240);\r
+\r
+        //\r
+        // Write Autogen.h header notation\r
+        //\r
+        fileBuffer.append(CommonDefinition.autogenHNotation);\r
+\r
+        //\r
+        // Add #ifndef ${BaseName}_AUTOGENH\r
+        // #def ${BseeName}_AUTOGENH\r
+        //\r
+        fileBuffer.append("#ifndef    " + "_AUTOGENH_" + this.moduleId.getGuid().replaceAll("-", "_") + "\r\n");\r
+        fileBuffer.append("#define    " + "_AUTOGENH_" + this.moduleId.getGuid().replaceAll("-", "_") + "\r\n\r\n");\r
+\r
+        //\r
+        // Write EFI_SPECIFICATION_VERSION and EDK_RELEASE_VERSION\r
+        // to autogen.h file.\r
+        // Note: the specification version and release version should\r
+        // be get from module surface area instead of hard code.\r
+        //\r
+        fileBuffer.append(CommonDefinition.autoGenHbegin);\r
+        String[] specList = SurfaceAreaQuery.getExternSpecificaiton();\r
+        for (int i = 0; i < specList.length; i++) {\r
+            fileBuffer.append(CommonDefinition.marcDefineStr + specList[i]\r
+                              + "\r\n");\r
+        }\r
+        // fileBuffer.append(CommonDefinition.autoGenHLine1);\r
+        // fileBuffer.append(CommonDefinition.autoGenHLine2);\r
+\r
+        //\r
+        // Write consumed package's mdouleInfo related *.h file to autogen.h.\r
+        //\r
+        moduleType = SurfaceAreaQuery.getModuleType();\r
+        PackageIdentification[] cosumedPkglist = SurfaceAreaQuery\r
+                                                 .getDependencePkg(this.arch);\r
+        headerFileList = depPkgToAutogenH(cosumedPkglist, moduleType);\r
+        item = headerFileList.iterator();\r
+        while (item.hasNext()) {\r
+            fileBuffer.append(item.next().toString());\r
+        }\r
+        //\r
+        // Write library class's related *.h file to autogen.h\r
+        //\r
+        String[] libClassList = SurfaceAreaQuery\r
+                                .getLibraryClasses(CommonDefinition.AlwaysConsumed, this.arch);\r
+        if (libClassList != null) {\r
+            libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
+            item = libClassIncludeH.iterator();\r
+            while (item.hasNext()) {\r
+                fileBuffer.append(item.next().toString());\r
+            }\r
+        }\r
+\r
+        libClassList = SurfaceAreaQuery\r
+                       .getLibraryClasses(CommonDefinition.AlwaysProduced, this.arch);\r
+        if (libClassList != null) {\r
+            libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
+            item = libClassIncludeH.iterator();\r
+            while (item.hasNext()) {\r
+                fileBuffer.append(item.next().toString());\r
+            }\r
+        }\r
+        fileBuffer.append("\r\n");\r
 \r
         //\r
         //  If is TianoR8FlashMap, copy {Fv_DIR}/FlashMap.h to\r
@@ -582,350 +594,351 @@ public class AutoGen {
             copyFlashMapHToDebugDir();\r
         }\r
 \r
-               //\r
-               // Write PCD information to library AutoGen.h.\r
-               //\r
-               if (this.myPcdAutogen != null) {\r
+        //\r
+        // Write PCD information to library AutoGen.h.\r
+        //\r
+        if (this.myPcdAutogen != null) {\r
             fileBuffer.append("\r\n");\r
-                       fileBuffer.append(this.myPcdAutogen.OutputH());\r
-               }\r
-\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
-               if (!saveFile(outputPath + File.separatorChar + "AutoGen.h", fileBuffer)) {\r
-                       throw new BuildException("Failed to generate AutoGen.h !!!");\r
-               }\r
-       }\r
-\r
-       /**\r
-        * libGenAutogenC\r
-        *\r
-        * This function generates AutoGen.h for library.\r
-        *\r
-        * @throws BuildException\r
-        *             Failed to generate AutoGen.c.\r
-        */\r
-       void libGenAutogenC() throws BuildException, PcdAutogenException {\r
-               StringBuffer fileBuffer = new StringBuffer(10240);\r
-\r
-               //\r
-               // Write Autogen.c header notation\r
-               //\r
-               fileBuffer.append(CommonDefinition.autogenCNotation);\r
-\r
-               fileBuffer.append(CommonDefinition.autoGenCLine1);\r
-               fileBuffer.append("\r\n");\r
-\r
-               //\r
-               // Call pcd autogen.\r
-               //\r
-                this.myPcdAutogen = new PCDAutoGenAction(this.moduleId,\r
-                                                         this.arch,\r
-                                                         true,\r
-                                                         SurfaceAreaQuery.getModulePcdEntryNameArray());\r
-               try {\r
-                    this.myPcdAutogen.execute();\r
-               } catch (Exception e) {\r
-                    throw new PcdAutogenException(e.getMessage());\r
-               }\r
-\r
-               if (this.myPcdAutogen != null) {\r
-                    fileBuffer.append("\r\n");\r
-                    fileBuffer.append(this.myPcdAutogen.OutputC());\r
-               }\r
-\r
-               if (!saveFile(outputPath + File.separatorChar + "AutoGen.c", fileBuffer)) {\r
-                       throw new BuildException("Failed to generate AutoGen.c !!!");\r
-               }\r
-       }\r
-\r
-       /**\r
-        * LibraryClassToAutogenH\r
-        *\r
-        * This function returns *.h files declared by library classes which are\r
-        * consumed or produced by current build module or library.\r
-        *\r
-        * @param libClassList\r
-        *            List of library class which consumed or produce by current\r
-        *            build module or library.\r
-        * @return includeStrList List of *.h file.\r
-        */\r
-       Set<String> LibraryClassToAutogenH(String[] libClassList)\r
-                       throws AutoGenException {\r
-               Set<String> includStrList = new LinkedHashSet<String>();\r
-               String includerName[];\r
-               String str = "";\r
-\r
-               //\r
-               // Get include file from GlobalData's SPDTable according to\r
-               // library class name.\r
-               //\r
-\r
-               for (int i = 0; i < libClassList.length; i++) {\r
-                       includerName = GlobalData.getLibraryClassHeaderFiles(\r
-                                       SurfaceAreaQuery.getDependencePkg(this.arch),\r
-                                       libClassList[i]);\r
-                       if (includerName == null) {\r
-                               throw new AutoGenException("Can not find library class ["\r
-                                               + libClassList[i] + "] declaration in any SPD package. ");\r
-                       }\r
-                       for (int j = 0; j < includerName.length; j++) {\r
-                               String includeNameStr = includerName[j];\r
-                               if (includeNameStr != null) {\r
-                                       str = CommonDefinition.include + " " + "<";\r
-                                       str = str + includeNameStr + ">\r\n";\r
-                                       includStrList.add(str);\r
-                                       includeNameStr = null;\r
-                               }\r
-                       }\r
-               }\r
-               return includStrList;\r
-       }\r
-\r
-       /**\r
-        * IncludesToAutogenH\r
-        *\r
-        * This function add include file in AutoGen.h file.\r
-        *\r
-        * @param packageNameList\r
-        *            List of module depended package.\r
-        * @param moduleType\r
-        *            Module type.\r
-        * @return\r
-        */\r
-       List<String> depPkgToAutogenH(PackageIdentification[] packageNameList,\r
-                       String moduleType) throws AutoGenException {\r
-\r
-               List<String> includeStrList = new LinkedList<String>();\r
-               String pkgHeader;\r
-               String includeStr = "";\r
-\r
-               //\r
-               // Get include file from moduleInfo file\r
-               //\r
-               for (int i = 0; i < packageNameList.length; i++) {\r
-                       pkgHeader = GlobalData.getPackageHeaderFiles(packageNameList[i],\r
-                                       moduleType);\r
-                       if (pkgHeader == null) {\r
-                               throw new AutoGenException("Can not find package ["\r
-                                               + packageNameList[i]\r
-                                               + "] declaration in any SPD package. ");\r
-                       } else if (!pkgHeader.equalsIgnoreCase("")) {\r
-                               includeStr = CommonDefinition.include + " <" + pkgHeader\r
-                                               + ">\r\n";\r
-                               includeStrList.add(includeStr);\r
-                       }\r
-               }\r
-\r
-               return includeStrList;\r
-       }\r
-\r
-       /**\r
-        * EntryPointToAutoGen\r
-        *\r
-        * This function convert <ModuleEntryPoint> & <ModuleUnloadImage>\r
-        * information in mas to AutoGen.c\r
-        *\r
-        * @param entryPointList\r
-        *            List of entry point.\r
-        * @param fileBuffer\r
-        *            String buffer fo AutoGen.c.\r
-        * @throws Exception\r
-        */\r
-       void EntryPointToAutoGen(String[] entryPointList, StringBuffer fileBuffer)\r
-                       throws BuildException {\r
-\r
-               String typeStr = SurfaceAreaQuery.getModuleType();\r
-\r
-               //\r
-               // The parameters and return value of entryPoint is difference\r
-               // for difference module type.\r
-               //\r
-               switch (CommonDefinition.getModuleType(typeStr)) {\r
-\r
-               case CommonDefinition.ModuleTypePeiCore:\r
-                       if (entryPointList == null ||entryPointList.length != 1 ) {\r
-                               throw new BuildException(\r
-                                               "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\r
-                                               .append("  IN EFI_PEI_STARTUP_DESCRIPTOR  *PeiStartupDescriptor,\r\n");\r
-                               fileBuffer\r
-                                               .append("  IN VOID                        *OldCoreData\r\n");\r
-                               fileBuffer.append("  );\r\n\r\n");\r
-\r
-                               fileBuffer.append("EFI_STATUS\r\n");\r
-                               fileBuffer.append("EFIAPI\r\n");\r
-                               fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r
-                               fileBuffer\r
-                                               .append("  IN EFI_PEI_STARTUP_DESCRIPTOR  *PeiStartupDescriptor,\r\n");\r
-                               fileBuffer\r
-                                               .append("  IN VOID                        *OldCoreData\r\n");\r
-                               fileBuffer.append("  )\r\n\r\n");\r
-                               fileBuffer.append("{\r\n");\r
-                               fileBuffer.append("  return ");\r
-                               fileBuffer.append(entryPointList[0]);\r
-                               fileBuffer.append(" (PeiStartupDescriptor, OldCoreData);\r\n");\r
-                               fileBuffer.append("}\r\n\r\n");\r
-                       }\r
-                       break;\r
-\r
-               case CommonDefinition.ModuleTypeDxeCore:\r
-                       fileBuffer.append("const UINT32 _gUefiDriverRevision = 0;\r\n");\r
-                       if (entryPointList == null || entryPointList.length != 1) {\r
-                               throw new BuildException(\r
-                                               "Module type = 'DXE_CORE', can have only one module entry point!");\r
-                       } else {\r
-\r
-                               fileBuffer.append("VOID\r\n");\r
-                               fileBuffer.append("EFIAPI\r\n");\r
-                               fileBuffer.append(entryPointList[0]);\r
-                               fileBuffer.append(" (\n");\r
-                               fileBuffer.append("  IN VOID  *HobStart\r\n");\r
-                               fileBuffer.append("  );\r\n\r\n");\r
-\r
-                               fileBuffer.append("VOID\r\n");\r
-                               fileBuffer.append("EFIAPI\r\n");\r
-                               fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r
-                               fileBuffer.append("  IN VOID  *HobStart\r\n");\r
-                               fileBuffer.append("  )\r\n\r\n");\r
-                               fileBuffer.append("{\r\n");\r
-                               fileBuffer.append("  ");\r
-                               fileBuffer.append(entryPointList[0]);\r
-                               fileBuffer.append(" (HobStart);\r\n");\r
-                               fileBuffer.append("}\r\n\r\n");\r
-                       }\r
-                       break;\r
-\r
-               case CommonDefinition.ModuleTypePeim:\r
-                       int entryPointCount = 0;\r
-                       fileBuffer\r
-                                       .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = 0;\r\n");\r
-                       if (entryPointList == null || entryPointList.length == 0) {\r
-                               fileBuffer.append("EFI_STATUS\r\n");\r
-                               fileBuffer.append("EFIAPI\r\n");\r
-                               fileBuffer.append("ProcessModuleEntryPointList (\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\n");\r
-                               fileBuffer.append("{\r\n");\r
-                               fileBuffer.append("  return EFI_SUCCESS;\r\n");\r
-                               fileBuffer.append("}\r\n\r\n");\r
-                               break;\r
-                       }\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\r
-                                                       .append("  IN EFI_FFS_FILE_HEADER  *FfsHeader,\r\n");\r
-                                       fileBuffer\r
-                                                       .append("  IN EFI_PEI_SERVICES     **PeiServices\r\n");\r
-                                       fileBuffer.append("  );\r\n");\r
-                                       entryPointCount++;\r
-\r
-                       }\r
-\r
-                       fileBuffer.append("EFI_STATUS\r\n");\r
-                       fileBuffer.append("EFIAPI\r\n");\r
-                       fileBuffer.append("ProcessModuleEntryPointList (\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\n");\r
-                       fileBuffer.append("{\r\n");\r
-            if (entryPointCount == 1) {\r
-                               fileBuffer.append("  return ");\r
-                               fileBuffer.append(entryPointList[0]);\r
-                               fileBuffer.append(" (FfsHeader, PeiServices);\r\n");\r
-                       } else {\r
-                               fileBuffer.append("  EFI_STATUS  Status;\r\n");\r
-                               fileBuffer.append("  EFI_STATUS  CombinedStatus;\r\n\r\n");\r
-                               fileBuffer.append("  CombinedStatus = EFI_LOAD_ERROR;\r\n\r\n");\r
-                               for (int i = 0; i < entryPointList.length; i++) {\r
-                                       if (!entryPointList[i].equals("")) {\r
-                                               fileBuffer.append("  Status = ");\r
-                                               fileBuffer.append(entryPointList[i]);\r
-                                               fileBuffer.append(" (FfsHeader, PeiServices);\r\n");\r
-                                               fileBuffer\r
-                                                               .append("  if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {\r\n");\r
-                                               fileBuffer.append("    CombinedStatus = Status;\r\n");\r
-                                               fileBuffer.append("  }\r\n\r\n");\r
-                                       } else {\r
-                                               break;\r
-                                       }\r
-                               }\r
-                               fileBuffer.append("  return CombinedStatus;\r\n");\r
-                       }\r
-                       fileBuffer.append("}\r\n\r\n");\r
-                       break;\r
-\r
-               case CommonDefinition.ModuleTypeDxeSmmDriver:\r
-                       entryPointCount = 0;\r
-            //\r
-            // If entryPoint is null, create an empty ProcessModuleEntryPointList\r
-            // function.\r
-            //\r
-                       if (entryPointList == null || entryPointList.length == 0){\r
-                               fileBuffer\r
-                               .append("GLOBAL_REMOVE_IF_UNREFERENCED  const UINT8  _gDriverEntryPointCount = ");\r
-                       fileBuffer.append(Integer.toString(entryPointCount));\r
-                       fileBuffer.append(";\r\n");\r
-                fileBuffer.append("EFI_STATUS\r\n");\r
-                               fileBuffer.append("EFIAPI\r\n");\r
-                               fileBuffer.append("ProcessModuleEntryPointList (\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\n");\r
-                               fileBuffer.append("{\r\n");\r
-                               fileBuffer.append("  return EFI_SUCCESS;\r\n");\r
-                               fileBuffer.append("}\r\n\r\n");\r
-\r
-                       } 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
-                    fileBuffer.append("  IN EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
-                    fileBuffer.append("  );\r\n");\r
-                    entryPointCount++;\r
+            fileBuffer.append(this.myPcdAutogen.OutputH());\r
+        }\r
+\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
+        if (!saveFile(outputPath + File.separatorChar + "AutoGen.h", fileBuffer)) {\r
+            throw new BuildException("Failed to generate AutoGen.h !!!");\r
+        }\r
+    }\r
+\r
+    /**\r
+     * libGenAutogenC\r
+     *\r
+     * This function generates AutoGen.h for library.\r
+     *\r
+     * @throws BuildException\r
+     *             Failed to generate AutoGen.c.\r
+     */\r
+    void libGenAutogenC() throws BuildException, PcdAutogenException {\r
+        StringBuffer fileBuffer = new StringBuffer(10240);\r
+\r
+        //\r
+        // Write Autogen.c header notation\r
+        //\r
+        fileBuffer.append(CommonDefinition.autogenCNotation);\r
+\r
+        fileBuffer.append(CommonDefinition.autoGenCLine1);\r
+        fileBuffer.append("\r\n");\r
+\r
+        //\r
+        // Call pcd autogen.\r
+        //\r
+        this.myPcdAutogen = new PCDAutoGenAction(moduleId,\r
+                                                 arch,\r
+                                                 true,\r
+                                                 SurfaceAreaQuery.getModulePcdEntryNameArray(),\r
+                                                 pcdDriverType);\r
+        try {\r
+            this.myPcdAutogen.execute();\r
+        } catch (Exception e) {\r
+            throw new PcdAutogenException(e.getMessage());\r
+        }\r
+\r
+        if (this.myPcdAutogen != null) {\r
+            fileBuffer.append("\r\n");\r
+            fileBuffer.append(this.myPcdAutogen.OutputC());\r
+        }\r
+\r
+        if (!saveFile(outputPath + File.separatorChar + "AutoGen.c", fileBuffer)) {\r
+            throw new BuildException("Failed to generate AutoGen.c !!!");\r
+        }\r
+    }\r
+\r
+    /**\r
+     * LibraryClassToAutogenH\r
+     *\r
+     * This function returns *.h files declared by library classes which are\r
+     * consumed or produced by current build module or library.\r
+     *\r
+     * @param libClassList\r
+     *            List of library class which consumed or produce by current\r
+     *            build module or library.\r
+     * @return includeStrList List of *.h file.\r
+     */\r
+    Set<String> LibraryClassToAutogenH(String[] libClassList)\r
+    throws AutoGenException {\r
+        Set<String> includStrList = new LinkedHashSet<String>();\r
+        String includerName[];\r
+        String str = "";\r
+\r
+        //\r
+        // Get include file from GlobalData's SPDTable according to\r
+        // library class name.\r
+        //\r
+\r
+        for (int i = 0; i < libClassList.length; i++) {\r
+            includerName = GlobalData.getLibraryClassHeaderFiles(\r
+                                                                SurfaceAreaQuery.getDependencePkg(this.arch),\r
+                                                                libClassList[i]);\r
+            if (includerName == null) {\r
+                throw new AutoGenException("Can not find library class ["\r
+                                           + libClassList[i] + "] declaration in any SPD package. ");\r
+            }\r
+            for (int j = 0; j < includerName.length; j++) {\r
+                String includeNameStr = includerName[j];\r
+                if (includeNameStr != null) {\r
+                    str = CommonDefinition.include + " " + "<";\r
+                    str = str + includeNameStr + ">\r\n";\r
+                    includStrList.add(str);\r
+                    includeNameStr = null;\r
                 }\r
+            }\r
+        }\r
+        return includStrList;\r
+    }\r
+\r
+    /**\r
+     * IncludesToAutogenH\r
+     *\r
+     * This function add include file in AutoGen.h file.\r
+     *\r
+     * @param packageNameList\r
+     *            List of module depended package.\r
+     * @param moduleType\r
+     *            Module type.\r
+     * @return\r
+     */\r
+    List<String> depPkgToAutogenH(PackageIdentification[] packageNameList,\r
+                                  String moduleType) throws AutoGenException {\r
+\r
+        List<String> includeStrList = new LinkedList<String>();\r
+        String pkgHeader;\r
+        String includeStr = "";\r
+\r
+        //\r
+        // Get include file from moduleInfo file\r
+        //\r
+        for (int i = 0; i < packageNameList.length; i++) {\r
+            pkgHeader = GlobalData.getPackageHeaderFiles(packageNameList[i],\r
+                                                         moduleType);\r
+            if (pkgHeader == null) {\r
+                throw new AutoGenException("Can not find package ["\r
+                                           + packageNameList[i]\r
+                                           + "] declaration in any SPD package. ");\r
+            } else if (!pkgHeader.equalsIgnoreCase("")) {\r
+                includeStr = CommonDefinition.include + " <" + pkgHeader\r
+                             + ">\r\n";\r
+                includeStrList.add(includeStr);\r
+            }\r
+        }\r
+\r
+        return includeStrList;\r
+    }\r
+\r
+    /**\r
+     * EntryPointToAutoGen\r
+     *\r
+     * This function convert <ModuleEntryPoint> & <ModuleUnloadImage>\r
+     * information in mas to AutoGen.c\r
+     *\r
+     * @param entryPointList\r
+     *            List of entry point.\r
+     * @param fileBuffer\r
+     *            String buffer fo AutoGen.c.\r
+     * @throws Exception\r
+     */\r
+    void EntryPointToAutoGen(String[] entryPointList, StringBuffer fileBuffer)\r
+    throws BuildException {\r
+\r
+        String typeStr = SurfaceAreaQuery.getModuleType();\r
+\r
+        //\r
+        // The parameters and return value of entryPoint is difference\r
+        // for difference module type.\r
+        //\r
+        switch (CommonDefinition.getModuleType(typeStr)) {\r
+        \r
+        case CommonDefinition.ModuleTypePeiCore:\r
+            if (entryPointList == null ||entryPointList.length != 1 ) {\r
+                throw new BuildException(\r
+                                        "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\r
-                        .append("GLOBAL_REMOVE_IF_UNREFERENCED  const UINT8  _gDriverEntryPointCount = ");\r
-                fileBuffer.append(Integer.toString(entryPointCount));\r
-                fileBuffer.append(";\r\n");\r
-                fileBuffer\r
-                        .append("static BASE_LIBRARY_JUMP_BUFFER  mJumpContext;\r\n");\r
+                .append("  IN EFI_PEI_STARTUP_DESCRIPTOR  *PeiStartupDescriptor,\r\n");\r
                 fileBuffer\r
-                        .append("static EFI_STATUS  mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n\r\n");\r
+                .append("  IN VOID                        *OldCoreData\r\n");\r
+                fileBuffer.append("  );\r\n\r\n");\r
 \r
                 fileBuffer.append("EFI_STATUS\r\n");\r
                 fileBuffer.append("EFIAPI\r\n");\r
                 fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r
-                fileBuffer.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
-                fileBuffer.append("  IN EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
+                fileBuffer\r
+                .append("  IN EFI_PEI_STARTUP_DESCRIPTOR  *PeiStartupDescriptor,\r\n");\r
+                fileBuffer\r
+                .append("  IN VOID                        *OldCoreData\r\n");\r
                 fileBuffer.append("  )\r\n\r\n");\r
                 fileBuffer.append("{\r\n");\r
+                fileBuffer.append("  return ");\r
+                fileBuffer.append(entryPointList[0]);\r
+                fileBuffer.append(" (PeiStartupDescriptor, OldCoreData);\r\n");\r
+                fileBuffer.append("}\r\n\r\n");\r
+            }\r
+            break;\r
 \r
+        case CommonDefinition.ModuleTypeDxeCore:\r
+            fileBuffer.append("const UINT32 _gUefiDriverRevision = 0;\r\n");\r
+            if (entryPointList == null || entryPointList.length != 1) {\r
+                throw new BuildException(\r
+                                        "Module type = 'DXE_CORE', can have only one module entry point!");\r
+            } else {\r
 \r
-                for (int i = 0; i < entryPointList.length; i++) {\r
-                    fileBuffer\r
-                            .append("  if (SetJump (&mJumpContext) == 0) {\r\n");\r
-                    fileBuffer.append("    ExitDriver (");\r
-                    fileBuffer.append(entryPointList[i]);\r
-                    fileBuffer.append(" (ImageHandle, SystemTable));\r\n");\r
+                fileBuffer.append("VOID\r\n");\r
+                fileBuffer.append("EFIAPI\r\n");\r
+                fileBuffer.append(entryPointList[0]);\r
+                fileBuffer.append(" (\n");\r
+                fileBuffer.append("  IN VOID  *HobStart\r\n");\r
+                fileBuffer.append("  );\r\n\r\n");\r
+\r
+                fileBuffer.append("VOID\r\n");\r
+                fileBuffer.append("EFIAPI\r\n");\r
+                fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r
+                fileBuffer.append("  IN VOID  *HobStart\r\n");\r
+                fileBuffer.append("  )\r\n\r\n");\r
+                fileBuffer.append("{\r\n");\r
+                fileBuffer.append("  ");\r
+                fileBuffer.append(entryPointList[0]);\r
+                fileBuffer.append(" (HobStart);\r\n");\r
+                fileBuffer.append("}\r\n\r\n");\r
+            }\r
+            break;\r
+\r
+        case CommonDefinition.ModuleTypePeim:\r
+            int entryPointCount = 0;\r
+            fileBuffer\r
+            .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = 0;\r\n");\r
+            if (entryPointList == null || entryPointList.length == 0) {\r
+                fileBuffer.append("EFI_STATUS\r\n");\r
+                fileBuffer.append("EFIAPI\r\n");\r
+                fileBuffer.append("ProcessModuleEntryPointList (\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\n");\r
+                fileBuffer.append("{\r\n");\r
+                fileBuffer.append("  return EFI_SUCCESS;\r\n");\r
+                fileBuffer.append("}\r\n\r\n");\r
+                break;\r
+            }\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\r
+                .append("  IN EFI_FFS_FILE_HEADER  *FfsHeader,\r\n");\r
+                fileBuffer\r
+                .append("  IN EFI_PEI_SERVICES     **PeiServices\r\n");\r
+                fileBuffer.append("  );\r\n");\r
+                entryPointCount++;\r
+\r
+            }\r
+\r
+            fileBuffer.append("EFI_STATUS\r\n");\r
+            fileBuffer.append("EFIAPI\r\n");\r
+            fileBuffer.append("ProcessModuleEntryPointList (\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\n");\r
+            fileBuffer.append("{\r\n");\r
+            if (entryPointCount == 1) {\r
+                fileBuffer.append("  return ");\r
+                fileBuffer.append(entryPointList[0]);\r
+                fileBuffer.append(" (FfsHeader, PeiServices);\r\n");\r
+            } else {\r
+                fileBuffer.append("  EFI_STATUS  Status;\r\n");\r
+                fileBuffer.append("  EFI_STATUS  CombinedStatus;\r\n\r\n");\r
+                fileBuffer.append("  CombinedStatus = EFI_LOAD_ERROR;\r\n\r\n");\r
+                for (int i = 0; i < entryPointList.length; i++) {\r
+                    if (!entryPointList[i].equals("")) {\r
+                        fileBuffer.append("  Status = ");\r
+                        fileBuffer.append(entryPointList[i]);\r
+                        fileBuffer.append(" (FfsHeader, PeiServices);\r\n");\r
+                        fileBuffer\r
+                        .append("  if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {\r\n");\r
+                        fileBuffer.append("    CombinedStatus = Status;\r\n");\r
+                        fileBuffer.append("  }\r\n\r\n");\r
+                    } else {\r
+                        break;\r
+                    }\r
+                }\r
+                fileBuffer.append("  return CombinedStatus;\r\n");\r
+            }\r
+            fileBuffer.append("}\r\n\r\n");\r
+            break;\r
+\r
+        case CommonDefinition.ModuleTypeDxeSmmDriver:\r
+            entryPointCount = 0;\r
+            //\r
+            // If entryPoint is null, create an empty ProcessModuleEntryPointList\r
+            // function.\r
+            //\r
+            if (entryPointList == null || entryPointList.length == 0) {\r
+                fileBuffer\r
+                .append("GLOBAL_REMOVE_IF_UNREFERENCED  const UINT8  _gDriverEntryPointCount = ");\r
+                fileBuffer.append(Integer.toString(entryPointCount));\r
+                fileBuffer.append(";\r\n");\r
+                fileBuffer.append("EFI_STATUS\r\n");\r
+                fileBuffer.append("EFIAPI\r\n");\r
+                fileBuffer.append("ProcessModuleEntryPointList (\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\n");\r
+                fileBuffer.append("{\r\n");\r
+                fileBuffer.append("  return EFI_SUCCESS;\r\n");\r
+                fileBuffer.append("}\r\n\r\n");\r
+\r
+            } 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
+                    fileBuffer.append("  IN EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
+                    fileBuffer.append("  );\r\n");\r
+                    entryPointCount++;\r
+                }\r
+                fileBuffer\r
+                .append("GLOBAL_REMOVE_IF_UNREFERENCED  const UINT8  _gDriverEntryPointCount = ");\r
+                fileBuffer.append(Integer.toString(entryPointCount));\r
+                fileBuffer.append(";\r\n");\r
+                fileBuffer\r
+                .append("static BASE_LIBRARY_JUMP_BUFFER  mJumpContext;\r\n");\r
+                fileBuffer\r
+                .append("static EFI_STATUS  mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n\r\n");\r
+\r
+                fileBuffer.append("EFI_STATUS\r\n");\r
+                fileBuffer.append("EFIAPI\r\n");\r
+                fileBuffer.append("ProcessModuleEntryPointList (\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\n");\r
+                fileBuffer.append("{\r\n");\r
+\r
+\r
+                for (int i = 0; i < entryPointList.length; i++) {\r
+                    fileBuffer\r
+                    .append("  if (SetJump (&mJumpContext) == 0) {\r\n");\r
+                    fileBuffer.append("    ExitDriver (");\r
+                    fileBuffer.append(entryPointList[i]);\r
+                    fileBuffer.append(" (ImageHandle, SystemTable));\r\n");\r
                     fileBuffer.append("    ASSERT (FALSE);\r\n");\r
                     fileBuffer.append("  }\r\n");\r
 \r
@@ -940,7 +953,7 @@ public class AutoGen {
                 fileBuffer.append("  )\r\n\r\n");\r
                 fileBuffer.append("{\r\n");\r
                 fileBuffer\r
-                        .append("  if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");\r
+                .append("  if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");\r
                 fileBuffer.append("    mDriverEntryPointStatus = Status;\r\n");\r
                 fileBuffer.append("  }\r\n");\r
                 fileBuffer.append("  LongJump (&mJumpContext, (UINTN)-1);\r\n");\r
@@ -950,53 +963,53 @@ public class AutoGen {
             }\r
 \r
 \r
-                       //\r
-                       // Add "ModuleUnloadImage" for DxeSmmDriver module type;\r
-                       //\r
-                       entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();\r
+            //\r
+            // Add "ModuleUnloadImage" for DxeSmmDriver module type;\r
+            //\r
+            entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();\r
             entryPointList = CommonDefinition.remDupString(entryPointList);\r
-                       entryPointCount = 0;\r
+            entryPointCount = 0;\r
 \r
-                       if (entryPointList != null) {\r
-                               for (int i = 0; i < entryPointList.length; i++) {\r
+            if (entryPointList != null) {\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\r
-                            .append("  IN EFI_HANDLE        ImageHandle\r\n");\r
+                    .append("  IN EFI_HANDLE        ImageHandle\r\n");\r
                     fileBuffer.append("  );\r\n");\r
                     entryPointCount++;\r
                 }\r
-                       }\r
+            }\r
 \r
             fileBuffer\r
-                                       .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8  _gDriverUnloadImageCount = ");\r
-                       fileBuffer.append(Integer.toString(entryPointCount));\r
-                       fileBuffer.append(";\r\n\r\n");\r
-\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
-                       fileBuffer.append("  )\r\n");\r
-                       fileBuffer.append("{\r\n");\r
-\r
-                       if (entryPointCount == 0) {\r
-                               fileBuffer.append("  return EFI_SUCCESS;\r\n");\r
-                       } else if (entryPointCount == 1) {\r
-                               fileBuffer.append("  return ");\r
-                               fileBuffer.append(entryPointList[0]);\r
-                               fileBuffer.append("(ImageHandle);\r\n");\r
-                       } else {\r
-                               fileBuffer.append("  EFI_STATUS  Status;\r\n\r\n");\r
-                               fileBuffer.append("  Status = EFI_SUCCESS;\r\n\r\n");\r
-                               for (int i = 0; i < entryPointList.length; i++) {\r
-                    if (i == 0){\r
+            .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8  _gDriverUnloadImageCount = ");\r
+            fileBuffer.append(Integer.toString(entryPointCount));\r
+            fileBuffer.append(";\r\n\r\n");\r
+\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
+            fileBuffer.append("  )\r\n");\r
+            fileBuffer.append("{\r\n");\r
+\r
+            if (entryPointCount == 0) {\r
+                fileBuffer.append("  return EFI_SUCCESS;\r\n");\r
+            } else if (entryPointCount == 1) {\r
+                fileBuffer.append("  return ");\r
+                fileBuffer.append(entryPointList[0]);\r
+                fileBuffer.append("(ImageHandle);\r\n");\r
+            } else {\r
+                fileBuffer.append("  EFI_STATUS  Status;\r\n\r\n");\r
+                fileBuffer.append("  Status = EFI_SUCCESS;\r\n\r\n");\r
+                for (int i = 0; i < entryPointList.length; i++) {\r
+                    if (i == 0) {\r
                         fileBuffer.append("     Status = ");\r
                         fileBuffer.append(entryPointList[i]);\r
                         fileBuffer.append("(ImageHandle);\r\n");\r
-                    }else{\r
+                    } else {\r
                         fileBuffer.append("  if (EFI_ERROR (Status)) {\r\n");\r
                         fileBuffer.append("    ");\r
                         fileBuffer.append(entryPointList[i]);\r
@@ -1007,36 +1020,36 @@ public class AutoGen {
                         fileBuffer.append("(ImageHandle);\r\n");\r
                         fileBuffer.append("  }\r\n");\r
                     }\r
-                               }\r
-                               fileBuffer.append("  return Status;\r\n");\r
-                       }\r
-                       fileBuffer.append("}\r\n\r\n");\r
-                       break;\r
-\r
-               case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
-               case CommonDefinition.ModuleTypeDxeDriver:\r
-               case CommonDefinition.ModuleTypeDxeSalDriver:\r
-               case CommonDefinition.ModuleTypeUefiDriver:\r
-               case CommonDefinition.ModuleTypeUefiApplication:\r
-                       entryPointCount = 0;\r
-                       fileBuffer.append("const UINT32 _gUefiDriverRevision = 0;\r\n");\r
+                }\r
+                fileBuffer.append("  return Status;\r\n");\r
+            }\r
+            fileBuffer.append("}\r\n\r\n");\r
+            break;\r
+\r
+        case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
+        case CommonDefinition.ModuleTypeDxeDriver:\r
+        case CommonDefinition.ModuleTypeDxeSalDriver:\r
+        case CommonDefinition.ModuleTypeUefiDriver:\r
+        case CommonDefinition.ModuleTypeUefiApplication:\r
+            entryPointCount = 0;\r
+            fileBuffer.append("const UINT32 _gUefiDriverRevision = 0;\r\n");\r
             //\r
             // If entry point is null, create a empty ProcessModuleEntryPointList function.\r
             //\r
-                       if (entryPointList == null || entryPointList.length == 0){\r
+            if (entryPointList == null || entryPointList.length == 0) {\r
                 fileBuffer\r
                 .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8  _gDriverEntryPointCount = 0;\r\n");\r
-                               fileBuffer.append("EFI_STATUS\r\n");\r
-                               fileBuffer.append("EFIAPI\r\n");\r
-                               fileBuffer.append("ProcessModuleEntryPointList (\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\n");\r
-                               fileBuffer.append("{\r\n");\r
-                               fileBuffer.append("  return EFI_SUCCESS;\r\n");\r
-                               fileBuffer.append("}\r\n");\r
-\r
-                       }else {\r
+                fileBuffer.append("EFI_STATUS\r\n");\r
+                fileBuffer.append("EFIAPI\r\n");\r
+                fileBuffer.append("ProcessModuleEntryPointList (\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\n");\r
+                fileBuffer.append("{\r\n");\r
+                fileBuffer.append("  return EFI_SUCCESS;\r\n");\r
+                fileBuffer.append("}\r\n");\r
+\r
+            else {\r
                 for (int i = 0; i < entryPointList.length; i++) {\r
 \r
                     fileBuffer.append("EFI_STATUS\r\n");\r
@@ -1050,14 +1063,14 @@ public class AutoGen {
                 }\r
 \r
                 fileBuffer\r
-                        .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8  _gDriverEntryPointCount = ");\r
+                .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8  _gDriverEntryPointCount = ");\r
                 fileBuffer.append(Integer.toString(entryPointCount));\r
                 fileBuffer.append(";\r\n");\r
                 if (entryPointCount > 1) {\r
                     fileBuffer\r
-                            .append("static BASE_LIBRARY_JUMP_BUFFER  mJumpContext;\r\n");\r
+                    .append("static BASE_LIBRARY_JUMP_BUFFER  mJumpContext;\r\n");\r
                     fileBuffer\r
-                            .append("static EFI_STATUS  mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n");\r
+                    .append("static EFI_STATUS  mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n");\r
                 }\r
                 fileBuffer.append("\n");\r
 \r
@@ -1077,7 +1090,7 @@ public class AutoGen {
                     for (int i = 0; i < entryPointList.length; i++) {\r
                         if (!entryPointList[i].equals("")) {\r
                             fileBuffer\r
-                                    .append("  if (SetJump (&mJumpContext) == 0) {\r\n");\r
+                            .append("  if (SetJump (&mJumpContext) == 0) {\r\n");\r
                             fileBuffer.append("    ExitDriver (");\r
                             fileBuffer.append(entryPointList[i]);\r
                             fileBuffer.append(" (ImageHandle, SystemTable));\r\n");\r
@@ -1100,13 +1113,13 @@ public class AutoGen {
                 if (entryPointCount <= 1) {\r
                     fileBuffer.append("  if (EFI_ERROR (Status)) {\r\n");\r
                     fileBuffer\r
-                            .append("    ProcessLibraryDestructorList (gImageHandle, gST);\r\n");\r
+                    .append("    ProcessLibraryDestructorList (gImageHandle, gST);\r\n");\r
                     fileBuffer.append("  }\r\n");\r
                     fileBuffer\r
-                            .append("  gBS->Exit (gImageHandle, Status, 0, NULL);\r\n");\r
+                    .append("  gBS->Exit (gImageHandle, Status, 0, NULL);\r\n");\r
                 } else {\r
                     fileBuffer\r
-                            .append("  if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");\r
+                    .append("  if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");\r
                     fileBuffer.append("    mDriverEntryPointStatus = Status;\r\n");\r
                     fileBuffer.append("  }\r\n");\r
                     fileBuffer.append("  LongJump (&mJumpContext, (UINTN)-1);\r\n");\r
@@ -1116,855 +1129,855 @@ public class AutoGen {
 \r
             }\r
 \r
-                       //\r
-                       // Add ModuleUnloadImage for DxeDriver and UefiDriver module type.\r
-                       //\r
-                       entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();\r
+            //\r
+            // Add ModuleUnloadImage for DxeDriver and UefiDriver module type.\r
+            //\r
+            entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();\r
             //\r
             // Remover duplicate unload entry point.\r
             //\r
             entryPointList = CommonDefinition.remDupString(entryPointList);\r
-                       entryPointCount = 0;\r
-                       if (entryPointList != null) {\r
-                               for (int i = 0; i < entryPointList.length; i++) {\r
+            entryPointCount = 0;\r
+            if (entryPointList != null) {\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\r
-                            .append("  IN EFI_HANDLE        ImageHandle\r\n");\r
+                    .append("  IN EFI_HANDLE        ImageHandle\r\n");\r
                     fileBuffer.append("  );\r\n");\r
                     entryPointCount++;\r
-                               }\r
-                       }\r
-\r
-                       fileBuffer\r
-                                       .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8  _gDriverUnloadImageCount = ");\r
-                       fileBuffer.append(Integer.toString(entryPointCount));\r
-                       fileBuffer.append(";\r\n\r\n");\r
-\r
-                       fileBuffer.append("EFI_STATUS\n");\r
-                       fileBuffer.append("EFIAPI\r\n");\r
-                       fileBuffer.append("ProcessModuleUnloadList (\r\n");\r
-                       fileBuffer.append("  IN EFI_HANDLE  ImageHandle\r\n");\r
-                       fileBuffer.append("  )\r\n");\r
-                       fileBuffer.append("{\r\n");\r
-\r
-                       if (entryPointCount == 0) {\r
-                               fileBuffer.append("  return EFI_SUCCESS;\r\n");\r
-                       } else if (entryPointCount == 1) {\r
-                               fileBuffer.append("  return ");\r
-                               fileBuffer.append(entryPointList[0]);\r
-                               fileBuffer.append("(ImageHandle);\r\n");\r
-                       } else {\r
-                               fileBuffer.append("  EFI_STATUS  Status;\r\n\r\n");\r
-                               fileBuffer.append("  Status = EFI_SUCCESS;\r\n\r\n");\r
-                               for (int i = 0; i < entryPointList.length; i++) {\r
+                }\r
+            }\r
+\r
+            fileBuffer\r
+            .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8  _gDriverUnloadImageCount = ");\r
+            fileBuffer.append(Integer.toString(entryPointCount));\r
+            fileBuffer.append(";\r\n\r\n");\r
+\r
+            fileBuffer.append("EFI_STATUS\n");\r
+            fileBuffer.append("EFIAPI\r\n");\r
+            fileBuffer.append("ProcessModuleUnloadList (\r\n");\r
+            fileBuffer.append("  IN EFI_HANDLE  ImageHandle\r\n");\r
+            fileBuffer.append("  )\r\n");\r
+            fileBuffer.append("{\r\n");\r
+\r
+            if (entryPointCount == 0) {\r
+                fileBuffer.append("  return EFI_SUCCESS;\r\n");\r
+            } else if (entryPointCount == 1) {\r
+                fileBuffer.append("  return ");\r
+                fileBuffer.append(entryPointList[0]);\r
+                fileBuffer.append("(ImageHandle);\r\n");\r
+            } else {\r
+                fileBuffer.append("  EFI_STATUS  Status;\r\n\r\n");\r
+                fileBuffer.append("  Status = EFI_SUCCESS;\r\n\r\n");\r
+                for (int i = 0; i < entryPointList.length; i++) {\r
                     if (i == 0) {\r
                         fileBuffer.append("  Status = ");\r
                         fileBuffer.append(entryPointList[i]);\r
                         fileBuffer.append("(ImageHandle);\r\n");\r
-                    }else{\r
+                    } else {\r
                         fileBuffer.append("  if (EFI_ERROR (Status)) {\r\n");\r
-                                               fileBuffer.append("    ");\r
-                                               fileBuffer.append(entryPointList[i]);\r
-                                               fileBuffer.append("(ImageHandle);\r\n");\r
-                                               fileBuffer.append("  } else {\r\n");\r
-                                               fileBuffer.append("    Status = ");\r
-                                               fileBuffer.append(entryPointList[i]);\r
-                                               fileBuffer.append("(ImageHandle);\r\n");\r
-                                               fileBuffer.append("  }\r\n");\r
+                        fileBuffer.append("    ");\r
+                        fileBuffer.append(entryPointList[i]);\r
+                        fileBuffer.append("(ImageHandle);\r\n");\r
+                        fileBuffer.append("  } else {\r\n");\r
+                        fileBuffer.append("    Status = ");\r
+                        fileBuffer.append(entryPointList[i]);\r
+                        fileBuffer.append("(ImageHandle);\r\n");\r
+                        fileBuffer.append("  }\r\n");\r
                     }\r
-                               }\r
-                               fileBuffer.append("  return Status;\r\n");\r
-                       }\r
-                       fileBuffer.append("}\r\n\r\n");\r
-                       break;\r
-               }\r
-       }\r
-\r
-       /**\r
-        * PpiGuidToAutogenc\r
-        *\r
-        * This function gets GUIDs from SPD file accrodeing to <PPIs> information\r
-        * and write those GUIDs to AutoGen.c.\r
-        *\r
-        * @param fileBuffer\r
-        *            String Buffer for Autogen.c file.\r
-        * @throws BuildException\r
-        *             Guid must set value!\r
-        */\r
-       void PpiGuidToAutogenC(StringBuffer fileBuffer) throws AutoGenException {\r
-               String[] cNameGuid = null;\r
-\r
-               //\r
-               // Get the all PPI adn PPI Notify from MSA file,\r
-               // then add those PPI ,and PPI Notify name to list.\r
-               //\r
-\r
-               String[] ppiList = SurfaceAreaQuery.getPpiArray(this.arch);\r
-               for (int i = 0; i < ppiList.length; i++) {\r
-                       this.mPpiList.add(ppiList[i]);\r
-               }\r
-\r
-               String[] ppiNotifyList = SurfaceAreaQuery.getPpiNotifyArray(this.arch);\r
-               for (int i = 0; i < ppiNotifyList.length; i++) {\r
-                       this.mPpiList.add(ppiNotifyList[i]);\r
-               }\r
-\r
-               //\r
-               // Find CNAME and GUID from dependence SPD file and write to Autogen.c\r
-               //\r
-               Iterator ppiIterator = this.mPpiList.iterator();\r
-               String ppiKeyWord = null;\r
-               while (ppiIterator.hasNext()) {\r
-                       ppiKeyWord = ppiIterator.next().toString();\r
-                       cNameGuid = GlobalData.getPpiGuid(this.mDepPkgList, ppiKeyWord);\r
-                       if (cNameGuid != null) {\r
-                               fileBuffer\r
-                                               .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r
-                               fileBuffer.append(cNameGuid[0]);\r
-                               fileBuffer.append(" =     { ");\r
-                               fileBuffer.append(CommonDefinition.formatGuidName(cNameGuid[1]));\r
-                               fileBuffer.append(" } ;");\r
-                       } else {\r
-                               //\r
-                               // If can't find Ppi GUID declaration in every package\r
-                               //\r
-                               throw new AutoGenException("Can not find Ppi GUID ["\r
-                                               + ppiKeyWord + "] declaration in any SPD package!");\r
-                       }\r
-               }\r
-       }\r
-\r
-       /**\r
-        * ProtocolGuidToAutogenc\r
-        *\r
-        * This function gets GUIDs from SPD file accrodeing to <Protocol>\r
-        * information and write those GUIDs to AutoGen.c.\r
-        *\r
-        * @param fileBuffer\r
-        *            String Buffer for Autogen.c file.\r
-        * @throws BuildException\r
-        *             Protocol name must set.\r
-        */\r
-       void ProtocolGuidToAutogenC(StringBuffer fileBuffer) throws BuildException {\r
-               String[] cNameGuid = null;\r
-\r
-               String[] protocolList = SurfaceAreaQuery.getProtocolArray(this.arch);\r
-\r
-               //\r
-               // Add result to Autogen global list.\r
-               //\r
-               for (int i = 0; i < protocolList.length; i++) {\r
-                       this.mProtocolList.add(protocolList[i]);\r
-               }\r
-\r
-               String[] protocolNotifyList = SurfaceAreaQuery\r
-                               .getProtocolNotifyArray(this.arch);\r
-\r
-               for (int i = 0; i < protocolNotifyList.length; i++) {\r
-                       this.mProtocolList.add(protocolNotifyList[i]);\r
-               }\r
-\r
-               //\r
-               // Get the NAME and GUID from dependence SPD and write to Autogen.c\r
-               //\r
-               Iterator protocolIterator = this.mProtocolList.iterator();\r
-               String protocolKeyWord = null;\r
-\r
-\r
-               while (protocolIterator.hasNext()) {\r
-                       protocolKeyWord = protocolIterator.next().toString();\r
-                       cNameGuid = GlobalData.getProtocolGuid(this.mDepPkgList, protocolKeyWord);\r
-                       if (cNameGuid != null) {\r
-                               fileBuffer\r
-                                               .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r
-                               fileBuffer.append(cNameGuid[0]);\r
-                               fileBuffer.append(" =     { ");\r
-                               fileBuffer.append(CommonDefinition.formatGuidName(cNameGuid[1]));\r
-                               fileBuffer.append(" } ;");\r
-                       } else {\r
-                               //\r
-                               // If can't find protocol GUID declaration in every package\r
-                               //\r
-                               throw new BuildException("Can not find protocol Guid ["\r
-                                               + protocolKeyWord + "] declaration in any SPD package!");\r
-                       }\r
-               }\r
-       }\r
-\r
-       /**\r
-        * GuidGuidToAutogenc\r
-        *\r
-        * This function gets GUIDs from SPD file accrodeing to <Guids> information\r
-        * and write those GUIDs to AutoGen.c.\r
-        *\r
-        * @param fileBuffer\r
-        *            String Buffer for Autogen.c file.\r
-        *\r
-        */\r
-       void GuidGuidToAutogenC(StringBuffer fileBuffer) throws AutoGenException {\r
-               String[] cNameGuid = null;\r
-               String guidKeyWord = null;\r
-\r
-               String[] guidList = SurfaceAreaQuery.getGuidEntryArray(this.arch);\r
-\r
-               for (int i = 0; i < guidList.length; i++) {\r
-                       this.mGuidList.add(guidList[i]);\r
-               }\r
-\r
-\r
-               Iterator guidIterator = this.mGuidList.iterator();\r
-               while (guidIterator.hasNext()) {\r
-                       guidKeyWord = guidIterator.next().toString();\r
-                       cNameGuid = GlobalData.getGuid(this.mDepPkgList, guidKeyWord);\r
-\r
-                       if (cNameGuid != null) {\r
-                               fileBuffer\r
-                                               .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r
-                               fileBuffer.append(cNameGuid[0]);\r
-                               fileBuffer.append(" =     { ");\r
-                               fileBuffer.append(CommonDefinition.formatGuidName(cNameGuid[1]));\r
-                               fileBuffer.append("} ;");\r
-                       } else {\r
-                               //\r
-                               // If can't find GUID declaration in every package\r
-                               //\r
-                               throw new AutoGenException("Can not find Guid [" + guidKeyWord\r
-                                               + "] declaration in any SPD package. ");\r
-                       }\r
-\r
-               }\r
-       }\r
-\r
-       /**\r
-        * LibInstanceToAutogenC\r
-        *\r
-        * This function adds dependent library instance to autogen.c,which\r
-        * includeing library's constructor, destructor, and library dependent ppi,\r
-        * protocol, guid, pcd information.\r
-        *\r
-        * @param fileBuffer\r
-        *            String buffer for AutoGen.c\r
-        * @throws BuildException\r
-        */\r
-       void LibInstanceToAutogenC(StringBuffer fileBuffer) throws BuildException {\r
-               try {\r
+                }\r
+                fileBuffer.append("  return Status;\r\n");\r
+            }\r
+            fileBuffer.append("}\r\n\r\n");\r
+            break;\r
+        }\r
+    }\r
+\r
+    /**\r
+     * PpiGuidToAutogenc\r
+     *\r
+     * This function gets GUIDs from SPD file accrodeing to <PPIs> information\r
+     * and write those GUIDs to AutoGen.c.\r
+     *\r
+     * @param fileBuffer\r
+     *            String Buffer for Autogen.c file.\r
+     * @throws BuildException\r
+     *             Guid must set value!\r
+     */\r
+    void PpiGuidToAutogenC(StringBuffer fileBuffer) throws AutoGenException {\r
+        String[] cNameGuid = null;\r
+\r
+        //\r
+        // Get the all PPI adn PPI Notify from MSA file,\r
+        // then add those PPI ,and PPI Notify name to list.\r
+        //\r
+\r
+        String[] ppiList = SurfaceAreaQuery.getPpiArray(this.arch);\r
+        for (int i = 0; i < ppiList.length; i++) {\r
+            this.mPpiList.add(ppiList[i]);\r
+        }\r
+\r
+        String[] ppiNotifyList = SurfaceAreaQuery.getPpiNotifyArray(this.arch);\r
+        for (int i = 0; i < ppiNotifyList.length; i++) {\r
+            this.mPpiList.add(ppiNotifyList[i]);\r
+        }\r
+\r
+        //\r
+        // Find CNAME and GUID from dependence SPD file and write to Autogen.c\r
+        //\r
+        Iterator ppiIterator = this.mPpiList.iterator();\r
+        String ppiKeyWord = null;\r
+        while (ppiIterator.hasNext()) {\r
+            ppiKeyWord = ppiIterator.next().toString();\r
+            cNameGuid = GlobalData.getPpiGuid(this.mDepPkgList, ppiKeyWord);\r
+            if (cNameGuid != null) {\r
+                fileBuffer\r
+                .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r
+                fileBuffer.append(cNameGuid[0]);\r
+                fileBuffer.append(" =     { ");\r
+                fileBuffer.append(CommonDefinition.formatGuidName(cNameGuid[1]));\r
+                fileBuffer.append(" } ;");\r
+            } else {\r
+                //\r
+                // If can't find Ppi GUID declaration in every package\r
+                //\r
+                throw new AutoGenException("Can not find Ppi GUID ["\r
+                                           + ppiKeyWord + "] declaration in any SPD package!");\r
+            }\r
+        }\r
+    }\r
+\r
+    /**\r
+     * ProtocolGuidToAutogenc\r
+     *\r
+     * This function gets GUIDs from SPD file accrodeing to <Protocol>\r
+     * information and write those GUIDs to AutoGen.c.\r
+     *\r
+     * @param fileBuffer\r
+     *            String Buffer for Autogen.c file.\r
+     * @throws BuildException\r
+     *             Protocol name must set.\r
+     */\r
+    void ProtocolGuidToAutogenC(StringBuffer fileBuffer) throws BuildException {\r
+        String[] cNameGuid = null;\r
+\r
+        String[] protocolList = SurfaceAreaQuery.getProtocolArray(this.arch);\r
+\r
+        //\r
+        // Add result to Autogen global list.\r
+        //\r
+        for (int i = 0; i < protocolList.length; i++) {\r
+            this.mProtocolList.add(protocolList[i]);\r
+        }\r
+\r
+        String[] protocolNotifyList = SurfaceAreaQuery\r
+                                      .getProtocolNotifyArray(this.arch);\r
+\r
+        for (int i = 0; i < protocolNotifyList.length; i++) {\r
+            this.mProtocolList.add(protocolNotifyList[i]);\r
+        }\r
+\r
+        //\r
+        // Get the NAME and GUID from dependence SPD and write to Autogen.c\r
+        //\r
+        Iterator protocolIterator = this.mProtocolList.iterator();\r
+        String protocolKeyWord = null;\r
+\r
+\r
+        while (protocolIterator.hasNext()) {\r
+            protocolKeyWord = protocolIterator.next().toString();\r
+            cNameGuid = GlobalData.getProtocolGuid(this.mDepPkgList, protocolKeyWord);\r
+            if (cNameGuid != null) {\r
+                fileBuffer\r
+                .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r
+                fileBuffer.append(cNameGuid[0]);\r
+                fileBuffer.append(" =     { ");\r
+                fileBuffer.append(CommonDefinition.formatGuidName(cNameGuid[1]));\r
+                fileBuffer.append(" } ;");\r
+            } else {\r
+                //\r
+                // If can't find protocol GUID declaration in every package\r
+                //\r
+                throw new BuildException("Can not find protocol Guid ["\r
+                                         + protocolKeyWord + "] declaration in any SPD package!");\r
+            }\r
+        }\r
+    }\r
+\r
+    /**\r
+     * GuidGuidToAutogenc\r
+     *\r
+     * This function gets GUIDs from SPD file accrodeing to <Guids> information\r
+     * and write those GUIDs to AutoGen.c.\r
+     *\r
+     * @param fileBuffer\r
+     *            String Buffer for Autogen.c file.\r
+     *\r
+     */\r
+    void GuidGuidToAutogenC(StringBuffer fileBuffer) throws AutoGenException {\r
+        String[] cNameGuid = null;\r
+        String guidKeyWord = null;\r
+\r
+        String[] guidList = SurfaceAreaQuery.getGuidEntryArray(this.arch);\r
+\r
+        for (int i = 0; i < guidList.length; i++) {\r
+            this.mGuidList.add(guidList[i]);\r
+        }\r
+\r
+\r
+        Iterator guidIterator = this.mGuidList.iterator();\r
+        while (guidIterator.hasNext()) {\r
+            guidKeyWord = guidIterator.next().toString();\r
+            cNameGuid = GlobalData.getGuid(this.mDepPkgList, guidKeyWord);\r
+\r
+            if (cNameGuid != null) {\r
+                fileBuffer\r
+                .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r
+                fileBuffer.append(cNameGuid[0]);\r
+                fileBuffer.append(" =     { ");\r
+                fileBuffer.append(CommonDefinition.formatGuidName(cNameGuid[1]));\r
+                fileBuffer.append("} ;");\r
+            } else {\r
+                //\r
+                // If can't find GUID declaration in every package\r
+                //\r
+                throw new AutoGenException("Can not find Guid [" + guidKeyWord\r
+                                           + "] declaration in any SPD package. ");\r
+            }\r
+\r
+        }\r
+    }\r
+\r
+    /**\r
+     * LibInstanceToAutogenC\r
+     *\r
+     * This function adds dependent library instance to autogen.c,which\r
+     * includeing library's constructor, destructor, and library dependent ppi,\r
+     * protocol, guid, pcd information.\r
+     *\r
+     * @param fileBuffer\r
+     *            String buffer for AutoGen.c\r
+     * @throws BuildException\r
+     */\r
+    void LibInstanceToAutogenC(StringBuffer fileBuffer) throws BuildException {\r
+        try {\r
             String moduleType = this.moduleId.getModuleType();\r
-                   //\r
-                       // Add library constructor to AutoGen.c\r
-                       //\r
-                       LibConstructorToAutogenC(libConstructList, moduleType,\r
-                               fileBuffer/* autogenC */);\r
-                       //\r
-                       // Add library destructor to AutoGen.c\r
-                       //\r
-                       LibDestructorToAutogenC(libDestructList, moduleType, fileBuffer/* autogenC */);\r
-               } catch (Exception e) {\r
-                       throw new BuildException(e.getMessage());\r
-               }\r
-       }\r
-\r
-       /**\r
-        * LibConstructorToAutogenc\r
-        *\r
-        * This function writes library constructor list to AutoGen.c. 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 LibConstructorToAutogenC(List<String> libInstanceList,\r
-                       String moduleType, StringBuffer fileBuffer) throws Exception {\r
-               boolean isFirst = true;\r
-\r
-               //\r
-               // The library constructor's parameter and return value depend on\r
-               // module type.\r
-               //\r
-               for (int i = 0; i < libInstanceList.size(); i++) {\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));\r
-                               fileBuffer.append(" (\r\n");\r
-                               fileBuffer.append("  VOID\r\n");\r
-                               fileBuffer.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));\r
-                               fileBuffer.append(" (\r\n");\r
-                               fileBuffer\r
-                                               .append("  IN EFI_FFS_FILE_HEADER       *FfsHeader,\r\n");\r
-                               fileBuffer\r
-                                               .append("  IN EFI_PEI_SERVICES          **PeiServices\r\n");\r
-                               fileBuffer.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
-                               fileBuffer.append("EFI_STATUS\r\n");\r
-                               fileBuffer.append("EFIAPI\r\n");\r
-                               fileBuffer.append(libInstanceList.get(i));\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
-                               break;\r
-                       }\r
-               }\r
-\r
-               //\r
-               // Add ProcessLibraryConstructorList in AutoGen.c\r
-               //\r
-               fileBuffer.append("VOID\r\n");\r
-               fileBuffer.append("EFIAPI\r\n");\r
-               fileBuffer.append("ProcessLibraryConstructorList (\r\n");\r
-               switch (CommonDefinition.getModuleType(moduleType)) {\r
-               case CommonDefinition.ModuleTypeBase:\r
-                       fileBuffer.append("  VOID\r\n");\r
-                       break;\r
-\r
-               case CommonDefinition.ModuleTypePeiCore:\r
-               case CommonDefinition.ModuleTypePeim:\r
-                       fileBuffer.append("  IN EFI_FFS_FILE_HEADER       *FfsHeader,\r\n");\r
-                       fileBuffer\r
-                                       .append("  IN EFI_PEI_SERVICES          **PeiServices\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
-                       fileBuffer.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
-                       fileBuffer.append("  IN EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
-                       break;\r
-               }\r
-\r
-               fileBuffer.append("  )\r\n");\r
-               fileBuffer.append("{\r\n");\r
+            //\r
+            // Add library constructor to AutoGen.c\r
+            //\r
+            LibConstructorToAutogenC(libConstructList, moduleType,\r
+                                     fileBuffer/* autogenC */);\r
+            //\r
+            // Add library destructor to AutoGen.c\r
+            //\r
+            LibDestructorToAutogenC(libDestructList, moduleType, fileBuffer/* autogenC */);\r
+        } catch (Exception e) {\r
+            throw new BuildException(e.getMessage());\r
+        }\r
+    }\r
+\r
+    /**\r
+     * LibConstructorToAutogenc\r
+     *\r
+     * This function writes library constructor list to AutoGen.c. 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 LibConstructorToAutogenC(List<String> libInstanceList,\r
+                                  String moduleType, StringBuffer fileBuffer) throws Exception {\r
+        boolean isFirst = true;\r
+\r
+        //\r
+        // The library constructor's parameter and return value depend on\r
+        // module type.\r
+        //\r
+        for (int i = 0; i < libInstanceList.size(); i++) {\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));\r
+                fileBuffer.append(" (\r\n");\r
+                fileBuffer.append("  VOID\r\n");\r
+                fileBuffer.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));\r
+                fileBuffer.append(" (\r\n");\r
+                fileBuffer\r
+                .append("  IN EFI_FFS_FILE_HEADER       *FfsHeader,\r\n");\r
+                fileBuffer\r
+                .append("  IN EFI_PEI_SERVICES          **PeiServices\r\n");\r
+                fileBuffer.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
+                fileBuffer.append("EFI_STATUS\r\n");\r
+                fileBuffer.append("EFIAPI\r\n");\r
+                fileBuffer.append(libInstanceList.get(i));\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
+                break;\r
+            }\r
+        }\r
+\r
+        //\r
+        // Add ProcessLibraryConstructorList in AutoGen.c\r
+        //\r
+        fileBuffer.append("VOID\r\n");\r
+        fileBuffer.append("EFIAPI\r\n");\r
+        fileBuffer.append("ProcessLibraryConstructorList (\r\n");\r
+        switch (CommonDefinition.getModuleType(moduleType)) {\r
+        case CommonDefinition.ModuleTypeBase:\r
+            fileBuffer.append("  VOID\r\n");\r
+            break;\r
+\r
+        case CommonDefinition.ModuleTypePeiCore:\r
+        case CommonDefinition.ModuleTypePeim:\r
+            fileBuffer.append("  IN EFI_FFS_FILE_HEADER       *FfsHeader,\r\n");\r
+            fileBuffer\r
+            .append("  IN EFI_PEI_SERVICES          **PeiServices\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
+            fileBuffer.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
+            fileBuffer.append("  IN EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
+            break;\r
+        }\r
+\r
+        fileBuffer.append("  )\r\n");\r
+        fileBuffer.append("{\r\n");\r
         //\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
+        for (int i = 0; i < libInstanceList.size(); i++) {\r
+            if (isFirst) {\r
+                fileBuffer.append("  EFI_STATUS  Status;\r\n");\r
                 fileBuffer.append("  Status = EFI_SUCCESS;\r\n");\r
-                               fileBuffer.append("\r\n");\r
-                               isFirst = false;\r
-                       }\r
-                       switch (CommonDefinition.getModuleType(moduleType)) {\r
-                       case CommonDefinition.ModuleTypeBase:\r
-                               fileBuffer.append("  Status = ");\r
-                               fileBuffer.append(libInstanceList.get(i));\r
-                               fileBuffer.append("();\r\n");\r
-                               fileBuffer.append("  VOID\r\n");\r
-                               break;\r
-                       case CommonDefinition.ModuleTypePeiCore:\r
-                       case CommonDefinition.ModuleTypePeim:\r
-                               fileBuffer.append("  Status = ");\r
-                               fileBuffer.append(libInstanceList.get(i));\r
-                               fileBuffer.append(" (FfsHeader, PeiServices);\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
-                               fileBuffer.append("  Status = ");\r
-                               fileBuffer.append(libInstanceList.get(i));\r
-                               fileBuffer.append(" (ImageHandle, SystemTable);\r\n");\r
-                               break;\r
+                fileBuffer.append("\r\n");\r
+                isFirst = false;\r
+            }\r
+            switch (CommonDefinition.getModuleType(moduleType)) {\r
+            case CommonDefinition.ModuleTypeBase:\r
+                fileBuffer.append("  Status = ");\r
+                fileBuffer.append(libInstanceList.get(i));\r
+                fileBuffer.append("();\r\n");\r
+                fileBuffer.append("  VOID\r\n");\r
+                break;\r
+            case CommonDefinition.ModuleTypePeiCore:\r
+            case CommonDefinition.ModuleTypePeim:\r
+                fileBuffer.append("  Status = ");\r
+                fileBuffer.append(libInstanceList.get(i));\r
+                fileBuffer.append(" (FfsHeader, PeiServices);\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
+                fileBuffer.append("  Status = ");\r
+                fileBuffer.append(libInstanceList.get(i));\r
+                fileBuffer.append(" (ImageHandle, SystemTable);\r\n");\r
+                break;\r
             default:\r
                 EdkLog.log(EdkLog.EDK_INFO,"Autogen doesn't know how to deal with module type - " + moduleType + "!");\r
-                       }\r
-                       fileBuffer.append("  ASSERT_EFI_ERROR (Status);\r\n");\r
-               }\r
-               fileBuffer.append("}\r\n");\r
-       }\r
-\r
-       /**\r
-        * LibDestructorToAutogenc\r
-        *\r
-        * This function writes library destructor list to AutoGen.c. 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 LibDestructorToAutogenC(List<String> libInstanceList,\r
-                       String moduleType, StringBuffer fileBuffer) throws Exception {\r
-               boolean isFirst = true;\r
-               for (int i = 0; i < libInstanceList.size(); i++) {\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));\r
-                               fileBuffer.append(" (\r\n");\r
-                               fileBuffer.append("  VOID\r\n");\r
-                               fileBuffer.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));\r
-                               fileBuffer.append(" (\r\n");\r
-                               fileBuffer\r
-                                               .append("  IN EFI_FFS_FILE_HEADER       *FfsHeader,\r\n");\r
-                               fileBuffer\r
-                                               .append("  IN EFI_PEI_SERVICES          **PeiServices\r\n");\r
-                               fileBuffer.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
-                               fileBuffer.append("EFI_STATUS\r\n");\r
-                               fileBuffer.append("EFIAPI\r\n");\r
-                               fileBuffer.append(libInstanceList.get(i));\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
-                               break;\r
-                       }\r
-               }\r
-\r
-               //\r
-               // Write ProcessLibraryDestructor list to autogen.c\r
-               //\r
-               switch (CommonDefinition.getModuleType(moduleType)) {\r
-               case CommonDefinition.ModuleTypeBase:\r
-               case CommonDefinition.ModuleTypePeiCore:\r
-               case CommonDefinition.ModuleTypePeim:\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
-                       fileBuffer.append("VOID\r\n");\r
-                       fileBuffer.append("EFIAPI\r\n");\r
-                       fileBuffer.append("ProcessLibraryDestructorList (\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
-                       fileBuffer.append("{\r\n");\r
+            }\r
+            fileBuffer.append("  ASSERT_EFI_ERROR (Status);\r\n");\r
+        }\r
+        fileBuffer.append("}\r\n");\r
+    }\r
+\r
+    /**\r
+     * LibDestructorToAutogenc\r
+     *\r
+     * This function writes library destructor list to AutoGen.c. 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 LibDestructorToAutogenC(List<String> libInstanceList,\r
+                                 String moduleType, StringBuffer fileBuffer) throws Exception {\r
+        boolean isFirst = true;\r
+        for (int i = 0; i < libInstanceList.size(); i++) {\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));\r
+                fileBuffer.append(" (\r\n");\r
+                fileBuffer.append("  VOID\r\n");\r
+                fileBuffer.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));\r
+                fileBuffer.append(" (\r\n");\r
+                fileBuffer\r
+                .append("  IN EFI_FFS_FILE_HEADER       *FfsHeader,\r\n");\r
+                fileBuffer\r
+                .append("  IN EFI_PEI_SERVICES          **PeiServices\r\n");\r
+                fileBuffer.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
+                fileBuffer.append("EFI_STATUS\r\n");\r
+                fileBuffer.append("EFIAPI\r\n");\r
+                fileBuffer.append(libInstanceList.get(i));\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
+                break;\r
+            }\r
+        }\r
+\r
+        //\r
+        // Write ProcessLibraryDestructor list to autogen.c\r
+        //\r
+        switch (CommonDefinition.getModuleType(moduleType)) {\r
+        case CommonDefinition.ModuleTypeBase:\r
+        case CommonDefinition.ModuleTypePeiCore:\r
+        case CommonDefinition.ModuleTypePeim:\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
+            fileBuffer.append("VOID\r\n");\r
+            fileBuffer.append("EFIAPI\r\n");\r
+            fileBuffer.append("ProcessLibraryDestructorList (\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
+            fileBuffer.append("{\r\n");\r
             //\r
             // If no library destructor function, return EFI_SUCCESS.\r
             //\r
 \r
-                       for (int i = 0; i < libInstanceList.size(); i++) {\r
-                               if (isFirst) {\r
-                                       fileBuffer.append("  EFI_STATUS  Status;\r\n");\r
+            for (int i = 0; i < libInstanceList.size(); i++) {\r
+                if (isFirst) {\r
+                    fileBuffer.append("  EFI_STATUS  Status;\r\n");\r
                     fileBuffer.append("  Status = EFI_SUCCESS;\r\n");\r
-                                       fileBuffer.append("\r\n");\r
-                                       isFirst = false;\r
-                               }\r
-                               fileBuffer.append("  Status = ");\r
-                               fileBuffer.append(libInstanceList.get(i));\r
-                               fileBuffer.append("(ImageHandle, SystemTable);\r\n");\r
-                               fileBuffer.append("  ASSERT_EFI_ERROR (Status);\r\n");\r
-                       }\r
-                       fileBuffer.append("}\r\n");\r
-                       break;\r
-               }\r
-       }\r
-\r
-       /**\r
-        * ExternsDriverBindingToAutoGenC\r
-        *\r
-        * This function is to write DRIVER_BINDING, COMPONENT_NAME,\r
-        * DRIVER_CONFIGURATION, DRIVER_DIAGNOSTIC in AutoGen.c.\r
-        *\r
-        * @param fileBuffer\r
-        *            String buffer for AutoGen.c\r
-        */\r
-       void ExternsDriverBindingToAutoGenC(StringBuffer fileBuffer)\r
-                       throws BuildException {\r
-\r
-               //\r
-               // Check what <extern> contains. And the number of following elements\r
-               // under <extern> should be same. 1. DRIVER_BINDING 2. COMPONENT_NAME\r
-               // 3.DRIVER_CONFIGURATION 4. DRIVER_DIAGNOSTIC\r
-               //\r
-\r
-               String[] drvBindList = SurfaceAreaQuery.getDriverBindingArray();\r
-\r
-               //\r
-               // If component name protocol,component configuration protocol,\r
-               // component diagnostic protocol is not null or empty, check\r
-               // if every one have the same number of the driver binding protocol.\r
-               //\r
-               if (drvBindList == null || drvBindList.length == 0) {\r
-                       return;\r
-               }\r
-\r
-               String[] compNamList = SurfaceAreaQuery.getComponentNameArray();\r
-               String[] compConfList = SurfaceAreaQuery.getDriverConfigArray();\r
-               String[] compDiagList = SurfaceAreaQuery.getDriverDiagArray();\r
-\r
-               int BitMask = 0;\r
-\r
-               //\r
-               // Write driver binding protocol extern to autogen.c\r
-               //\r
-               for (int i = 0; i < drvBindList.length; i++) {\r
-                       fileBuffer.append("extern EFI_DRIVER_BINDING_PROTOCOL ");\r
-                       fileBuffer.append(drvBindList[i]);\r
-                       fileBuffer.append(";\r\n");\r
-               }\r
-\r
-               //\r
-               // Write component name protocol extern to autogen.c\r
-               //\r
-               if (compNamList != null && compNamList.length != 0) {\r
-                       if (drvBindList.length != compNamList.length) {\r
-                               throw new BuildException(\r
-                                               "Different number of Driver Binding and Component Name protocols!");\r
-                       }\r
-\r
-                       BitMask |= 0x01;\r
-                       for (int i = 0; i < compNamList.length; i++) {\r
-                               fileBuffer.append("extern EFI_COMPONENT_NAME_PROTOCOL ");\r
-                               fileBuffer.append(compNamList[i]);\r
-                               fileBuffer.append(";\r\n");\r
-                       }\r
-               }\r
-\r
-               //\r
-               // Write driver configration protocol extern to autogen.c\r
-               //\r
-               if (compConfList != null && compConfList.length != 0) {\r
-                       if (drvBindList.length != compConfList.length) {\r
-                               throw new BuildException(\r
-                                               "Different number of Driver Binding and Driver Configuration protocols!");\r
-                       }\r
-\r
-                       BitMask |= 0x02;\r
-                       for (int i = 0; i < compConfList.length; i++) {\r
-                               fileBuffer.append("extern EFI_DRIVER_CONFIGURATION_PROTOCOL ");\r
-                               fileBuffer.append(compConfList[i]);\r
-                               fileBuffer.append(";\r\n");\r
-                       }\r
-               }\r
-\r
-               //\r
-               // Write driver dignastic protocol extern to autogen.c\r
-               //\r
-               if (compDiagList != null && compDiagList.length != 0) {\r
-                       if (drvBindList.length != compDiagList.length) {\r
-                               throw new BuildException(\r
-                                               "Different number of Driver Binding and Driver Diagnosis protocols!");\r
-                       }\r
-\r
-                       BitMask |= 0x04;\r
-                       for (int i = 0; i < compDiagList.length; i++) {\r
-                               fileBuffer.append("extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL ");\r
-                               fileBuffer.append(compDiagList[i]);\r
-                               fileBuffer.append(";\r\n");\r
-                       }\r
-               }\r
-\r
-               //\r
-               // Write driver module protocol bitmask.\r
-               //\r
-               fileBuffer\r
-                               .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8  _gDriverModelProtocolBitmask = ");\r
-               fileBuffer.append(Integer.toString(BitMask));\r
-               fileBuffer.append(";\r\n");\r
-\r
-               //\r
-               // Write driver module protocol list entry\r
-               //\r
-               fileBuffer\r
-                               .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINTN  _gDriverModelProtocolListEntries = ");\r
-\r
-               fileBuffer.append(Integer.toString(drvBindList.length));\r
-               fileBuffer.append(";\r\n");\r
-\r
-               //\r
-               // Write drive module protocol list to autogen.c\r
-               //\r
-               fileBuffer\r
-                               .append("GLOBAL_REMOVE_IF_UNREFERENCED const EFI_DRIVER_MODEL_PROTOCOL_LIST  _gDriverModelProtocolList[] = {");\r
-               for (int i = 0; i < drvBindList.length; i++) {\r
-                       if (i != 0) {\r
-                               fileBuffer.append(",");\r
-                       }\r
-                       fileBuffer.append("\r\n {\r\n");\r
-                       fileBuffer.append("  &");\r
-                       fileBuffer.append(drvBindList[i]);\r
-                       fileBuffer.append(", \r\n");\r
-\r
-                       if (compNamList != null) {\r
-                               fileBuffer.append("  &");\r
-                               fileBuffer.append(compNamList[i]);\r
-                               fileBuffer.append(", \r\n");\r
-                       } else {\r
-                               fileBuffer.append("  NULL, \r\n");\r
-                       }\r
-\r
-                       if (compConfList != null) {\r
-                               fileBuffer.append("  &");\r
-                               fileBuffer.append(compConfList[i]);\r
-                               fileBuffer.append(", \r\n");\r
-                       } else {\r
-                               fileBuffer.append("  NULL, \r\n");\r
-                       }\r
-\r
-                       if (compDiagList != null) {\r
-                               fileBuffer.append("  &");\r
-                               fileBuffer.append(compDiagList[i]);\r
-                               fileBuffer.append(", \r\n");\r
-                       } else {\r
-                               fileBuffer.append("  NULL, \r\n");\r
-                       }\r
-                       fileBuffer.append("  }");\r
-               }\r
-               fileBuffer.append("\r\n};\r\n");\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 ExternCallBackToAutoGenC(StringBuffer fileBuffer)\r
-                       throws BuildException {\r
-               //\r
-               // Collect module's <SetVirtualAddressMapCallBack> and\r
-               // <ExitBootServiceCallBack> and add to setVirtualAddList\r
-               //  exitBootServiceList.\r
-               //\r
+                    fileBuffer.append("\r\n");\r
+                    isFirst = false;\r
+                }\r
+                fileBuffer.append("  Status = ");\r
+                fileBuffer.append(libInstanceList.get(i));\r
+                fileBuffer.append("(ImageHandle, SystemTable);\r\n");\r
+                fileBuffer.append("  ASSERT_EFI_ERROR (Status);\r\n");\r
+            }\r
+            fileBuffer.append("}\r\n");\r
+            break;\r
+        }\r
+    }\r
+\r
+    /**\r
+     * ExternsDriverBindingToAutoGenC\r
+     *\r
+     * This function is to write DRIVER_BINDING, COMPONENT_NAME,\r
+     * DRIVER_CONFIGURATION, DRIVER_DIAGNOSTIC in AutoGen.c.\r
+     *\r
+     * @param fileBuffer\r
+     *            String buffer for AutoGen.c\r
+     */\r
+    void ExternsDriverBindingToAutoGenC(StringBuffer fileBuffer)\r
+    throws BuildException {\r
+\r
+        //\r
+        // Check what <extern> contains. And the number of following elements\r
+        // under <extern> should be same. 1. DRIVER_BINDING 2. COMPONENT_NAME\r
+        // 3.DRIVER_CONFIGURATION 4. DRIVER_DIAGNOSTIC\r
+        //\r
+\r
+        String[] drvBindList = SurfaceAreaQuery.getDriverBindingArray();\r
+\r
+        //\r
+        // If component name protocol,component configuration protocol,\r
+        // component diagnostic protocol is not null or empty, check\r
+        // if every one have the same number of the driver binding protocol.\r
+        //\r
+        if (drvBindList == null || drvBindList.length == 0) {\r
+            return;\r
+        }\r
+\r
+        String[] compNamList = SurfaceAreaQuery.getComponentNameArray();\r
+        String[] compConfList = SurfaceAreaQuery.getDriverConfigArray();\r
+        String[] compDiagList = SurfaceAreaQuery.getDriverDiagArray();\r
+\r
+        int BitMask = 0;\r
+\r
+        //\r
+        // Write driver binding protocol extern to autogen.c\r
+        //\r
+        for (int i = 0; i < drvBindList.length; i++) {\r
+            fileBuffer.append("extern EFI_DRIVER_BINDING_PROTOCOL ");\r
+            fileBuffer.append(drvBindList[i]);\r
+            fileBuffer.append(";\r\n");\r
+        }\r
+\r
+        //\r
+        // Write component name protocol extern to autogen.c\r
+        //\r
+        if (compNamList != null && compNamList.length != 0) {\r
+            if (drvBindList.length != compNamList.length) {\r
+                throw new BuildException(\r
+                                        "Different number of Driver Binding and Component Name protocols!");\r
+            }\r
+\r
+            BitMask |= 0x01;\r
+            for (int i = 0; i < compNamList.length; i++) {\r
+                fileBuffer.append("extern EFI_COMPONENT_NAME_PROTOCOL ");\r
+                fileBuffer.append(compNamList[i]);\r
+                fileBuffer.append(";\r\n");\r
+            }\r
+        }\r
+\r
+        //\r
+        // Write driver configration protocol extern to autogen.c\r
+        //\r
+        if (compConfList != null && compConfList.length != 0) {\r
+            if (drvBindList.length != compConfList.length) {\r
+                throw new BuildException(\r
+                                        "Different number of Driver Binding and Driver Configuration protocols!");\r
+            }\r
+\r
+            BitMask |= 0x02;\r
+            for (int i = 0; i < compConfList.length; i++) {\r
+                fileBuffer.append("extern EFI_DRIVER_CONFIGURATION_PROTOCOL ");\r
+                fileBuffer.append(compConfList[i]);\r
+                fileBuffer.append(";\r\n");\r
+            }\r
+        }\r
+\r
+        //\r
+        // Write driver dignastic protocol extern to autogen.c\r
+        //\r
+        if (compDiagList != null && compDiagList.length != 0) {\r
+            if (drvBindList.length != compDiagList.length) {\r
+                throw new BuildException(\r
+                                        "Different number of Driver Binding and Driver Diagnosis protocols!");\r
+            }\r
+\r
+            BitMask |= 0x04;\r
+            for (int i = 0; i < compDiagList.length; i++) {\r
+                fileBuffer.append("extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL ");\r
+                fileBuffer.append(compDiagList[i]);\r
+                fileBuffer.append(";\r\n");\r
+            }\r
+        }\r
+\r
+        //\r
+        // Write driver module protocol bitmask.\r
+        //\r
+        fileBuffer\r
+        .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8  _gDriverModelProtocolBitmask = ");\r
+        fileBuffer.append(Integer.toString(BitMask));\r
+        fileBuffer.append(";\r\n");\r
+\r
+        //\r
+        // Write driver module protocol list entry\r
+        //\r
+        fileBuffer\r
+        .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINTN  _gDriverModelProtocolListEntries = ");\r
+\r
+        fileBuffer.append(Integer.toString(drvBindList.length));\r
+        fileBuffer.append(";\r\n");\r
+\r
+        //\r
+        // Write drive module protocol list to autogen.c\r
+        //\r
+        fileBuffer\r
+        .append("GLOBAL_REMOVE_IF_UNREFERENCED const EFI_DRIVER_MODEL_PROTOCOL_LIST  _gDriverModelProtocolList[] = {");\r
+        for (int i = 0; i < drvBindList.length; i++) {\r
+            if (i != 0) {\r
+                fileBuffer.append(",");\r
+            }\r
+            fileBuffer.append("\r\n {\r\n");\r
+            fileBuffer.append("  &");\r
+            fileBuffer.append(drvBindList[i]);\r
+            fileBuffer.append(", \r\n");\r
+\r
+            if (compNamList != null) {\r
+                fileBuffer.append("  &");\r
+                fileBuffer.append(compNamList[i]);\r
+                fileBuffer.append(", \r\n");\r
+            } else {\r
+                fileBuffer.append("  NULL, \r\n");\r
+            }\r
+\r
+            if (compConfList != null) {\r
+                fileBuffer.append("  &");\r
+                fileBuffer.append(compConfList[i]);\r
+                fileBuffer.append(", \r\n");\r
+            } else {\r
+                fileBuffer.append("  NULL, \r\n");\r
+            }\r
+\r
+            if (compDiagList != null) {\r
+                fileBuffer.append("  &");\r
+                fileBuffer.append(compDiagList[i]);\r
+                fileBuffer.append(", \r\n");\r
+            } else {\r
+                fileBuffer.append("  NULL, \r\n");\r
+            }\r
+            fileBuffer.append("  }");\r
+        }\r
+        fileBuffer.append("\r\n};\r\n");\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 ExternCallBackToAutoGenC(StringBuffer fileBuffer)\r
+    throws BuildException {\r
+        //\r
+        // Collect module's <SetVirtualAddressMapCallBack> and\r
+        // <ExitBootServiceCallBack> and add to setVirtualAddList\r
+        //  exitBootServiceList.\r
+        //\r
         String[] setVirtuals = SurfaceAreaQuery.getSetVirtualAddressMapCallBackArray();\r
         String[] exitBoots = SurfaceAreaQuery.getExitBootServicesCallBackArray();\r
         if (setVirtuals != null) {\r
             for (int j = 0; j < setVirtuals.length; j++) {\r
-                           this.setVirtalAddList.add(setVirtuals[j]);\r
-                       }\r
-               }\r
-               if (exitBoots != null) {\r
-                   for (int k = 0; k < exitBoots.length; k++) {\r
-                           this.exitBootServiceList.add(exitBoots[k]);\r
-                       }\r
-               }\r
-               //\r
-               //  Add c code in autogen.c which relate to <SetVirtualAddressMapCallBack>\r
-               //  and <ExitBootServicesCallBack>\r
-               //\r
-               String moduleType = this.moduleId.getModuleType();\r
-               boolean UefiOrDxeModule = false;\r
-               int Count = 0;\r
-               int i;\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
-                       // Entry point lib for these module types needs to know the count\r
-                       // of entryPoint.\r
-                       //\r
-                       UefiOrDxeModule = true;\r
-                       fileBuffer\r
-                                       .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED  const UINTN _gDriverSetVirtualAddressMapEventCount = ");\r
-\r
-                       //\r
-                       // If the list is not valid or has no entries set count to zero else\r
-                       // set count to the number of valid entries\r
-                       //\r
-                       Count = 0;\r
-                       if (this.setVirtalAddList != null) {\r
-                               for (i = 0; i < this.setVirtalAddList.size(); i++) {\r
-                                       if (this.setVirtalAddList.get(i).equalsIgnoreCase("")) {\r
-                                               break;\r
-                                       }\r
-                               }\r
-                               Count = i;\r
-                       }\r
-\r
-                       fileBuffer.append(Integer.toString(Count));\r
-                       fileBuffer.append(";\r\n\r\n");\r
-                       break;\r
-               default:\r
-                       break;\r
-               }\r
-\r
-               if (this.setVirtalAddList == null || this.setVirtalAddList.size() == 0) {\r
-                       if (UefiOrDxeModule) {\r
-                               //\r
-                               // No data so make a NULL list\r
-                               //\r
-                               fileBuffer\r
-                                               .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {\r\n");\r
-                               fileBuffer.append("  NULL\r\n");\r
-                               fileBuffer.append("};\r\n\r\n");\r
-                       }\r
-               } else {\r
-                       //\r
-                       // Write SetVirtualAddressMap function definition.\r
-                       //\r
-                       for (i = 0; i < this.setVirtalAddList.size(); i++) {\r
-                               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
-                       }\r
-\r
-                       //\r
-                       // Write SetVirtualAddressMap entry point array.\r
-                       //\r
-                       fileBuffer\r
-                                       .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {");\r
-                       for (i = 0; i < this.setVirtalAddList.size(); i++) {\r
-                               if (this.setVirtalAddList.get(i).equalsIgnoreCase("")) {\r
-                                       break;\r
-                               }\r
-\r
-                               if (i == 0) {\r
-                                       fileBuffer.append("\r\n  ");\r
-                               } else {\r
-                                       fileBuffer.append(",\r\n  ");\r
-                               }\r
-\r
-                               fileBuffer.append(this.setVirtalAddList.get(i));\r
-                       }\r
-                       //\r
-                       //  If module is not DXE_DRIVER, DXE_RUNTIME_DIRVER, UEFI_DRIVER\r
-                       //  UEFI_APPLICATION and DXE_SAL_DRIVER add the NULL at the end of\r
-                       //  _gDriverSetVirtualAddressMapEvent list.\r
-                       //\r
-                       if (!UefiOrDxeModule) {\r
-                               fileBuffer.append(",\r\n  NULL");\r
-                       }\r
-                       fileBuffer.append("\r\n};\r\n\r\n");\r
-               }\r
-\r
-               if (UefiOrDxeModule) {\r
-                       //\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
-\r
-                       //\r
-                       // If the list is not valid or has no entries set count to zero else\r
-                       // set count to the number of valid entries.\r
-                       //\r
-                       Count = 0;\r
-                       if (this.exitBootServiceList != null) {\r
-                               for (i = 0; i < this.exitBootServiceList.size(); i++) {\r
-                                       if (this.exitBootServiceList.get(i).equalsIgnoreCase("")) {\r
-                                               break;\r
-                                       }\r
-                               }\r
-                               Count = i;\r
-                       }\r
-                       fileBuffer.append(Integer.toString(Count));\r
-                       fileBuffer.append(";\r\n\r\n");\r
-               }\r
-\r
-               if (this.exitBootServiceList == null || this.exitBootServiceList.size() == 0) {\r
-                       if (UefiOrDxeModule) {\r
-                               //\r
-                               // No data so make a NULL list.\r
-                               //\r
-                               fileBuffer\r
-                                               .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {\r\n");\r
-                               fileBuffer.append("  NULL\r\n");\r
-                               fileBuffer.append("};\r\n\r\n");\r
-                       }\r
-               } else {\r
-                       //\r
-                       // Write DriverExitBootServices function definition.\r
-                       //\r
-                       for (i = 0; i < this.exitBootServiceList.size(); i++) {\r
-                               if (this.exitBootServiceList.get(i).equalsIgnoreCase("")) {\r
-                                       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
-                       }\r
-\r
-                       //\r
-                       // Write DriverExitBootServices entry point array.\r
-                       //\r
-                       fileBuffer\r
-                                       .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {");\r
-                       for (i = 0; i < this.exitBootServiceList.size(); i++) {\r
-                               if (this.exitBootServiceList.get(i).equalsIgnoreCase("")) {\r
-                                       break;\r
-                               }\r
-\r
-                               if (i == 0) {\r
-                                       fileBuffer.append("\r\n  ");\r
-                               } else {\r
-                                       fileBuffer.append(",\r\n  ");\r
-                               }\r
-                               fileBuffer.append(this.exitBootServiceList.get(i));\r
-                       }\r
-                       if (!UefiOrDxeModule) {\r
-                               fileBuffer.append(",\r\n  NULL");\r
-                       }\r
-                       fileBuffer.append("\r\n};\r\n\r\n");\r
-               }\r
-\r
-       }\r
+                this.setVirtalAddList.add(setVirtuals[j]);\r
+            }\r
+        }\r
+        if (exitBoots != null) {\r
+            for (int k = 0; k < exitBoots.length; k++) {\r
+                this.exitBootServiceList.add(exitBoots[k]);\r
+            }\r
+        }\r
+        //\r
+        //  Add c code in autogen.c which relate to <SetVirtualAddressMapCallBack>\r
+        //  and <ExitBootServicesCallBack>\r
+        //\r
+        String moduleType = this.moduleId.getModuleType();\r
+        boolean UefiOrDxeModule = false;\r
+        int Count = 0;\r
+        int i;\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
+            // Entry point lib for these module types needs to know the count\r
+            // of entryPoint.\r
+            //\r
+            UefiOrDxeModule = true;\r
+            fileBuffer\r
+            .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED  const UINTN _gDriverSetVirtualAddressMapEventCount = ");\r
+\r
+            //\r
+            // If the list is not valid or has no entries set count to zero else\r
+            // set count to the number of valid entries\r
+            //\r
+            Count = 0;\r
+            if (this.setVirtalAddList != null) {\r
+                for (i = 0; i < this.setVirtalAddList.size(); i++) {\r
+                    if (this.setVirtalAddList.get(i).equalsIgnoreCase("")) {\r
+                        break;\r
+                    }\r
+                }\r
+                Count = i;\r
+            }\r
+\r
+            fileBuffer.append(Integer.toString(Count));\r
+            fileBuffer.append(";\r\n\r\n");\r
+            break;\r
+        default:\r
+            break;\r
+        }\r
+\r
+        if (this.setVirtalAddList == null || this.setVirtalAddList.size() == 0) {\r
+            if (UefiOrDxeModule) {\r
+                //\r
+                // No data so make a NULL list\r
+                //\r
+                fileBuffer\r
+                .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {\r\n");\r
+                fileBuffer.append("  NULL\r\n");\r
+                fileBuffer.append("};\r\n\r\n");\r
+            }\r
+        } else {\r
+            //\r
+            // Write SetVirtualAddressMap function definition.\r
+            //\r
+            for (i = 0; i < this.setVirtalAddList.size(); i++) {\r
+                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
+            }\r
+\r
+            //\r
+            // Write SetVirtualAddressMap entry point array.\r
+            //\r
+            fileBuffer\r
+            .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {");\r
+            for (i = 0; i < this.setVirtalAddList.size(); i++) {\r
+                if (this.setVirtalAddList.get(i).equalsIgnoreCase("")) {\r
+                    break;\r
+                }\r
+\r
+                if (i == 0) {\r
+                    fileBuffer.append("\r\n  ");\r
+                } else {\r
+                    fileBuffer.append(",\r\n  ");\r
+                }\r
+\r
+                fileBuffer.append(this.setVirtalAddList.get(i));\r
+            }\r
+            //\r
+            //  If module is not DXE_DRIVER, DXE_RUNTIME_DIRVER, UEFI_DRIVER\r
+            //  UEFI_APPLICATION and DXE_SAL_DRIVER add the NULL at the end of\r
+            //  _gDriverSetVirtualAddressMapEvent list.\r
+            //\r
+            if (!UefiOrDxeModule) {\r
+                fileBuffer.append(",\r\n  NULL");\r
+            }\r
+            fileBuffer.append("\r\n};\r\n\r\n");\r
+        }\r
+\r
+        if (UefiOrDxeModule) {\r
+            //\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
+\r
+            //\r
+            // If the list is not valid or has no entries set count to zero else\r
+            // set count to the number of valid entries.\r
+            //\r
+            Count = 0;\r
+            if (this.exitBootServiceList != null) {\r
+                for (i = 0; i < this.exitBootServiceList.size(); i++) {\r
+                    if (this.exitBootServiceList.get(i).equalsIgnoreCase("")) {\r
+                        break;\r
+                    }\r
+                }\r
+                Count = i;\r
+            }\r
+            fileBuffer.append(Integer.toString(Count));\r
+            fileBuffer.append(";\r\n\r\n");\r
+        }\r
+\r
+        if (this.exitBootServiceList == null || this.exitBootServiceList.size() == 0) {\r
+            if (UefiOrDxeModule) {\r
+                //\r
+                // No data so make a NULL list.\r
+                //\r
+                fileBuffer\r
+                .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {\r\n");\r
+                fileBuffer.append("  NULL\r\n");\r
+                fileBuffer.append("};\r\n\r\n");\r
+            }\r
+        } else {\r
+            //\r
+            // Write DriverExitBootServices function definition.\r
+            //\r
+            for (i = 0; i < this.exitBootServiceList.size(); i++) {\r
+                if (this.exitBootServiceList.get(i).equalsIgnoreCase("")) {\r
+                    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
+            }\r
+\r
+            //\r
+            // Write DriverExitBootServices entry point array.\r
+            //\r
+            fileBuffer\r
+            .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {");\r
+            for (i = 0; i < this.exitBootServiceList.size(); i++) {\r
+                if (this.exitBootServiceList.get(i).equalsIgnoreCase("")) {\r
+                    break;\r
+                }\r
+\r
+                if (i == 0) {\r
+                    fileBuffer.append("\r\n  ");\r
+                } else {\r
+                    fileBuffer.append(",\r\n  ");\r
+                }\r
+                fileBuffer.append(this.exitBootServiceList.get(i));\r
+            }\r
+            if (!UefiOrDxeModule) {\r
+                fileBuffer.append(",\r\n  NULL");\r
+            }\r
+            fileBuffer.append("\r\n};\r\n\r\n");\r
+        }\r
+\r
+    }\r
 \r
     private void copyFlashMapHToDebugDir() throws  AutoGenException{\r
 \r
@@ -1972,12 +1985,12 @@ public class AutoGen {
         int size = (int)inFile.length();\r
         byte[] buffer = new byte[size];\r
         File outFile = new File (this.outputPath + File.separatorChar + CommonDefinition.tianoR8FlashMapH);\r
-               //\r
-               //  If TianoR8FlashMap.h existed and the flashMap.h don't change,\r
-               //  do nothing.\r
-               //\r
+        //\r
+        //  If TianoR8FlashMap.h existed and the flashMap.h don't change,\r
+        //  do nothing.\r
+        //\r
         if ((!outFile.exists()) ||(inFile.lastModified() - outFile.lastModified()) >= 0) {\r
-                   try{\r
+            try {\r
                 if (inFile.exists()) {\r
                     FileInputStream fis = new FileInputStream (inFile);\r
                     fis.read(buffer);\r
@@ -1985,13 +1998,13 @@ public class AutoGen {
                     fos.write(buffer);\r
                     fis.close();\r
                     fos.close();\r
-                }else {\r
+                } else {\r
                     throw new AutoGenException("The file, flashMap.h doesn't exist!");\r
                 }\r
-            } catch (Exception e){\r
+            } catch (Exception e) {\r
                 throw new AutoGenException(e.getMessage());\r
             }\r
-               }\r
+        }\r
     }\r
 \r
     /**\r
@@ -2000,137 +2013,137 @@ public class AutoGen {
     *SetVirtalAddressMapCallBack, ExitBootServiceCallBack, and\r
     *Destructor, Constructor.\r
     *\r
-       **/\r
-       private void collectLibInstanceInfo(){\r
-               int index;\r
-\r
-               String moduleType = SurfaceAreaQuery.getModuleType();\r
-               String libConstructName = null;\r
-               String libDestructName = null;\r
-               String[] setVirtuals = null;\r
-               String[] exitBoots = null;\r
-\r
-               ModuleIdentification[] libraryIdList = SurfaceAreaQuery\r
-                               .getLibraryInstance(this.arch);\r
-               try {\r
-                       if (libraryIdList != null) {\r
-                               //\r
-                               // Reorder library instance sequence.\r
-                               //\r
-                               AutogenLibOrder libOrder = new AutogenLibOrder(libraryIdList,\r
-                                               this.arch);\r
-                               List<ModuleIdentification> orderList = libOrder\r
-                                               .orderLibInstance();\r
-\r
-                               if (orderList != null) {\r
-                                       //\r
-                                       // Process library instance one by one.\r
-                                       //\r
-                                       for (int i = 0; i < orderList.size(); i++) {\r
-\r
-                                               //\r
-                                               // Get library instance basename.\r
-                                               //\r
-                                               ModuleIdentification libInstanceId = orderList.get(i);\r
-\r
-                                               //\r
-                                               // Get override map\r
-                                               //\r
-\r
-                                               Map<String, XmlObject> libDoc = GlobalData.getDoc(\r
-                                                               libInstanceId, this.arch);\r
-                                               SurfaceAreaQuery.push(libDoc);\r
-                                               //\r
-                                               // Get <PPis>, <Protocols>, <Guids> list of this library\r
-                                               // instance.\r
-                                               //\r
-                                               String[] ppiList = SurfaceAreaQuery.getPpiArray(this.arch);\r
-                                               String[] ppiNotifyList = SurfaceAreaQuery\r
-                                                               .getPpiNotifyArray(this.arch);\r
-                                               String[] protocolList = SurfaceAreaQuery\r
-                                                               .getProtocolArray(this.arch);\r
-                                               String[] protocolNotifyList = SurfaceAreaQuery\r
-                                                               .getProtocolNotifyArray(this.arch);\r
-                                               String[] guidList = SurfaceAreaQuery\r
-                                                               .getGuidEntryArray(this.arch);\r
-                                               PackageIdentification[] pkgList = SurfaceAreaQuery.getDependencePkg(this.arch);\r
-\r
-                                               //\r
-                                               // Add those ppi, protocol, guid in global ppi,\r
-                                               // protocol, guid\r
-                                               // list.\r
-                                               //\r
-                                               for (index = 0; index < ppiList.length; index++) {\r
-                                                       this.mPpiList.add(ppiList[index]);\r
-                                               }\r
-\r
-                                               for (index = 0; index < ppiNotifyList.length; index++) {\r
-                                                       this.mPpiList.add(ppiNotifyList[index]);\r
-                                               }\r
-\r
-                                               for (index = 0; index < protocolList.length; index++) {\r
-                                                       this.mProtocolList.add(protocolList[index]);\r
-                                               }\r
-\r
-                                               for (index = 0; index < protocolNotifyList.length; index++) {\r
-                                                       this.mProtocolList.add(protocolNotifyList[index]);\r
-                                               }\r
-\r
-                                               for (index = 0; index < guidList.length; index++) {\r
-                                                       this.mGuidList.add(guidList[index]);\r
-                                               }\r
-                                               for (index = 0; index < pkgList.length; index++){\r
-                                                       if (!this.mDepPkgList.contains(pkgList[index])){\r
-                                                               this.mDepPkgList.add(pkgList[index]);\r
-                                                       }\r
-                                               }\r
-\r
-                                               //\r
-                                               // If not yet parse this library instance's constructor\r
-                                               // element,parse it.\r
-                                               //\r
-                                               libConstructName = SurfaceAreaQuery\r
-                                                               .getLibConstructorName();\r
-                                               libDestructName = SurfaceAreaQuery\r
-                                                               .getLibDestructorName();\r
-\r
-                                               //\r
-                                               // Collect SetVirtualAddressMapCallBack and\r
-                                               // ExitBootServiceCallBack.\r
-                                               //\r
+    **/\r
+    private void collectLibInstanceInfo(){\r
+        int index;\r
+\r
+        String moduleType = SurfaceAreaQuery.getModuleType();\r
+        String libConstructName = null;\r
+        String libDestructName = null;\r
+        String[] setVirtuals = null;\r
+        String[] exitBoots = null;\r
+\r
+        ModuleIdentification[] libraryIdList = SurfaceAreaQuery\r
+                                               .getLibraryInstance(this.arch);\r
+        try {\r
+            if (libraryIdList != null) {\r
+                //\r
+                // Reorder library instance sequence.\r
+                //\r
+                AutogenLibOrder libOrder = new AutogenLibOrder(libraryIdList,\r
+                                                               this.arch);\r
+                List<ModuleIdentification> orderList = libOrder\r
+                                                       .orderLibInstance();\r
+\r
+                if (orderList != null) {\r
+                    //\r
+                    // Process library instance one by one.\r
+                    //\r
+                    for (int i = 0; i < orderList.size(); i++) {\r
+\r
+                        //\r
+                        // Get library instance basename.\r
+                        //\r
+                        ModuleIdentification libInstanceId = orderList.get(i);\r
+\r
+                        //\r
+                        // Get override map\r
+                        //\r
+\r
+                        Map<String, XmlObject> libDoc = GlobalData.getDoc(\r
+                                                                         libInstanceId, this.arch);\r
+                        SurfaceAreaQuery.push(libDoc);\r
+                        //\r
+                        // Get <PPis>, <Protocols>, <Guids> list of this library\r
+                        // instance.\r
+                        //\r
+                        String[] ppiList = SurfaceAreaQuery.getPpiArray(this.arch);\r
+                        String[] ppiNotifyList = SurfaceAreaQuery\r
+                                                 .getPpiNotifyArray(this.arch);\r
+                        String[] protocolList = SurfaceAreaQuery\r
+                                                .getProtocolArray(this.arch);\r
+                        String[] protocolNotifyList = SurfaceAreaQuery\r
+                                                      .getProtocolNotifyArray(this.arch);\r
+                        String[] guidList = SurfaceAreaQuery\r
+                                            .getGuidEntryArray(this.arch);\r
+                        PackageIdentification[] pkgList = SurfaceAreaQuery.getDependencePkg(this.arch);\r
+\r
+                        //\r
+                        // Add those ppi, protocol, guid in global ppi,\r
+                        // protocol, guid\r
+                        // list.\r
+                        //\r
+                        for (index = 0; index < ppiList.length; index++) {\r
+                            this.mPpiList.add(ppiList[index]);\r
+                        }\r
+\r
+                        for (index = 0; index < ppiNotifyList.length; index++) {\r
+                            this.mPpiList.add(ppiNotifyList[index]);\r
+                        }\r
+\r
+                        for (index = 0; index < protocolList.length; index++) {\r
+                            this.mProtocolList.add(protocolList[index]);\r
+                        }\r
+\r
+                        for (index = 0; index < protocolNotifyList.length; index++) {\r
+                            this.mProtocolList.add(protocolNotifyList[index]);\r
+                        }\r
+\r
+                        for (index = 0; index < guidList.length; index++) {\r
+                            this.mGuidList.add(guidList[index]);\r
+                        }\r
+                        for (index = 0; index < pkgList.length; index++) {\r
+                            if (!this.mDepPkgList.contains(pkgList[index])) {\r
+                                this.mDepPkgList.add(pkgList[index]);\r
+                            }\r
+                        }\r
+\r
+                        //\r
+                        // If not yet parse this library instance's constructor\r
+                        // element,parse it.\r
+                        //\r
+                        libConstructName = SurfaceAreaQuery\r
+                                           .getLibConstructorName();\r
+                        libDestructName = SurfaceAreaQuery\r
+                                          .getLibDestructorName();\r
+\r
+                        //\r
+                        // Collect SetVirtualAddressMapCallBack and\r
+                        // ExitBootServiceCallBack.\r
+                        //\r
                         setVirtuals = SurfaceAreaQuery.getSetVirtualAddressMapCallBackArray();\r
                         exitBoots = SurfaceAreaQuery.getExitBootServicesCallBackArray();\r
                         if (setVirtuals != null) {\r
                             for (int j = 0; j < setVirtuals.length; j++) {\r
-                                                           this.setVirtalAddList.add(setVirtuals[j]);\r
-                                                   }\r
-                                               }\r
-                                               if (exitBoots != null) {\r
-                                                       for (int k = 0; k < exitBoots.length; k++) {\r
-                                                           this.exitBootServiceList.add(exitBoots[k]);\r
-                                                   }\r
-                                               }\r
-                                               SurfaceAreaQuery.pop();\r
-                                               //\r
-                                               // Add dependent library instance constructor function.\r
-                                               //\r
-                                               if (libConstructName != null) {\r
-                                                       this.libConstructList.add(libConstructName);\r
-                                               }\r
-                                               //\r
-                                               // Add dependent library instance destructor fuction.\r
-                                               //\r
-                                               if (libDestructName != null) {\r
-                                                       this.libDestructList.add(libDestructName);\r
-                                               }\r
-                                       }\r
-                               }\r
-\r
-                       }\r
-\r
-       }catch (Exception e){\r
-       System.out.println(e.getMessage());\r
-       System.out.println("Collect library instance failed!");\r
-}\r
-}\r
+                                this.setVirtalAddList.add(setVirtuals[j]);\r
+                            }\r
+                        }\r
+                        if (exitBoots != null) {\r
+                            for (int k = 0; k < exitBoots.length; k++) {\r
+                                this.exitBootServiceList.add(exitBoots[k]);\r
+                            }\r
+                        }\r
+                        SurfaceAreaQuery.pop();\r
+                        //\r
+                        // Add dependent library instance constructor function.\r
+                        //\r
+                        if (libConstructName != null) {\r
+                            this.libConstructList.add(libConstructName);\r
+                        }\r
+                        //\r
+                        // Add dependent library instance destructor fuction.\r
+                        //\r
+                        if (libDestructName != null) {\r
+                            this.libDestructList.add(libDestructName);\r
+                        }\r
+                    }\r
+                }\r
+\r
+            }\r
+\r
+        } catch (Exception e) {\r
+            System.out.println(e.getMessage());\r
+            System.out.println("Collect library instance failed!");\r
+        }\r
+    }\r
 }\r
index fe3b460..335ff8f 100644 (file)
@@ -34,15 +34,15 @@ public class CommonDefinition {
     public final static String autoGenHbegin = "extern int __make_me_compile_correctly;\r\n";\r
     public final static String include = "#include";\r
     public final static String autoGenCLine1 = "\r\n";\r
-    \r
+\r
     public final static String autoGenCLine2 = "const UINT8  _gDebugPropertyMask "\r
-                    + "= DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED"\r
-                    + "  | DEBUG_PROPERTY_DEBUG_PRINT_ENABLED"\r
-                    + "  | DEBUG_PROPERTY_DEBUG_CODE_ENABLED;\r\n";\r
+                                               + "= DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED"\r
+                                               + "  | DEBUG_PROPERTY_DEBUG_PRINT_ENABLED"\r
+                                               + "  | DEBUG_PROPERTY_DEBUG_CODE_ENABLED;\r\n";\r
 \r
     public final static String autoGenCLine3 = "const UINTN  _gModuleDefaultErrorLevel"\r
-                    + " = EFI_D_ERROR | EFI_D_LOAD;\r\n";\r
-    \r
+                                               + " = EFI_D_ERROR | EFI_D_LOAD;\r\n";\r
+\r
     public final static String autoGenHLine1          = "#define EFI_SPECIFICATION_VERSION    0x00020000\r\n";\r
     public final static String autoGenHVersionDefault = "#define EFI_SPECIFICATION_VERSION    0x00000000\r\n";\r
     public final static String autoGenHLine2          = "#define EDK_RELEASE_VERSION        0x00090000\r\n";\r
@@ -56,32 +56,41 @@ public class CommonDefinition {
     public final static String ppiGuid = "PpiGuid";\r
     public final static String guidGuid = "Guid";\r
 \r
-       public final static String tianoR8FlashMapH = "TianoR8FlashMap.h";\r
-       public final static String flashMapH = "FlashMap.h";\r
-    \r
+    public final static String tianoR8FlashMapH = "TianoR8FlashMap.h";\r
+    public final static String flashMapH = "FlashMap.h";\r
+\r
+    //\r
+    // The defintions for identifying current module\r
+    // is PEI Pcd driver or Dxe Pcd driver.\r
+    // \r
+    public static enum   PCD_DRIVER_TYPE { NOT_PCD_DRIVER,\r
+        PEI_PCD_DRIVER, \r
+        DXE_PCD_DRIVER,\r
+        UNKNOWN_PCD_DRIVER};\r
+\r
     //\r
     // AutoGen.h and AutoGen.c file's header\r
     //\r
     public final static String autogenHNotation = \r
-      "/**\r\n" +\r
-      "  DO NOT EDIT\r\n" +\r
-      "  FILE auto-generated by GenBuild tasks\r\n" +\r
-      "  Module name:\r\n" +\r
-      "       AutoGen.h\r\n" +\r
-      "  Abstract:" +\r
-      "       Auto-generated AutoGen.h for building module or library.\r\n" +\r
-      "**/\r\n\r\n";\r
-        \r
+    "/**\r\n" +\r
+    "  DO NOT EDIT\r\n" +\r
+    "  FILE auto-generated by GenBuild tasks\r\n" +\r
+    "  Module name:\r\n" +\r
+    "       AutoGen.h\r\n" +\r
+    "  Abstract:" +\r
+    "       Auto-generated AutoGen.h for building module or library.\r\n" +\r
+    "**/\r\n\r\n";\r
+\r
     public final static String autogenCNotation = \r
-        "/**\r\n" +\r
-        "  DO NOT EDIT\r\n" +\r
-        "  FILE auto-generated by GenBuild tasks\r\n" +\r
-        "  Module name:\r\n" +\r
-        "       AutoGen.c\r\n" +\r
-        "  Abstract:" +\r
-        "       Auto-generated AutoGen.c for building module or library.\r\n" +\r
-        "**/\r\n\r\n";\r
-    \r
+    "/**\r\n" +\r
+    "  DO NOT EDIT\r\n" +\r
+    "  FILE auto-generated by GenBuild tasks\r\n" +\r
+    "  Module name:\r\n" +\r
+    "       AutoGen.c\r\n" +\r
+    "  Abstract:" +\r
+    "       Auto-generated AutoGen.c for building module or library.\r\n" +\r
+    "**/\r\n\r\n";\r
+\r
     //\r
     // module type\r
     //\r
@@ -97,8 +106,8 @@ public class CommonDefinition {
     public final static int ModuleTypeUefiDriver = 9;\r
     public final static int ModuleTypeUefiApplication = 10;\r
     public final static int ModuleTypeUnknown = 11;\r
-    \r
-   \r
+\r
+\r
     //\r
     // component type\r
     //                           \r
@@ -123,13 +132,13 @@ public class CommonDefinition {
     public final static int  ComponentTypeCustomBuild = 18;\r
     public final static int  ComponentTypeUnknown = 19;\r
 \r
-    \r
+\r
     //\r
     // Usaged style\r
     //\r
     public final static String AlwaysConsumed = "ALWAYS_CONSUMED";\r
     public final static String AlwaysProduced = "ALWAYS_PRODUCED";\r
-  \r
+\r
 \r
     public static class MyEnum {\r
         String moduleTypeStr;\r
@@ -147,47 +156,47 @@ public class CommonDefinition {
                 return -1;\r
         }\r
     }\r
-    \r
+\r
     //\r
     // Module type\r
     //\r
     public static final MyEnum[] moduleEnum = new MyEnum[] {\r
-                    new MyEnum("BASE", ModuleTypeBase),\r
-                    new MyEnum("SEC", ModuleTypeSec),\r
-                    new MyEnum("PEI_CORE", ModuleTypePeiCore),\r
-                    new MyEnum("PEIM", ModuleTypePeim),\r
-                    new MyEnum("DXE_CORE", ModuleTypeDxeCore),\r
-                    new MyEnum("DXE_DRIVER", ModuleTypeDxeDriver),\r
-                    new MyEnum("DXE_RUNTIME_DRIVER", ModuleTypeDxeRuntimeDriver),\r
-                    new MyEnum("DXE_SAL_DRIVER", ModuleTypeDxeSalDriver),\r
-                    new MyEnum("DXE_SMM_DRIVER", ModuleTypeDxeSmmDriver),\r
-                    new MyEnum("UEFI_DRIVER", ModuleTypeUefiDriver),\r
-                    new MyEnum("UEFI_APPLICATION", ModuleTypeUefiApplication) };\r
-    \r
+        new MyEnum("BASE", ModuleTypeBase),\r
+        new MyEnum("SEC", ModuleTypeSec),\r
+        new MyEnum("PEI_CORE", ModuleTypePeiCore),\r
+        new MyEnum("PEIM", ModuleTypePeim),\r
+        new MyEnum("DXE_CORE", ModuleTypeDxeCore),\r
+        new MyEnum("DXE_DRIVER", ModuleTypeDxeDriver),\r
+        new MyEnum("DXE_RUNTIME_DRIVER", ModuleTypeDxeRuntimeDriver),\r
+        new MyEnum("DXE_SAL_DRIVER", ModuleTypeDxeSalDriver),\r
+        new MyEnum("DXE_SMM_DRIVER", ModuleTypeDxeSmmDriver),\r
+        new MyEnum("UEFI_DRIVER", ModuleTypeUefiDriver),\r
+        new MyEnum("UEFI_APPLICATION", ModuleTypeUefiApplication)};\r
+\r
     //\r
     // Component type\r
     //\r
     public static final MyEnum[] componentEnum = new MyEnum[]{\r
-                    new MyEnum("APRIORI", ComponentTypeApriori),\r
-                    new MyEnum("SEC", ComponentTypeSec),\r
-                    new MyEnum("LIBRARY", ComponentTypeLibrary),\r
-                    new MyEnum("FV_IMAGE_FILE", ComponentTypeFvImageFile),\r
-                    new MyEnum("BS_DRIVER", ComponentTypeBsDriver),\r
-                    new MyEnum("RT_DRIVER", ComponentTypeRtDriver),\r
-                    new MyEnum("SAL_RT_DRIVER", ComponentTypeSalRtDriver),\r
-                    new MyEnum("PE32_PEIM", ComponentTypePe32Peim),\r
-                    new MyEnum("PIC_PEIM", ComponentTypePicPeim),\r
-                    new MyEnum("COMBINED_PEIM_DRIVER", ComponentTypeCombinedPeimDriver),\r
-                    new MyEnum("PEI_CORE", ComponentTypePeiCore),\r
-                    new MyEnum("DXE_CORE", ComponentTypeDxeCore),\r
-                    new MyEnum("APPLICATION", ComponentTypeApplication),\r
-                    new MyEnum("BS_DRIVER_EFI", ComponentTypeBsDriverEfi),\r
-                    new MyEnum("SHELLAPP", ComponentTypeShellApp),\r
-                    new MyEnum("BINARY", ComponentTypeBinary),\r
-                    new MyEnum("LOGO", ComponentTypeLogo),\r
-                    new MyEnum("CUSTOM_BUILD", ComponentTypeCustomBuild)\r
-                    };\r
-   \r
+        new MyEnum("APRIORI", ComponentTypeApriori),\r
+        new MyEnum("SEC", ComponentTypeSec),\r
+        new MyEnum("LIBRARY", ComponentTypeLibrary),\r
+        new MyEnum("FV_IMAGE_FILE", ComponentTypeFvImageFile),\r
+        new MyEnum("BS_DRIVER", ComponentTypeBsDriver),\r
+        new MyEnum("RT_DRIVER", ComponentTypeRtDriver),\r
+        new MyEnum("SAL_RT_DRIVER", ComponentTypeSalRtDriver),\r
+        new MyEnum("PE32_PEIM", ComponentTypePe32Peim),\r
+        new MyEnum("PIC_PEIM", ComponentTypePicPeim),\r
+        new MyEnum("COMBINED_PEIM_DRIVER", ComponentTypeCombinedPeimDriver),\r
+        new MyEnum("PEI_CORE", ComponentTypePeiCore),\r
+        new MyEnum("DXE_CORE", ComponentTypeDxeCore),\r
+        new MyEnum("APPLICATION", ComponentTypeApplication),\r
+        new MyEnum("BS_DRIVER_EFI", ComponentTypeBsDriverEfi),\r
+        new MyEnum("SHELLAPP", ComponentTypeShellApp),\r
+        new MyEnum("BINARY", ComponentTypeBinary),\r
+        new MyEnum("LOGO", ComponentTypeLogo),\r
+        new MyEnum("CUSTOM_BUILD", ComponentTypeCustomBuild)\r
+    };\r
+\r
     /**\r
       getModuleType\r
       \r
@@ -234,18 +243,18 @@ public class CommonDefinition {
     \r
     @param    componentType  Integer value of component type.\r
     @return\r
-  **/\r
+    **/\r
     static public String getComponentTypeString (int componentType) {\r
-      if ((componentType > CommonDefinition.ComponentTypeUnknown) || \r
-          (componentType < CommonDefinition.ComponentTypeNull)) {\r
-        return null;\r
-      }\r
-      for (int index = 0; index < CommonDefinition.componentEnum.length; index ++) {\r
-        if (componentType == CommonDefinition.componentEnum[index].type) {\r
-          return CommonDefinition.componentEnum[index].moduleTypeStr;\r
+        if ((componentType > CommonDefinition.ComponentTypeUnknown) || \r
+            (componentType < CommonDefinition.ComponentTypeNull)) {\r
+            return null;\r
+        }\r
+        for (int index = 0; index < CommonDefinition.componentEnum.length; index ++) {\r
+            if (componentType == CommonDefinition.componentEnum[index].type) {\r
+                return CommonDefinition.componentEnum[index].moduleTypeStr;\r
+            }\r
         }\r
-      }\r
-      return null;\r
+        return null;\r
     }\r
 \r
     /**\r
@@ -258,12 +267,12 @@ public class CommonDefinition {
       @return\r
     **/\r
     static public boolean isLibraryComponent (int componentType) {\r
-      if (ComponentTypeLibrary == componentType) {\r
-        return true;\r
-      }\r
-      return false;\r
+        if (ComponentTypeLibrary == componentType) {\r
+            return true;\r
+        }\r
+        return false;\r
     }\r
-    \r
+\r
     /**\r
      * formateGuidName\r
      * \r
@@ -278,7 +287,7 @@ public class CommonDefinition {
         String guid = "";\r
         int index = 0;\r
         if (guidNameConv\r
-                .matches("[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}")) {\r
+            .matches("[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}")) {\r
             strList = guidNameConv.split("-");\r
             guid = "0x" + strList[0] + ", ";\r
             guid = guid + "0x" + strList[1] + ", ";\r
@@ -295,7 +304,7 @@ public class CommonDefinition {
             guid = guid + "}";\r
             return guid;\r
         } else if (guidNameConv\r
-                .matches("0x[a-fA-F0-9]{1,8},( )*0x[a-fA-F0-9]{1,4},( )*0x[a-fA-F0-9]{1,4}(,( )*\\{)?(,?( )*0x[a-fA-F0-9]{1,2}){8}( )*(\\})?")) {\r
+                   .matches("0x[a-fA-F0-9]{1,8},( )*0x[a-fA-F0-9]{1,4},( )*0x[a-fA-F0-9]{1,4}(,( )*\\{)?(,?( )*0x[a-fA-F0-9]{1,2}){8}( )*(\\})?")) {\r
             strList = guidNameConv.split(",");\r
 \r
             //\r
@@ -317,12 +326,12 @@ public class CommonDefinition {
             return guid;\r
         } else {\r
             System.out\r
-                    .println("Check GUID Value, It doesn't conform to the registry format specified in the schema!!!");\r
+            .println("Check GUID Value, It doesn't conform to the registry format specified in the schema!!!");\r
             return "0";\r
 \r
         }\r
     }\r
-    \r
+\r
     /**\r
      * Remove deuplicat string in list\r
      * \r
@@ -335,20 +344,20 @@ public class CommonDefinition {
     public static String[] remDupString (String[] orgList){\r
         Set<String> strList = new LinkedHashSet<String>();\r
         String[] desList ;\r
-        if (orgList == null){\r
+        if (orgList == null) {\r
             return new String[0];\r
         }\r
-        for (int i = 0; i < orgList.length; i++){\r
+        for (int i = 0; i < orgList.length; i++) {\r
             strList.add(orgList[i]);\r
         }\r
         desList = new String[strList.size()];\r
         Iterator item = strList.iterator();\r
         int index = 0;\r
-        while (item.hasNext()){\r
+        while (item.hasNext()) {\r
             desList[index] = (String)item.next();\r
             index++;\r
         }\r
         return desList;\r
     }\r
-    \r
+\r
 }\r
index 93727db..4b5e1ff 100644 (file)
@@ -60,6 +60,7 @@ import org.tianocore.FilenameDocument.Filename;
 import org.tianocore.MsaHeaderDocument.MsaHeader;\r
 import org.tianocore.ProtocolsDocument.Protocols.Protocol;\r
 import org.tianocore.ProtocolsDocument.Protocols.ProtocolNotify;\r
+import org.tianocore.PcdDriverTypes;\r
 \r
 import org.tianocore.common.logger.EdkLog;\r
 import org.tianocore.build.id.FpdModuleIdentification;\r
@@ -67,6 +68,7 @@ import org.tianocore.build.id.ModuleIdentification;
 import org.tianocore.build.id.PackageIdentification;\r
 import org.tianocore.build.id.PlatformIdentification;\r
 import org.tianocore.build.toolchain.ToolChainInfo;\r
+import org.tianocore.build.autogen.CommonDefinition;\r
 \r
 /**\r
  * SurfaceAreaQuery class is used to query Surface Area information from msa,\r
@@ -1275,6 +1277,30 @@ public class SurfaceAreaQuery {
         return getCNames("Externs", xPath);\r
     }\r
 \r
+    /**\r
+      Judge whether current driver is PEI_PCD_DRIVER or DXE_PCD_DRIVER or\r
+      NOT_PCD_DRIVER.\r
+      \r
+      @return CommonDefinition.PCD_DRIVER_TYPE  the type of current driver\r
+    **/\r
+    public static CommonDefinition.PCD_DRIVER_TYPE getPcdDriverType() {\r
+        String[] xPath   = new String[] {"/PcdIsDriver"};\r
+        Object[] results = get ("Externs", xPath);\r
+\r
+        if (results != null && results.length != 0) {\r
+            PcdDriverTypes type     = (PcdDriverTypes) results[0];\r
+            String         typeStr  = type.enumValue().toString();\r
+            if (typeStr.equals(CommonDefinition.PCD_DRIVER_TYPE.PEI_PCD_DRIVER.toString())) {\r
+                return CommonDefinition.PCD_DRIVER_TYPE.PEI_PCD_DRIVER;\r
+            } else if (typeStr.equals(CommonDefinition.PCD_DRIVER_TYPE.DXE_PCD_DRIVER.toString())) {\r
+                return CommonDefinition.PCD_DRIVER_TYPE.DXE_PCD_DRIVER;\r
+            }\r
+            return CommonDefinition.PCD_DRIVER_TYPE.UNKNOWN_PCD_DRIVER;\r
+        }\r
+\r
+        return CommonDefinition.PCD_DRIVER_TYPE.NOT_PCD_DRIVER;\r
+    }\r
+\r
     /**\r
      * Retrieve module surface area file information\r
      *\r
index 5c7b29a..6d71629 100644 (file)
@@ -22,16 +22,17 @@ import java.util.List;
 import java.util.regex.Matcher;\r
 import java.util.regex.Pattern;\r
 \r
+import org.tianocore.build.autogen.CommonDefinition;\r
+import org.tianocore.build.exception.PcdAutogenException;\r
 import org.tianocore.build.global.GlobalData;\r
 import org.tianocore.build.id.ModuleIdentification;\r
+import org.tianocore.pcd.action.ActionMessage;\r
+import org.tianocore.pcd.action.BuildAction;\r
 import org.tianocore.pcd.entity.MemoryDatabaseManager;\r
 import org.tianocore.pcd.entity.Token;\r
+import org.tianocore.pcd.entity.UsageIdentification;\r
 import org.tianocore.pcd.entity.UsageInstance;\r
 import org.tianocore.pcd.exception.BuildActionException;\r
-import org.tianocore.pcd.entity.UsageIdentification;\r
-import org.tianocore.pcd.action.BuildAction;\r
-import org.tianocore.pcd.action.ActionMessage;\r
-import org.tianocore.build.exception.PcdAutogenException;\r
 \r
 /** This class is to manage how to generate the PCD information into Autogen.c and\r
     Autogen.h.\r
@@ -52,6 +53,11 @@ public class PCDAutoGenAction extends BuildAction {
     ///\r
     private boolean               isBuildUsedLibrary;\r
 \r
+    ///\r
+    /// One of PEI_PCD_DRIVER, DXE_PCD_DRIVER, NOT_PCD_DRIVER \r
+    /// \r
+    private CommonDefinition.PCD_DRIVER_TYPE pcdDriverType;\r
+\r
     ///\r
     /// The generated string for header file.\r
     ///\r
@@ -76,6 +82,14 @@ public class PCDAutoGenAction extends BuildAction {
         this.usageId = usageId;\r
     }\r
 \r
+    /**\r
+       Set paramter pcdDriverType\r
+       \r
+       @param pcdDriverType the driver type for PCD\r
+    **/\r
+    public void setPcdDriverType(CommonDefinition.PCD_DRIVER_TYPE pcdDriverType) {\r
+        this.pcdDriverType = pcdDriverType;\r
+    }\r
     /**\r
        set isBuildUsedLibrary parameter.\r
 \r
@@ -122,11 +136,14 @@ public class PCDAutoGenAction extends BuildAction {
         @param arch                 the architecture for module\r
         @param isBuildUsedLibary    Is the current module library.\r
         @param pcdNameArrayInMsa    the pcd name array got from MSA file.\r
+        @param pcdDriverType        one of PEI_PCD_DRIVER, DXE_PCD_DRIVER,\r
+                                    NOT_PCD_DRIVER\r
     **/\r
     public PCDAutoGenAction(ModuleIdentification moduleId,\r
                             String               arch,\r
                             boolean              isBuildUsedLibrary,\r
-                            String[]             pcdNameArrayInMsa) {\r
+                            String[]             pcdNameArrayInMsa,\r
+                            CommonDefinition.PCD_DRIVER_TYPE pcdDriverType) {\r
         dbManager       = null;\r
         hAutoGenString  = "";\r
         cAutoGenString  = "";\r
@@ -140,6 +157,7 @@ public class PCDAutoGenAction extends BuildAction {
                                            moduleId.getModuleType()));\r
         setIsBuildUsedLibrary(isBuildUsedLibrary);\r
         setPcdNameArrayInMsa(pcdNameArrayInMsa);\r
+        setPcdDriverType(pcdDriverType);\r
     }\r
 \r
     /**\r
@@ -303,10 +321,10 @@ public class PCDAutoGenAction extends BuildAction {
         // Work around code, In furture following code should be modified that get\r
         // these information from Uplevel Autogen tools.\r
         //\r
-        if (moduleName.equalsIgnoreCase("PcdPeim")) {\r
+        if (pcdDriverType == CommonDefinition.PCD_DRIVER_TYPE.PEI_PCD_DRIVER) {\r
             hAutoGenString += MemoryDatabaseManager.PcdPeimHString;\r
             cAutoGenString += MemoryDatabaseManager.PcdPeimCString;\r
-        } else if (moduleName.equalsIgnoreCase("PcdDxe")) {\r
+        } else if (pcdDriverType == CommonDefinition.PCD_DRIVER_TYPE.DXE_PCD_DRIVER) {\r
             hAutoGenString += MemoryDatabaseManager.PcdDxeHString;\r
             cAutoGenString += MemoryDatabaseManager.PcdDxeCString;\r
         }\r