]> git.proxmox.com Git - mirror_edk2.git/commitdiff
1) correct the assert condition for LibPcdSetPtr and LibPcdSetExPtr
authorqwang12 <qwang12@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 26 Jun 2006 13:41:23 +0000 (13:41 +0000)
committerqwang12 <qwang12@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 26 Jun 2006 13:41:23 +0000 (13:41 +0000)
2) make sure VOID* type dynamic PCD entry can handle ASCII string correctly.
3) correct one bug where if StringTable is empty the autogen.c won't compile.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@630 6f19259b-4bc3-4df7-8a09-765794883524

MdePkg/Library/BasePcdLibNull/PcdLib.c
MdePkg/Library/DxePcdLib/DxePcdLib.c
MdePkg/Library/PeiPcdLib/PeiPcdLib.c
Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java
Tools/Source/GenBuild/org/tianocore/build/pcd/entity/Token.java

index 832100758fc1516f9917ebd61941517ded1b7908..de90c2f90edc0eab30f4167ef0b2066d7393c080 100644 (file)
@@ -461,7 +461,9 @@ LibPcdSetPtr (
   IN      VOID              *Buffer\r
   )\r
 {\r
   IN      VOID              *Buffer\r
   )\r
 {\r
-  ASSERT (Buffer != NULL);\r
+  if (*SizeOfBuffer > 0) {\r
+    ASSERT (Buffer != NULL);\r
+  }\r
 \r
   return Buffer;\r
 }\r
 \r
   return Buffer;\r
 }\r
@@ -630,7 +632,10 @@ LibPcdSetExPtr (
   )\r
 {\r
   ASSERT (Guid != NULL);\r
   )\r
 {\r
   ASSERT (Guid != NULL);\r
-  ASSERT (Buffer != NULL);\r
+\r
+  if (*SizeOfBuffer > 0) {\r
+    ASSERT (Buffer != NULL);\r
+  }\r
 \r
   return Buffer;\r
 }\r
 \r
   return Buffer;\r
 }\r
index fe7ae4247c9045334e3ffc984526fbb4be2170ea..ec5da259a640014a17123750b5ca020bfcb09f13 100644 (file)
@@ -513,8 +513,10 @@ LibPcdSetPtr (
 {\r
   EFI_STATUS Status;\r
   UINTN      Size;\r
 {\r
   EFI_STATUS Status;\r
   UINTN      Size;\r
-  \r
-  ASSERT ((*SizeOfBuffer > 0) && Buffer == NULL);\r
+\r
+  if (*SizeOfBuffer > 0) {\r
+    ASSERT (Buffer != NULL);\r
+  }\r
 \r
   Size = LibPcdGetSize (TokenNumber);\r
   \r
 \r
   Size = LibPcdGetSize (TokenNumber);\r
   \r
@@ -726,8 +728,9 @@ LibPcdSetExPtr (
   EFI_STATUS  Status;\r
   UINTN       Size;\r
 \r
   EFI_STATUS  Status;\r
   UINTN       Size;\r
 \r
-  ASSERT (Guid != NULL);\r
-  ASSERT (Buffer != NULL);\r
+  if (*SizeOfBuffer > 0) {\r
+    ASSERT (Buffer != NULL);\r
+  }\r
 \r
   Size = LibPcdGetExSize (Guid, TokenNumber);\r
   if (*SizeOfBuffer > Size) {\r
 \r
   Size = LibPcdGetExSize (Guid, TokenNumber);\r
   if (*SizeOfBuffer > Size) {\r
index a73d804797836441a2df70cb6906f4956fe846df..4018e44f702b45514164bbbeb195bcf6dc5711f8 100644 (file)
@@ -586,10 +586,12 @@ LibPcdSetPtr (
   PCD_PPI    *PcdPpi;\r
   UINTN      Size;\r
 \r
   PCD_PPI    *PcdPpi;\r
   UINTN      Size;\r
 \r
+  if (*SizeOfBuffer > 0) {\r
+    ASSERT (Buffer != NULL);\r
+  }\r
+\r
   PcdPpi = GetPcdPpiPtr ();\r
   \r
   PcdPpi = GetPcdPpiPtr ();\r
   \r
-  ASSERT ((*SizeOfBuffer > 0) && Buffer == NULL);\r
-\r
   Size = LibPcdGetSize (TokenNumber);\r
   \r
   if (*SizeOfBuffer > Size) {\r
   Size = LibPcdGetSize (TokenNumber);\r
   \r
   if (*SizeOfBuffer > Size) {\r
@@ -813,6 +815,10 @@ LibPcdSetExPtr (
   PCD_PPI         *PcdPpi;\r
   UINTN           Size;\r
 \r
   PCD_PPI         *PcdPpi;\r
   UINTN           Size;\r
 \r
+  if (*SizeOfBuffer > 0) {\r
+    ASSERT (Buffer != NULL);\r
+  }\r
+\r
   PcdPpi = GetPcdPpiPtr ();\r
 \r
   Size = LibPcdGetExSize (Guid, TokenNumber);\r
   PcdPpi = GetPcdPpiPtr ();\r
 \r
   Size = LibPcdGetExSize (Guid, TokenNumber);\r
index f6ea239b3830ef5a189c0116e6b90d22b88f8a0b..40a462c3d0c3e85564e03a6e7769fb4d732a1838 100644 (file)
@@ -107,7 +107,7 @@ class StringTable {
         // If we have a empty StringTable\r
         //\r
         if (al.size() == 0) {\r
         // If we have a empty StringTable\r
         //\r
         if (al.size() == 0) {\r
-            cDeclCode += tab + String.format("UINT16             %s[1]; /* StringTable is Empty */", stringTable) + newLine; \r
+            cDeclCode += String.format("%-20s%s[1]; /* StringTable is empty */", "UINT16", stringTable) + newLine; \r
             decl = new CStructTypeDeclaration (\r
                                                 stringTable,\r
                                                 2,\r
             decl = new CStructTypeDeclaration (\r
                                                 stringTable,\r
                                                 2,\r
@@ -116,7 +116,7 @@ class StringTable {
                                         );  \r
             declaList.add(decl);\r
 \r
                                         );  \r
             declaList.add(decl);\r
 \r
-            cInstCode = " { 0 } " + String.format("/* %s */", stringTable);\r
+            cInstCode = String.format("/* %s */", stringTable) + newLine + tab + "{ 0 }";\r
             instTable.put(stringTable, cInstCode);\r
         } else {\r
 \r
             instTable.put(stringTable, cInstCode);\r
         } else {\r
 \r
@@ -137,7 +137,7 @@ class StringTable {
                     stringTableName = String.format("%s_%d", stringTable, i);\r
                     cDeclCode += tab;\r
                 }\r
                     stringTableName = String.format("%s_%d", stringTable, i);\r
                     cDeclCode += tab;\r
                 }\r
-                cDeclCode += String.format("UINT16              %s[%d]; /* %s */", stringTableName, str.length() + 1, alComments.get(i)) + newLine;\r
+                cDeclCode += String.format("%-20s%s[%d]; /* %s */", "UINT16", stringTableName, str.length() + 1, alComments.get(i)) + newLine;\r
                 \r
                 if (i == 0) {\r
                     cInstCode = "/* StringTable */" + newLine;\r
                 \r
                 if (i == 0) {\r
                     cInstCode = "/* StringTable */" + newLine;\r
@@ -295,7 +295,7 @@ class SizeTable {
         Output.add("/* SizeTable */");\r
         Output.add("{");\r
         if (al.size() == 0) {\r
         Output.add("/* SizeTable */");\r
         Output.add("{");\r
         if (al.size() == 0) {\r
-            Output.add("0");\r
+            Output.add("\t0");\r
         } else {\r
             for (int index = 0; index < al.size(); index++) {\r
                 Integer n = al.get(index);\r
         } else {\r
             for (int index = 0; index < al.size(); index++) {\r
                 Integer n = al.get(index);\r
@@ -387,7 +387,7 @@ class GuidTable {
 \r
         guidStrArray =(uuid.toString()).split("-");\r
 \r
 \r
         guidStrArray =(uuid.toString()).split("-");\r
 \r
-        return String.format("{ 0x%s, 0x%s, 0x%s, { 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s } }",\r
+        return String.format("{0x%s, 0x%s, 0x%s, {0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s}}",\r
                                          guidStrArray[0],\r
                                          guidStrArray[1],\r
                                          guidStrArray[2],\r
                                          guidStrArray[0],\r
                                          guidStrArray[1],\r
                                          guidStrArray[2],\r
@@ -408,7 +408,7 @@ class GuidTable {
         Output.add("/* GuidTable */");\r
         Output.add("{");\r
         if (al.size() == 0) {\r
         Output.add("/* GuidTable */");\r
         Output.add("{");\r
         if (al.size() == 0) {\r
-            Output.add(getUuidCString(new UUID(0, 0)));\r
+            Output.add("\t" + getUuidCString(new UUID(0, 0)));\r
         }\r
         \r
         for (int i = 0; i < al.size(); i++) {\r
         }\r
         \r
         for (int i = 0; i < al.size(); i++) {\r
@@ -505,7 +505,7 @@ class SkuIdTable {
             decl = new CStructTypeDeclaration (\r
                                                 "SystemSkuId",\r
                                                 1,\r
             decl = new CStructTypeDeclaration (\r
                                                 "SystemSkuId",\r
                                                 1,\r
-                                                "SKU_ID          SystemSkuId;\r\n",\r
+                                                String.format("%-20sSystemSkuId;\r\n", "SKU_ID"),\r
                                                 true\r
                                               );\r
             declaList.add(decl);\r
                                                 true\r
                                               );\r
             declaList.add(decl);\r
@@ -662,7 +662,7 @@ class LocalTokenNumberTable {
         output.add("{");\r
 \r
         if (al.size() == 0) {\r
         output.add("{");\r
 \r
         if (al.size() == 0) {\r
-            output.add("0");\r
+            output.add("\t0");\r
         }\r
         \r
         for (int index = 0; index < al.size(); index++) {\r
         }\r
         \r
         for (int index = 0; index < al.size(); index++) {\r
@@ -864,12 +864,12 @@ class PcdDatabase {
     private final String        newLine                         = "\r\n";\r
     private final String        commaNewLine                    = ",\r\n";\r
     private final String        tab                             = "\t";\r
     private final String        newLine                         = "\r\n";\r
     private final String        commaNewLine                    = ",\r\n";\r
     private final String        tab                             = "\t";\r
-    public final static String ExMapTableDeclaration            = "DYNAMICEX_MAPPING ExMapTable[%s_EXMAPPING_TABLE_SIZE];\r\n";\r
-    public final static String GuidTableDeclaration             = "EFI_GUID          GuidTable[%s_GUID_TABLE_SIZE];\r\n";\r
-    public final static String LocalTokenNumberTableDeclaration = "UINT32            LocalTokenNumberTable[%s_LOCAL_TOKEN_NUMBER_TABLE_SIZE];\r\n";\r
-    public final static String StringTableDeclaration           = "UINT16            StringTable[%s_STRING_TABLE_SIZE];\r\n";\r
-    public final static String SizeTableDeclaration             = "UINT16            SizeTable[%s_LOCAL_TOKEN_NUMBER_TABLE_SIZE];\r\n";\r
-    public final static String SkuIdTableDeclaration            = "UINT8             SkuIdTable[%s_SKUID_TABLE_SIZE];\r\n";\r
+    public final static String ExMapTableDeclaration            = "DYNAMICEX_MAPPING   ExMapTable[%s_EXMAPPING_TABLE_SIZE];\r\n";\r
+    public final static String GuidTableDeclaration             = "EFI_GUID            GuidTable[%s_GUID_TABLE_SIZE];\r\n";\r
+    public final static String LocalTokenNumberTableDeclaration = "UINT32              LocalTokenNumberTable[%s_LOCAL_TOKEN_NUMBER_TABLE_SIZE];\r\n";\r
+    public final static String StringTableDeclaration           = "UINT16              StringTable[%s_STRING_TABLE_SIZE];\r\n";\r
+    public final static String SizeTableDeclaration             = "UINT16              SizeTable[%s_LOCAL_TOKEN_NUMBER_TABLE_SIZE];\r\n";\r
+    public final static String SkuIdTableDeclaration            = "UINT8               SkuIdTable[%s_SKUID_TABLE_SIZE];\r\n";\r
 \r
 \r
     public final static String ExMapTableSizeMacro              = "#define %s_EXMAPPING_TABLE_SIZE  %d\r\n";\r
 \r
 \r
     public final static String ExMapTableSizeMacro              = "#define %s_EXMAPPING_TABLE_SIZE  %d\r\n";\r
@@ -1206,7 +1206,8 @@ class PcdDatabase {
                 //\r
                 // We made a assumption that both PEI_PCD_DATABASE and DXE_PCD_DATABASE\r
                 // has a least one data memember with alignment size of 1. So we can\r
                 //\r
                 // We made a assumption that both PEI_PCD_DATABASE and DXE_PCD_DATABASE\r
                 // has a least one data memember with alignment size of 1. So we can\r
-                // remove the last "," in the C structure instantiation string.\r
+                // remove the last "," in the C structure instantiation string. Luckily,\r
+                // this is true as both data structure has SKUID_TABLE anyway.\r
                 //\r
                 if ((align == 1) && (i == declaListBasedOnAlignment.size() - 1)) {\r
                     initInstStr += newLine;\r
                 //\r
                 if ((align == 1) && (i == declaListBasedOnAlignment.size() - 1)) {\r
                     initInstStr += newLine;\r
@@ -1228,7 +1229,7 @@ class PcdDatabase {
         }\r
         \r
         if (uinitDatabaseEmpty) {\r
         }\r
         \r
         if (uinitDatabaseEmpty) {\r
-            uninitDeclStr += tab + "   UINT8        dummy; /* PCD_DATABASE_UNINIT is emptry */\r\n";\r
+            uninitDeclStr += tab + String.format("%-20sdummy; /* PCD_DATABASE_UNINIT is emptry */\r\n", "UINT8");\r
         }\r
         \r
         initDeclStr += String.format("} %s_PCD_DATABASE_INIT;", phase) + newLine + newLine;\r
         }\r
         \r
         initDeclStr += String.format("} %s_PCD_DATABASE_INIT;", phase) + newLine + newLine;\r
@@ -1475,7 +1476,7 @@ class PcdDatabase {
     }\r
 \r
     private String getSkuEnabledTypeDeclaration (Token token) {\r
     }\r
 \r
     private String getSkuEnabledTypeDeclaration (Token token) {\r
-        return String.format("SKU_HEAD %s;\r\n", token.getPrimaryKeyString());\r
+        return String.format("%-20s%s;\r\n", "SKU_HEAD", token.getPrimaryKeyString());\r
     }\r
 \r
     private String getSkuEnabledTypeInstantiaion (Token token, int SkuTableIdx) {\r
     }\r
 \r
     private String getSkuEnabledTypeInstantiaion (Token token, int SkuTableIdx) {\r
@@ -1581,20 +1582,29 @@ class PcdDatabase {
         }\r
 \r
         if (t.isUnicodeStringType()) {\r
         }\r
 \r
         if (t.isUnicodeStringType()) {\r
-            privateGlobalCCode = String.format("STRING_HEAD              %s[%d];\r\n", t.getPrimaryKeyString(), t.getSkuIdCount());\r
+            privateGlobalCCode = String.format("%-20s%s[%d];\r\n", "STRING_HEAD", t.getPrimaryKeyString(), t.getSkuIdCount());\r
         } else {\r
             String type = getCType(t);\r
             if (t.datumType == Token.DATUM_TYPE.POINTER) {\r
         } else {\r
             String type = getCType(t);\r
             if (t.datumType == Token.DATUM_TYPE.POINTER) {\r
-                privateGlobalCCode = String.format("%s              %s[%d][%d];\r\n", type, privateGlobalName, t.getSkuIdCount(), t.datumSize);\r
+                int bufferSize;\r
+                if (t.isASCIIStringType()) {\r
+                    //\r
+                    // Build tool will add a NULL string at the end of the ASCII string\r
+                    //\r
+                    bufferSize = t.datumSize + 1;\r
+                } else {\r
+                    bufferSize = t.datumSize;\r
+                }\r
+                privateGlobalCCode = String.format("%-20s%s[%d][%d];\r\n", type, privateGlobalName, t.getSkuIdCount(), bufferSize);\r
             } else {\r
             } else {\r
-                privateGlobalCCode = String.format("%s              %s[%d];\r\n", type, privateGlobalName, t.getSkuIdCount());\r
+                privateGlobalCCode = String.format("%-20s%s[%d];\r\n", type, privateGlobalName, t.getSkuIdCount());\r
             }\r
         }\r
     }\r
     \r
     private String getDataTypeDeclarationForVariableDefault_new (Token token, String cName, int skuId) {\r
 \r
             }\r
         }\r
     }\r
     \r
     private String getDataTypeDeclarationForVariableDefault_new (Token token, String cName, int skuId) {\r
 \r
-        String typeStr = "";\r
+        String typeStr;\r
 \r
         if (token.datumType == Token.DATUM_TYPE.UINT8) {\r
             typeStr = "UINT8";\r
 \r
         if (token.datumType == Token.DATUM_TYPE.UINT8) {\r
             typeStr = "UINT8";\r
@@ -1607,11 +1617,12 @@ class PcdDatabase {
         } else if (token.datumType == Token.DATUM_TYPE.BOOLEAN) {\r
             typeStr = "BOOLEAN";\r
         } else if (token.datumType == Token.DATUM_TYPE.POINTER) {\r
         } else if (token.datumType == Token.DATUM_TYPE.BOOLEAN) {\r
             typeStr = "BOOLEAN";\r
         } else if (token.datumType == Token.DATUM_TYPE.POINTER) {\r
-            return String.format("UINT8 %s[%d]", cName, token.datumSize);\r
+            return String.format("%-20s%s[%d];\r\n", cName, token.datumSize);\r
         } else {\r
         } else {\r
+            typeStr = "";\r
         }\r
 \r
         }\r
 \r
-        return String.format("%s             %s;\r\n", typeStr, cName);\r
+        return String.format("%-20s%s;\r\n", typeStr, cName);\r
     }\r
     \r
     private String getDataTypeDeclaration (Token token) {\r
     }\r
     \r
     private String getDataTypeDeclaration (Token token) {\r
index 46a90cb02497d0ecb639884a4986fae8d519d194..edcbd80aa2aeed8597163a22faf41f6a94e15e74 100644 (file)
@@ -708,6 +708,22 @@ public class Token {
         return false;\r
     }\r
     \r
         return false;\r
     }\r
     \r
+    public boolean isASCIIStringType () {\r
+        String str = getDynamicDefaultValue();\r
+\r
+        if (str == null) {\r
+            return false;\r
+        }\r
+\r
+        if (datumType == Token.DATUM_TYPE.POINTER &&\r
+            str.startsWith("\"") && \r
+            str.endsWith("\"")) {\r
+            return true;\r
+        }\r
+\r
+        return false;\r
+    }\r
+\r
     public boolean isByteStreamType () {\r
         String str = getDynamicDefaultValue();\r
 \r
     public boolean isByteStreamType () {\r
         String str = getDynamicDefaultValue();\r
 \r