]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/SetupBrowserDxe/IfrParse.c
Update the HiiConfigToBlock to follow spec.
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / IfrParse.c
index 50ae87d92e668ba0a8f8a029d3734639dfb8b481..7221c42fa3110db8d7c69c4b1ad2394c42a00620 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Parser for IFR binary encoding.\r
 \r
-Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -18,13 +18,6 @@ UINT16           mStatementIndex;
 UINT16           mExpressionOpCodeIndex;\r
 \r
 BOOLEAN          mInScopeSubtitle;\r
-BOOLEAN          mInScopeSuppress;\r
-BOOLEAN          mInScopeGrayOut;\r
-BOOLEAN          mInScopeDisable;\r
-FORM_EXPRESSION  *mSuppressExpression;\r
-FORM_EXPRESSION  *mGrayOutExpression;\r
-FORM_EXPRESSION  *mDisableExpression;\r
-\r
 /**\r
   Initialize Statement header members.\r
 \r
@@ -44,6 +37,7 @@ CreateStatement (
 {\r
   FORM_BROWSER_STATEMENT    *Statement;\r
   EFI_IFR_STATEMENT_HEADER  *StatementHdr;\r
+  INTN                      ConditionalExprCount; \r
 \r
   if (Form == NULL) {\r
     //\r
@@ -68,17 +62,18 @@ CreateStatement (
   CopyMem (&Statement->Prompt, &StatementHdr->Prompt, sizeof (EFI_STRING_ID));\r
   CopyMem (&Statement->Help, &StatementHdr->Help, sizeof (EFI_STRING_ID));\r
 \r
-  if (mInScopeSuppress) {\r
-    Statement->SuppressExpression = mSuppressExpression;\r
-  }\r
-\r
-  if (mInScopeGrayOut) {\r
-    Statement->GrayOutExpression = mGrayOutExpression;\r
-  }\r
-\r
-\r
-  if (mInScopeDisable) {\r
-    Statement->DisableExpression = mDisableExpression;\r
+  ConditionalExprCount = GetConditionalExpressionCount(ExpressStatement);\r
+  if (ConditionalExprCount > 0) {\r
+    //\r
+    // Form is inside of suppressif\r
+    //\r
+    \r
+    Statement->Expression = (FORM_EXPRESSION_LIST *) AllocatePool( \r
+                                             (UINTN) (sizeof(FORM_EXPRESSION_LIST) + ((ConditionalExprCount -1) * sizeof(FORM_EXPRESSION *))));\r
+    ASSERT (Statement->Expression != NULL);\r
+    Statement->Expression->Count     = (UINTN) ConditionalExprCount;\r
+    Statement->Expression->Signature = FORM_EXPRESSION_LIST_SIGNATURE;\r
+    CopyMem (Statement->Expression->Expression, GetConditionalExpressionList(ExpressStatement), (UINTN) (sizeof (FORM_EXPRESSION *) * ConditionalExprCount));\r
   }\r
 \r
   Statement->InSubtitle = mInScopeSubtitle;\r
@@ -629,6 +624,9 @@ DestroyStatement (
   while (!IsListEmpty (&Statement->OptionListHead)) {\r
     Link = GetFirstNode (&Statement->OptionListHead);\r
     Option = QUESTION_OPTION_FROM_LINK (Link);\r
+    if (Option->SuppressExpression != NULL) {\r
+      FreePool (Option->SuppressExpression);\r
+    }\r
     RemoveEntryList (&Option->Link);\r
 \r
     FreePool (Option);\r
@@ -656,6 +654,10 @@ DestroyStatement (
     DestroyExpression (Expression);\r
   }\r
 \r
+  if (Statement->Expression != NULL) {\r
+    FreePool (Statement->Expression);\r
+  }\r
+\r
   if (Statement->VariableName != NULL) {\r
     FreePool (Statement->VariableName);\r
   }\r
@@ -723,6 +725,10 @@ DestroyForm (
     FreePool (ConfigInfo);\r
   }\r
 \r
+  if (Form->SuppressExpression != NULL) {\r
+    FreePool (Form->SuppressExpression);\r
+  }\r
+\r
   //\r
   // Free this Form\r
   //\r
@@ -931,10 +937,6 @@ ParseOpCodes (
   EFI_IMAGE_ID            *ImageId;\r
   BOOLEAN                 SuppressForQuestion;\r
   BOOLEAN                 SuppressForOption;\r
-  BOOLEAN                 InScopeOptionSuppress;\r
-  FORM_EXPRESSION         *OptionSuppressExpression;\r
-  BOOLEAN                 InScopeFormSuppress;\r
-  FORM_EXPRESSION         *FormSuppressExpression;\r
   UINT16                  DepthOfDisable;\r
   BOOLEAN                 OpCodeDisabled;\r
   BOOLEAN                 SingleOpCodeExpression;\r
@@ -946,15 +948,13 @@ ParseOpCodes (
   FORMSET_STORAGE         *VarStorage;\r
   LIST_ENTRY              *MapExpressionList;\r
   EFI_VARSTORE_ID         TempVarstoreId;\r
+  BOOLEAN                 InScopeDisable;\r
+  INTN                    ConditionalExprCount;\r
 \r
   mInScopeSubtitle         = FALSE;\r
   SuppressForQuestion      = FALSE;\r
   SuppressForOption        = FALSE;\r
-  InScopeFormSuppress      = FALSE;\r
-  mInScopeSuppress         = FALSE;\r
-  InScopeOptionSuppress    = FALSE;\r
-  mInScopeGrayOut          = FALSE;\r
-  mInScopeDisable          = FALSE;\r
+  InScopeDisable           = FALSE;\r
   DepthOfDisable           = 0;\r
   OpCodeDisabled           = FALSE;\r
   SingleOpCodeExpression   = FALSE;\r
@@ -962,8 +962,6 @@ ParseOpCodes (
   CurrentExpression        = NULL;\r
   CurrentDefault           = NULL;\r
   CurrentOption            = NULL;\r
-  OptionSuppressExpression = NULL;\r
-  FormSuppressExpression   = NULL;\r
   ImageId                  = NULL;\r
   MapMethod                = NULL;\r
   MapScopeDepth            = 0;\r
@@ -971,6 +969,7 @@ ParseOpCodes (
   VarStorage               = NULL;\r
   MapExpressionList        = NULL;\r
   TempVarstoreId           = 0;\r
+  ConditionalExprCount     = 0;\r
 \r
   //\r
   // Get the number of Statements and Expressions\r
@@ -1032,7 +1031,7 @@ ParseOpCodes (
 \r
         if (ScopeOpCode == EFI_IFR_DISABLE_IF_OP) {\r
           if (DepthOfDisable == 0) {\r
-            mInScopeDisable = FALSE;\r
+            InScopeDisable = FALSE;\r
             OpCodeDisabled = FALSE;\r
           } else {\r
             DepthOfDisable--;\r
@@ -1063,7 +1062,7 @@ ParseOpCodes (
         CopyMem (&ExpressionOpCode->QuestionId2, &((EFI_IFR_EQ_ID_ID *) OpCodeData)->QuestionId2, sizeof (EFI_QUESTION_ID));\r
         break;\r
 \r
-      case EFI_IFR_EQ_ID_LIST_OP:\r
+      case EFI_IFR_EQ_ID_VAL_LIST_OP:\r
         CopyMem (&ExpressionOpCode->QuestionId, &((EFI_IFR_EQ_ID_VAL_LIST *) OpCodeData)->QuestionId, sizeof (EFI_QUESTION_ID));\r
         CopyMem (&ExpressionOpCode->ListLength, &((EFI_IFR_EQ_ID_VAL_LIST *) OpCodeData)->ListLength, sizeof (UINT16));\r
         ExpressionOpCode->ValueList = AllocateCopyPool (ExpressionOpCode->ListLength * sizeof (UINT16), &((EFI_IFR_EQ_ID_VAL_LIST *) OpCodeData)->ValueList);\r
@@ -1288,7 +1287,7 @@ ParseOpCodes (
         //\r
         SingleOpCodeExpression = FALSE;\r
 \r
-        if (mInScopeDisable && CurrentForm == NULL) {\r
+        if (InScopeDisable && CurrentForm == NULL) {\r
           //\r
           // This is DisableIf expression for Form, it should be a constant expression\r
           //\r
@@ -1351,11 +1350,17 @@ ParseOpCodes (
       CopyMem (&CurrentForm->FormId,    &((EFI_IFR_FORM *) OpCodeData)->FormId,    sizeof (UINT16));\r
       CopyMem (&CurrentForm->FormTitle, &((EFI_IFR_FORM *) OpCodeData)->FormTitle, sizeof (EFI_STRING_ID));\r
 \r
-      if (InScopeFormSuppress) {\r
+      ConditionalExprCount = GetConditionalExpressionCount(ExpressForm);\r
+      if ( ConditionalExprCount > 0) {\r
         //\r
         // Form is inside of suppressif\r
         //\r
-        CurrentForm->SuppressExpression = FormSuppressExpression;\r
+        CurrentForm->SuppressExpression = (FORM_EXPRESSION_LIST *) AllocatePool( \r
+                                                 (UINTN) (sizeof(FORM_EXPRESSION_LIST) + ((ConditionalExprCount -1) * sizeof(FORM_EXPRESSION *))));\r
+        ASSERT (CurrentForm->SuppressExpression != NULL);\r
+        CurrentForm->SuppressExpression->Count     = (UINTN) ConditionalExprCount;\r
+        CurrentForm->SuppressExpression->Signature = FORM_EXPRESSION_LIST_SIGNATURE;\r
+        CopyMem (CurrentForm->SuppressExpression->Expression, GetConditionalExpressionList(ExpressForm), (UINTN) (sizeof (FORM_EXPRESSION *) * ConditionalExprCount));\r
       }\r
 \r
       if (Scope != 0) {\r
@@ -1410,11 +1415,17 @@ ParseOpCodes (
         CopyMem (&CurrentForm->FormTitle, &MapMethod->MethodTitle, sizeof (EFI_STRING_ID));\r
       }\r
 \r
-      if (InScopeFormSuppress) {\r
+      ConditionalExprCount = GetConditionalExpressionCount(ExpressForm);\r
+      if ( ConditionalExprCount > 0) {\r
         //\r
         // Form is inside of suppressif\r
         //\r
-        CurrentForm->SuppressExpression = FormSuppressExpression;\r
+        CurrentForm->SuppressExpression = (FORM_EXPRESSION_LIST *) AllocatePool( \r
+                                                 (UINTN) (sizeof(FORM_EXPRESSION_LIST) + ((ConditionalExprCount -1) * sizeof(FORM_EXPRESSION *))));\r
+        ASSERT (CurrentForm->SuppressExpression != NULL);\r
+        CurrentForm->SuppressExpression->Count     = (UINTN) ConditionalExprCount;\r
+        CurrentForm->SuppressExpression->Signature = FORM_EXPRESSION_LIST_SIGNATURE;\r
+        CopyMem (CurrentForm->SuppressExpression->Expression, GetConditionalExpressionList(ExpressForm), (UINTN) (sizeof (FORM_EXPRESSION *) * ConditionalExprCount));\r
       }\r
 \r
       if (Scope != 0) {\r
@@ -1768,8 +1779,10 @@ ParseOpCodes (
 \r
       CurrentDefault->Value.Type = ((EFI_IFR_DEFAULT *) OpCodeData)->Type;\r
       CopyMem (&CurrentDefault->DefaultId, &((EFI_IFR_DEFAULT *) OpCodeData)->DefaultId, sizeof (UINT16));\r
-      CopyMem (&CurrentDefault->Value.Value, &((EFI_IFR_DEFAULT *) OpCodeData)->Value, sizeof (EFI_IFR_TYPE_VALUE));\r
-      ExtendValueToU64 (&CurrentDefault->Value);\r
+      if (OpCodeLength == sizeof (EFI_IFR_DEFAULT)) {\r
+        CopyMem (&CurrentDefault->Value.Value, &((EFI_IFR_DEFAULT *) OpCodeData)->Value, sizeof (EFI_IFR_TYPE_VALUE));\r
+        ExtendValueToU64 (&CurrentDefault->Value);\r
+      }\r
 \r
       //\r
       // Insert to Default Value list of current Question\r
@@ -1799,8 +1812,17 @@ ParseOpCodes (
       CopyMem (&CurrentOption->Value.Value, &((EFI_IFR_ONE_OF_OPTION *) OpCodeData)->Value, sizeof (EFI_IFR_TYPE_VALUE));\r
       ExtendValueToU64 (&CurrentOption->Value);\r
 \r
-      if (InScopeOptionSuppress) {\r
-        CurrentOption->SuppressExpression = OptionSuppressExpression;\r
+      ConditionalExprCount = GetConditionalExpressionCount(ExpressOption);\r
+      if ( ConditionalExprCount > 0) {\r
+        //\r
+        // Form is inside of suppressif\r
+        //\r
+        CurrentOption->SuppressExpression = (FORM_EXPRESSION_LIST *) AllocatePool( \r
+                                                 (UINTN) (sizeof(FORM_EXPRESSION_LIST) + ((ConditionalExprCount -1) * sizeof(FORM_EXPRESSION *))));\r
+        ASSERT (CurrentOption->SuppressExpression != NULL);\r
+        CurrentOption->SuppressExpression->Count     = (UINTN) ConditionalExprCount;\r
+        CurrentOption->SuppressExpression->Signature = FORM_EXPRESSION_LIST_SIGNATURE;\r
+        CopyMem (CurrentOption->SuppressExpression->Expression, GetConditionalExpressionList(ExpressOption), (UINTN) (sizeof (FORM_EXPRESSION *) * ConditionalExprCount));\r
       }\r
 \r
       //\r
@@ -1841,6 +1863,10 @@ ParseOpCodes (
         CurrentStatement->StorageWidth = (UINT16) (CurrentStatement->MaxContainers * Width);\r
         CurrentStatement->BufferValue = AllocateZeroPool (CurrentStatement->StorageWidth);\r
         CurrentStatement->ValueType = CurrentOption->Value.Type;\r
+        if (CurrentStatement->HiiValue.Type == EFI_IFR_TYPE_BUFFER) {\r
+          CurrentStatement->HiiValue.Buffer = CurrentStatement->BufferValue;\r
+          CurrentStatement->HiiValue.BufferLen = CurrentStatement->StorageWidth;\r
+        }\r
 \r
         InitializeRequestElement (FormSet, CurrentStatement, CurrentForm);\r
       }\r
@@ -1888,14 +1914,11 @@ ParseOpCodes (
       }\r
 \r
       if (SuppressForOption) {\r
-        InScopeOptionSuppress = TRUE;\r
-        OptionSuppressExpression = CurrentExpression;\r
+        PushConditionalExpression(CurrentExpression, ExpressOption);       \r
       } else if (SuppressForQuestion) {\r
-        mInScopeSuppress = TRUE;\r
-        mSuppressExpression = CurrentExpression;\r
+        PushConditionalExpression(CurrentExpression, ExpressStatement);  \r
       } else {\r
-        InScopeFormSuppress = TRUE;\r
-        FormSuppressExpression = CurrentExpression;\r
+        PushConditionalExpression(CurrentExpression, ExpressForm);  \r
       }\r
 \r
       //\r
@@ -1914,9 +1937,7 @@ ParseOpCodes (
       CurrentExpression = CreateExpression (CurrentForm);\r
       CurrentExpression->Type = EFI_HII_EXPRESSION_GRAY_OUT_IF;\r
       InsertTailList (&CurrentForm->ExpressionListHead, &CurrentExpression->Link);\r
-\r
-      mInScopeGrayOut = TRUE;\r
-      mGrayOutExpression = CurrentExpression;\r
+      PushConditionalExpression(CurrentExpression, ExpressStatement);\r
 \r
       //\r
       // Take a look at next OpCode to see whether current expression consists\r
@@ -1943,12 +1964,11 @@ ParseOpCodes (
         // This is DisableIf for Question, enqueue it to Form expression list\r
         //\r
         InsertTailList (&CurrentForm->ExpressionListHead, &CurrentExpression->Link);\r
+        PushConditionalExpression(CurrentExpression, ExpressStatement);\r
       }\r
 \r
-      mDisableExpression = CurrentExpression;\r
-      mInScopeDisable    = TRUE;\r
-      OpCodeDisabled     = FALSE;\r
-\r
+      OpCodeDisabled  = FALSE;\r
+      InScopeDisable  = TRUE;\r
       //\r
       // Take a look at next OpCode to see whether current expression consists\r
       // of single OpCode\r
@@ -2117,6 +2137,28 @@ ParseOpCodes (
       CurrentForm->ModalForm = TRUE;\r
       break;\r
 \r
+    //\r
+    // Lock tag, used by form and statement.\r
+    //\r
+    case EFI_IFR_LOCKED_OP:\r
+      //\r
+      // Get ScopeOpcode from top of stack\r
+      //\r
+      PopScope (&ScopeOpCode);\r
+      PushScope (ScopeOpCode);\r
+      switch (ScopeOpCode) {\r
+      case EFI_IFR_FORM_OP:\r
+      case EFI_IFR_FORM_MAP_OP:\r
+        ASSERT (CurrentForm != NULL);\r
+        CurrentForm->Locked = TRUE;\r
+        break;\r
+\r
+      default:\r
+        ASSERT (CurrentStatement != NULL);\r
+        CurrentStatement->Locked = TRUE;\r
+      }      \r
+      break;\r
+\r
     //\r
     // Vendor specific\r
     //\r
@@ -2209,20 +2251,23 @@ ParseOpCodes (
 \r
       case EFI_IFR_SUPPRESS_IF_OP:\r
         if (SuppressForOption) {\r
-          InScopeOptionSuppress = FALSE;\r
+          PopConditionalExpression(ExpressOption);      \r
         } else if (SuppressForQuestion) {\r
-          mInScopeSuppress = FALSE;\r
+          PopConditionalExpression(ExpressStatement);\r
         } else {\r
-          InScopeFormSuppress = FALSE;\r
+          PopConditionalExpression(ExpressForm);\r
         }\r
         break;\r
 \r
       case EFI_IFR_GRAY_OUT_IF_OP:\r
-        mInScopeGrayOut = FALSE;\r
+        PopConditionalExpression(ExpressStatement);\r
         break;\r
 \r
       case EFI_IFR_DISABLE_IF_OP:\r
-        mInScopeDisable = FALSE;\r
+        if (CurrentForm != NULL) {\r
+          PopConditionalExpression(ExpressStatement);\r
+        }\r
+        InScopeDisable = FALSE;\r
         OpCodeDisabled = FALSE;\r
         break;\r
 \r
@@ -2254,7 +2299,7 @@ ParseOpCodes (
 \r
       default:\r
         if (IsExpressionOpCode (ScopeOpCode)) {\r
-          if (mInScopeDisable && CurrentForm == NULL) {\r
+          if (InScopeDisable && CurrentForm == NULL) {\r
             //\r
             // This is DisableIf expression for Form, it should be a constant expression\r
             //\r