]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/AutoGen/GenC.py
Sync BaseTool trunk (version r2423) into EDKII BaseTools. The change mainly includes:
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / GenC.py
index 3c256c8b74c83a3d0f4070aa9370378bfa7918f9..5638bfd043c41067b8827d565be46ae778868cb0 100644 (file)
@@ -1,7 +1,7 @@
 ## @file
 # Routines for generating AutoGen.h and AutoGen.c
 #
-# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>
 # This program and the accompanying materials
 # are licensed and made available under the terms and conditions of the BSD License
 # which accompanies this distribution.  The full text of the license may be found at
@@ -67,21 +67,21 @@ typedef UINT8 SKU_ID;
 
 #define PCD_TYPE_SHIFT        28
 
-#define PCD_TYPE_DATA         (0x0 << PCD_TYPE_SHIFT)
-#define PCD_TYPE_HII          (0x8 << PCD_TYPE_SHIFT)
-#define PCD_TYPE_VPD          (0x4 << PCD_TYPE_SHIFT)
-#define PCD_TYPE_SKU_ENABLED  (0x2 << PCD_TYPE_SHIFT)
-#define PCD_TYPE_STRING       (0x1 << PCD_TYPE_SHIFT)
+#define PCD_TYPE_DATA         (0x0U << PCD_TYPE_SHIFT)
+#define PCD_TYPE_HII          (0x8U << PCD_TYPE_SHIFT)
+#define PCD_TYPE_VPD          (0x4U << PCD_TYPE_SHIFT)
+#define PCD_TYPE_SKU_ENABLED  (0x2U << PCD_TYPE_SHIFT)
+#define PCD_TYPE_STRING       (0x1U << PCD_TYPE_SHIFT)
 
 #define PCD_TYPE_ALL_SET      (PCD_TYPE_DATA | PCD_TYPE_HII | PCD_TYPE_VPD | PCD_TYPE_SKU_ENABLED | PCD_TYPE_STRING)
 
 #define PCD_DATUM_TYPE_SHIFT  24
 
-#define PCD_DATUM_TYPE_POINTER  (0x0 << PCD_DATUM_TYPE_SHIFT)
-#define PCD_DATUM_TYPE_UINT8    (0x1 << PCD_DATUM_TYPE_SHIFT)
-#define PCD_DATUM_TYPE_UINT16   (0x2 << PCD_DATUM_TYPE_SHIFT)
-#define PCD_DATUM_TYPE_UINT32   (0x4 << PCD_DATUM_TYPE_SHIFT)
-#define PCD_DATUM_TYPE_UINT64   (0x8 << PCD_DATUM_TYPE_SHIFT)
+#define PCD_DATUM_TYPE_POINTER  (0x0U << PCD_DATUM_TYPE_SHIFT)
+#define PCD_DATUM_TYPE_UINT8    (0x1U << PCD_DATUM_TYPE_SHIFT)
+#define PCD_DATUM_TYPE_UINT16   (0x2U << PCD_DATUM_TYPE_SHIFT)
+#define PCD_DATUM_TYPE_UINT32   (0x4U << PCD_DATUM_TYPE_SHIFT)
+#define PCD_DATUM_TYPE_UINT64   (0x8U << PCD_DATUM_TYPE_SHIFT)
 
 #define PCD_DATUM_TYPE_ALL_SET  (PCD_DATUM_TYPE_POINTER | \\
                                  PCD_DATUM_TYPE_UINT8   | \\
@@ -312,7 +312,19 @@ gAutoGenHPrologueString = TemplateString("""
 
 """)
 
+gAutoGenHCppPrologueString = """
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+"""
+
 gAutoGenHEpilogueString = """
+
+#ifdef __cplusplus
+}
+#endif
+
 #endif
 """
 
@@ -917,7 +929,7 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
                             "No generated token number for %s.%s\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName),
                             ExtraData="[%s]" % str(Info))
         TokenNumber = PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName]
-    AutoGenH.Append('\n#define %s  %d\n' % (PcdTokenName, TokenNumber))
+    AutoGenH.Append('\n#define %s  %dU\n' % (PcdTokenName, TokenNumber))
 
     EdkLogger.debug(EdkLogger.DEBUG_3, "Creating code for " + Pcd.TokenCName + "." + Pcd.TokenSpaceGuidCName)
     if Pcd.Type not in gItemTypeStringDatabase:
@@ -956,6 +968,14 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
         Value = Pcd.DefaultValue
         Unicode = False
         ValueNumber = 0
+
+        if Pcd.DatumType == 'BOOLEAN':
+            BoolValue = Value.upper()
+            if BoolValue == 'TRUE':
+                Value = '1U'
+            elif BoolValue == 'FALSE':
+                Value = '0U'
+
         if Pcd.DatumType in ['UINT64', 'UINT32', 'UINT16', 'UINT8']:
             try:
                 if Value.upper().startswith('0X'):
@@ -986,6 +1006,8 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
                     EdkLogger.error("build", AUTOGEN_ERROR,
                                     "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),
                                     ExtraData="[%s]" % str(Info))
+                if not Value.endswith('U'):
+                    Value += 'U'
             elif Pcd.DatumType == 'UINT16':
                 if ValueNumber < 0:
                     EdkLogger.error("build", AUTOGEN_ERROR,
@@ -995,6 +1017,8 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
                     EdkLogger.error("build", AUTOGEN_ERROR,
                                     "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),
                                     ExtraData="[%s]" % str(Info))
+                if not Value.endswith('U'):
+                    Value += 'U'                    
             elif Pcd.DatumType == 'UINT8':
                 if ValueNumber < 0:
                     EdkLogger.error("build", AUTOGEN_ERROR,
@@ -1004,6 +1028,8 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
                     EdkLogger.error("build", AUTOGEN_ERROR,
                                     "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),
                                     ExtraData="[%s]" % str(Info))
+                if not Value.endswith('U'):
+                    Value += 'U'
         if Pcd.DatumType == 'VOID*':
             if Pcd.MaxDatumSize == None or Pcd.MaxDatumSize == '':
                 EdkLogger.error("build", AUTOGEN_ERROR,
@@ -1098,6 +1124,10 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):
                         ExtraData="[%s]" % str(Info))
     TokenNumber = PcdTokenNumber[TokenCName, TokenSpaceGuidCName]
 
+    # If PCD is DynamicEx, then use TokenNumber declared in DEC file
+    if Pcd.Type in gDynamicExPcd:
+        TokenNumber = int(Pcd.TokenValue, 0)
+
     if Pcd.Type not in gItemTypeStringDatabase:
         EdkLogger.error("build", AUTOGEN_ERROR,
                         "Unknown PCD type [%s] of PCD %s.%s" % (Pcd.Type, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),
@@ -1119,7 +1149,7 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):
         Type = '(VOID *)'
         Array = '[]'
 
-    AutoGenH.Append('#define _PCD_TOKEN_%s  %d\n' % (TokenCName, TokenNumber))
+    AutoGenH.Append('#define _PCD_TOKEN_%s  %dU\n' % (TokenCName, TokenNumber))
 
     PcdItemType = Pcd.Type
     #if PcdItemType in gDynamicPcd:
@@ -1393,6 +1423,8 @@ def CreatePcdDatabasePhaseSpecificAutoGen (Platform, Phase):
                 #
                 if Pcd.DatumType == "UINT64":
                     ValueList.append(Sku.DefaultValue + "ULL")
+                elif Pcd.DatumType in ("UINT32", "UINT16", "UINT8"):
+                    ValueList.append(Sku.DefaultValue + "U")
                 else:
                     ValueList.append(Sku.DefaultValue)
 
@@ -1677,11 +1709,11 @@ def CreateModuleEntryPointCode(Info, AutoGenC, AutoGenH):
     if 'PI_SPECIFICATION_VERSION' in Info.Module.Specification:
         PiSpecVersion = Info.Module.Specification['PI_SPECIFICATION_VERSION']
     else:
-        PiSpecVersion = 0
+        PiSpecVersion = '0x00000000'
     if 'UEFI_SPECIFICATION_VERSION' in Info.Module.Specification:
         UefiSpecVersion = Info.Module.Specification['UEFI_SPECIFICATION_VERSION']
     else:
-        UefiSpecVersion = 0
+        UefiSpecVersion = '0x00000000'
     Dict = {
         'Function'       :   Info.Module.ModuleEntryPointList,
         'PiSpecVersion'  :   PiSpecVersion,
@@ -1689,14 +1721,15 @@ def CreateModuleEntryPointCode(Info, AutoGenC, AutoGenH):
     }
 
     if Info.ModuleType in ['PEI_CORE', 'DXE_CORE', 'SMM_CORE']:
-        if NumEntryPoints != 1:
-            EdkLogger.error(
-                "build",
-                AUTOGEN_ERROR,
-                '%s must have exactly one entry point' % Info.ModuleType,
-                File=str(Info),
-                ExtraData= ", ".join(Info.Module.ModuleEntryPointList)
-                )
+        if Info.SourceFileList <> None and Info.SourceFileList <> []:
+          if NumEntryPoints != 1:
+              EdkLogger.error(
+                  "build",
+                  AUTOGEN_ERROR,
+                  '%s must have exactly one entry point' % Info.ModuleType,
+                  File=str(Info),
+                  ExtraData= ", ".join(Info.Module.ModuleEntryPointList)
+                  )
     if Info.ModuleType == 'PEI_CORE':
         AutoGenC.Append(gPeiCoreEntryPointString.Replace(Dict))
         AutoGenH.Append(gPeiCoreEntryPointPrototype.Replace(Dict))
@@ -1827,6 +1860,23 @@ def CreatePpiDefinitionCode(Info, AutoGenC, AutoGenH):
 #   @param      AutoGenH    The TemplateString object for header file
 #
 def CreatePcdCode(Info, AutoGenC, AutoGenH):
+
+    # Collect Token Space GUIDs used by DynamicEc PCDs
+    TokenSpaceList = []
+    for Pcd in Info.ModulePcdList:
+       if Pcd.Type in gDynamicExPcd and Pcd.TokenSpaceGuidCName not in TokenSpaceList:
+            TokenSpaceList += [Pcd.TokenSpaceGuidCName]
+            
+    # Add extern declarations to AutoGen.h if one or more Token Space GUIDs were found
+    if TokenSpaceList <> []:            
+        AutoGenH.Append("\n// Definition of PCD Token Space GUIDs used in this module\n\n")
+        if Info.ModuleType in ["USER_DEFINED", "BASE"]:
+            GuidType = "GUID"
+        else:
+            GuidType = "EFI_GUID"              
+        for Item in TokenSpaceList:
+            AutoGenH.Append('extern %s %s;\n' % (GuidType, Item))
+
     if Info.IsLibrary:
         if Info.ModulePcdList:
             AutoGenH.Append("\n// PCD definitions\n")
@@ -1923,12 +1973,20 @@ def CreateHeaderCode(Info, AutoGenC, AutoGenH):
     AutoGenH.Append(gAutoGenHeaderString.Replace({'FileName':'AutoGen.h'}))
     # header file Prologue
     AutoGenH.Append(gAutoGenHPrologueString.Replace({'File':'AUTOGENH','Guid':Info.Guid.replace('-','_')}))
+    AutoGenH.Append(gAutoGenHCppPrologueString)
     if Info.AutoGenVersion >= 0x00010005:
         # header files includes
         AutoGenH.Append("#include <%s>\n" % gBasicHeaderFile)
         if Info.ModuleType in gModuleTypeHeaderFile \
            and gModuleTypeHeaderFile[Info.ModuleType][0] != gBasicHeaderFile:
             AutoGenH.Append("#include <%s>\n" % gModuleTypeHeaderFile[Info.ModuleType][0])
+        #
+        # if either PcdLib in [LibraryClasses] sections or there exist Pcd section, add PcdLib.h 
+        # As if modules only uses FixedPcd, then PcdLib is not needed in [LibraryClasses] section.
+        #
+        if 'PcdLib' in Info.Module.LibraryClasses or Info.Module.Pcds:
+            AutoGenH.Append("#include <Library/PcdLib.h>\n")
+
         AutoGenH.Append('\nextern GUID  gEfiCallerIdGuid;\n\n')
 
         if Info.IsLibrary:
@@ -1993,7 +2051,7 @@ def CreateCode(Info, AutoGenC, AutoGenH, StringH, UniGenCFlag, UniGenBinBuffer):
 
     CreateFooterCode(Info, AutoGenC, AutoGenH)
 
-    # no generation of AutoGen.c for R8 modules without unicode file
+    # no generation of AutoGen.c for Edk modules without unicode file
     if Info.AutoGenVersion < 0x00010005 and len(Info.UnicodeFileList) == 0:
         AutoGenC.String = ''