2 Parser for IFR binary encoding.
4 Copyright (c) 2007 - 2009, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 UINT16 mStatementIndex
;
19 UINT16 mExpressionOpCodeIndex
;
21 BOOLEAN mInScopeSubtitle
;
22 BOOLEAN mInScopeSuppress
;
23 BOOLEAN mInScopeGrayOut
;
24 BOOLEAN mInScopeDisable
;
25 FORM_EXPRESSION
*mSuppressExpression
;
26 FORM_EXPRESSION
*mGrayOutExpression
;
27 FORM_EXPRESSION
*mDisableExpression
;
30 Initialize Statement header members.
32 @param OpCodeData Pointer of the raw OpCode data.
33 @param FormSet Pointer of the current FormSe.
34 @param Form Pointer of the current Form.
36 @return The Statement.
39 FORM_BROWSER_STATEMENT
*
42 IN OUT FORM_BROWSER_FORMSET
*FormSet
,
43 IN OUT FORM_BROWSER_FORM
*Form
46 FORM_BROWSER_STATEMENT
*Statement
;
47 EFI_IFR_STATEMENT_HEADER
*StatementHdr
;
51 // We are currently not in a Form Scope, so just skip this Statement
56 Statement
= &FormSet
->StatementBuffer
[mStatementIndex
];
59 InitializeListHead (&Statement
->DefaultListHead
);
60 InitializeListHead (&Statement
->OptionListHead
);
61 InitializeListHead (&Statement
->InconsistentListHead
);
62 InitializeListHead (&Statement
->NoSubmitListHead
);
64 Statement
->Signature
= FORM_BROWSER_STATEMENT_SIGNATURE
;
66 Statement
->Operand
= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
;
68 StatementHdr
= (EFI_IFR_STATEMENT_HEADER
*) (OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
));
69 CopyMem (&Statement
->Prompt
, &StatementHdr
->Prompt
, sizeof (EFI_STRING_ID
));
70 CopyMem (&Statement
->Help
, &StatementHdr
->Help
, sizeof (EFI_STRING_ID
));
72 if (mInScopeSuppress
) {
73 Statement
->SuppressExpression
= mSuppressExpression
;
76 if (mInScopeGrayOut
) {
77 Statement
->GrayOutExpression
= mGrayOutExpression
;
81 if (mInScopeDisable
) {
82 Statement
->DisableExpression
= mDisableExpression
;
85 Statement
->InSubtitle
= mInScopeSubtitle
;
88 // Insert this Statement into current Form
90 InsertTailList (&Form
->StatementListHead
, &Statement
->Link
);
96 Convert a numeric value to a Unicode String and insert it to String Package.
97 This string is used as the Unicode Name for the EFI Variable. This is to support
98 the deprecated vareqval opcode.
100 @param FormSet The FormSet.
101 @param Statement The numeric question whose VarStoreInfo.VarName is the
102 numeric value which is used to produce the Unicode Name
103 for the EFI Variable.
105 If the Statement is NULL, the ASSERT.
106 If the opcode is not Numeric, then ASSERT.
108 @retval EFI_SUCCESS The funtion always succeeds.
111 UpdateCheckBoxStringToken (
112 IN CONST FORM_BROWSER_FORMSET
*FormSet
,
113 IN FORM_BROWSER_STATEMENT
*Statement
116 CHAR16 Str
[MAXIMUM_VALUE_CHARACTERS
];
119 ASSERT (Statement
!= NULL
);
120 ASSERT (Statement
->Operand
== EFI_IFR_NUMERIC_OP
);
122 UnicodeValueToString (Str
, 0, Statement
->VarStoreInfo
.VarName
, MAXIMUM_VALUE_CHARACTERS
- 1);
124 Id
= HiiSetString (FormSet
->HiiHandle
, 0, Str
, NULL
);
126 return EFI_OUT_OF_RESOURCES
;
129 Statement
->VarStoreInfo
.VarName
= Id
;
135 Check if the next opcode is the EFI_IFR_EXTEND_OP_VAREQNAME.
137 @param OpCodeData The current opcode.
143 IsNextOpCodeGuidedVarEqName (
150 OpCodeData
+= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
151 if (*OpCodeData
== EFI_IFR_GUID_OP
) {
152 if (CompareGuid (&gEfiIfrFrameworkGuid
, (EFI_GUID
*)(OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
)))) {
154 // Specific GUIDed opcodes to support IFR generated from Framework HII VFR
156 if ((((EFI_IFR_GUID_VAREQNAME
*) OpCodeData
)->ExtendOpCode
) == EFI_IFR_EXTEND_OP_VAREQNAME
) {
166 Initialize Question's members.
168 @param OpCodeData Pointer of the raw OpCode data.
169 @param FormSet Pointer of the current FormSet.
170 @param Form Pointer of the current Form.
172 @return The Question.
175 FORM_BROWSER_STATEMENT
*
177 IN UINT8
*OpCodeData
,
178 IN OUT FORM_BROWSER_FORMSET
*FormSet
,
179 IN OUT FORM_BROWSER_FORM
*Form
182 FORM_BROWSER_STATEMENT
*Statement
;
183 EFI_IFR_QUESTION_HEADER
*QuestionHdr
;
185 FORMSET_STORAGE
*Storage
;
186 NAME_VALUE_NODE
*NameValueNode
;
189 Statement
= CreateStatement (OpCodeData
, FormSet
, Form
);
190 if (Statement
== NULL
) {
194 QuestionHdr
= (EFI_IFR_QUESTION_HEADER
*) (OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
));
195 CopyMem (&Statement
->QuestionId
, &QuestionHdr
->QuestionId
, sizeof (EFI_QUESTION_ID
));
196 CopyMem (&Statement
->VarStoreId
, &QuestionHdr
->VarStoreId
, sizeof (EFI_VARSTORE_ID
));
197 CopyMem (&Statement
->VarStoreInfo
.VarOffset
, &QuestionHdr
->VarStoreInfo
.VarOffset
, sizeof (UINT16
));
199 Statement
->QuestionFlags
= QuestionHdr
->Flags
;
201 if (Statement
->VarStoreId
== 0) {
203 // VarStoreId of zero indicates no variable storage
209 // Take a look at next OpCode to see whether it is a GUIDed opcode to support
210 // Framework Compatibility
212 if (FeaturePcdGet (PcdFrameworkCompatibilitySupport
)) {
213 if ((*OpCodeData
== EFI_IFR_NUMERIC_OP
) && IsNextOpCodeGuidedVarEqName (OpCodeData
)) {
214 Status
= UpdateCheckBoxStringToken (FormSet
, Statement
);
215 if (EFI_ERROR (Status
)) {
222 // Find Storage for this Question
224 Link
= GetFirstNode (&FormSet
->StorageListHead
);
225 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
226 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
228 if (Storage
->VarStoreId
== Statement
->VarStoreId
) {
229 Statement
->Storage
= Storage
;
233 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
235 ASSERT (Statement
->Storage
!= NULL
);
238 // Initialilze varname for Name/Value or EFI Variable
240 if ((Statement
->Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) ||
241 (Statement
->Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
)) {
242 Statement
->VariableName
= GetToken (Statement
->VarStoreInfo
.VarName
, FormSet
->HiiHandle
);
243 ASSERT (Statement
->VariableName
!= NULL
);
245 if (Statement
->Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
247 // Insert to Name/Value varstore list
249 NameValueNode
= AllocateZeroPool (sizeof (NAME_VALUE_NODE
));
250 ASSERT (NameValueNode
!= NULL
);
251 NameValueNode
->Signature
= NAME_VALUE_NODE_SIGNATURE
;
252 NameValueNode
->Name
= AllocateCopyPool (StrSize (Statement
->VariableName
), Statement
->VariableName
);
253 ASSERT (NameValueNode
->Name
!= NULL
);
254 NameValueNode
->Value
= AllocateZeroPool (0x10);
255 ASSERT (NameValueNode
->Value
!= NULL
);
256 NameValueNode
->EditValue
= AllocateZeroPool (0x10);
257 ASSERT (NameValueNode
->EditValue
!= NULL
);
259 InsertTailList (&Statement
->Storage
->NameValueListHead
, &NameValueNode
->Link
);
268 Allocate a FORM_EXPRESSION node.
270 @param Form The Form associated with this Expression
272 @return Pointer to a FORM_EXPRESSION data structure.
277 IN OUT FORM_BROWSER_FORM
*Form
280 FORM_EXPRESSION
*Expression
;
282 Expression
= AllocateZeroPool (sizeof (FORM_EXPRESSION
));
283 ASSERT (Expression
!= NULL
);
284 Expression
->Signature
= FORM_EXPRESSION_SIGNATURE
;
285 InitializeListHead (&Expression
->OpCodeListHead
);
292 Allocate a FORMSET_STORAGE data structure and insert to FormSet Storage List.
294 @param FormSet Pointer of the current FormSet
296 @return Pointer to a FORMSET_STORAGE data structure.
301 IN FORM_BROWSER_FORMSET
*FormSet
304 FORMSET_STORAGE
*Storage
;
306 Storage
= AllocateZeroPool (sizeof (FORMSET_STORAGE
));
307 ASSERT (Storage
!= NULL
);
308 Storage
->Signature
= FORMSET_STORAGE_SIGNATURE
;
309 InitializeListHead (&Storage
->NameValueListHead
);
310 InsertTailList (&FormSet
->StorageListHead
, &Storage
->Link
);
317 Create ConfigHdr string for a storage.
319 @param FormSet Pointer of the current FormSet
320 @param Storage Pointer of the storage
322 @retval EFI_SUCCESS Initialize ConfigHdr success
326 InitializeConfigHdr (
327 IN FORM_BROWSER_FORMSET
*FormSet
,
328 IN OUT FORMSET_STORAGE
*Storage
333 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) {
334 Name
= Storage
->Name
;
339 Storage
->ConfigHdr
= HiiConstructConfigHdr (
342 FormSet
->DriverHandle
345 if (Storage
->ConfigHdr
== NULL
) {
346 return EFI_NOT_FOUND
;
349 Storage
->ConfigRequest
= AllocateCopyPool (StrSize (Storage
->ConfigHdr
), Storage
->ConfigHdr
);
350 Storage
->SpareStrLen
= 0;
357 Initialize Request Element of a Question. <RequestElement> ::= '&'<BlockName> | '&'<Label>
359 @param FormSet Pointer of the current FormSet.
360 @param Question The Question to be initialized.
362 @retval EFI_SUCCESS Function success.
363 @retval EFI_INVALID_PARAMETER No storage associated with the Question.
367 InitializeRequestElement (
368 IN OUT FORM_BROWSER_FORMSET
*FormSet
,
369 IN OUT FORM_BROWSER_STATEMENT
*Question
372 FORMSET_STORAGE
*Storage
;
376 CHAR16 RequestElement
[30];
378 Storage
= Question
->Storage
;
379 if (Storage
== NULL
) {
380 return EFI_INVALID_PARAMETER
;
383 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
385 // <ConfigRequest> is unnecessary for EFI variable storage,
386 // GetVariable()/SetVariable() will be used to retrieve/save values
392 // Prepare <RequestElement>
394 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) {
395 StrLen
= UnicodeSPrint (
397 30 * sizeof (CHAR16
),
398 L
"&OFFSET=%x&WIDTH=%x",
399 Question
->VarStoreInfo
.VarOffset
,
400 Question
->StorageWidth
402 Question
->BlockName
= AllocateCopyPool ((StrLen
+ 1) * sizeof (CHAR16
), RequestElement
);
404 StrLen
= UnicodeSPrint (RequestElement
, 30 * sizeof (CHAR16
), L
"&%s", Question
->VariableName
);
407 if ((Question
->Operand
== EFI_IFR_PASSWORD_OP
) && ((Question
->QuestionFlags
& EFI_IFR_FLAG_CALLBACK
) == EFI_IFR_FLAG_CALLBACK
)) {
409 // Password with CALLBACK flag is stored in encoded format,
410 // so don't need to append it to <ConfigRequest>
416 // Append <RequestElement> to <ConfigRequest>
418 if (StrLen
> Storage
->SpareStrLen
) {
420 // Old String buffer is not sufficient for RequestElement, allocate a new one
422 StringSize
= (Storage
->ConfigRequest
!= NULL
) ? StrSize (Storage
->ConfigRequest
) : sizeof (CHAR16
);
423 NewStr
= AllocateZeroPool (StringSize
+ CONFIG_REQUEST_STRING_INCREMENTAL
* sizeof (CHAR16
));
424 ASSERT (NewStr
!= NULL
);
425 if (Storage
->ConfigRequest
!= NULL
) {
426 CopyMem (NewStr
, Storage
->ConfigRequest
, StringSize
);
427 FreePool (Storage
->ConfigRequest
);
429 Storage
->ConfigRequest
= NewStr
;
430 Storage
->SpareStrLen
= CONFIG_REQUEST_STRING_INCREMENTAL
;
433 StrCat (Storage
->ConfigRequest
, RequestElement
);
434 Storage
->ElementCount
++;
435 Storage
->SpareStrLen
-= StrLen
;
442 Free resources of a Expression.
444 @param FormSet Pointer of the Expression
449 IN FORM_EXPRESSION
*Expression
453 EXPRESSION_OPCODE
*OpCode
;
455 while (!IsListEmpty (&Expression
->OpCodeListHead
)) {
456 Link
= GetFirstNode (&Expression
->OpCodeListHead
);
457 OpCode
= EXPRESSION_OPCODE_FROM_LINK (Link
);
458 RemoveEntryList (&OpCode
->Link
);
460 if (OpCode
->ValueList
!= NULL
) {
461 FreePool (OpCode
->ValueList
);
466 // Free this Expression
468 FreePool (Expression
);
473 Free resources of a storage.
475 @param Storage Pointer of the storage
480 IN FORMSET_STORAGE
*Storage
484 NAME_VALUE_NODE
*NameValueNode
;
486 if (Storage
== NULL
) {
490 if (Storage
->Name
!= NULL
) {
491 FreePool (Storage
->Name
);
493 if (Storage
->Buffer
!= NULL
) {
494 FreePool (Storage
->Buffer
);
496 if (Storage
->EditBuffer
!= NULL
) {
497 FreePool (Storage
->EditBuffer
);
500 while (!IsListEmpty (&Storage
->NameValueListHead
)) {
501 Link
= GetFirstNode (&Storage
->NameValueListHead
);
502 NameValueNode
= NAME_VALUE_NODE_FROM_LINK (Link
);
503 RemoveEntryList (&NameValueNode
->Link
);
505 if (NameValueNode
->Name
!= NULL
) {
506 FreePool (NameValueNode
->Name
);
508 if (NameValueNode
->Value
!= NULL
) {
509 FreePool (NameValueNode
->Value
);
511 if (NameValueNode
->EditValue
!= NULL
) {
512 FreePool (NameValueNode
->EditValue
);
514 FreePool (NameValueNode
);
517 if (Storage
->ConfigHdr
!= NULL
) {
518 FreePool (Storage
->ConfigHdr
);
520 if (Storage
->ConfigRequest
!= NULL
) {
521 FreePool (Storage
->ConfigRequest
);
529 Free resources of a Statement.
531 @param Statement Pointer of the Statement
536 IN OUT FORM_BROWSER_STATEMENT
*Statement
540 QUESTION_DEFAULT
*Default
;
541 QUESTION_OPTION
*Option
;
542 FORM_EXPRESSION
*Expression
;
545 // Free Default value List
547 while (!IsListEmpty (&Statement
->DefaultListHead
)) {
548 Link
= GetFirstNode (&Statement
->DefaultListHead
);
549 Default
= QUESTION_DEFAULT_FROM_LINK (Link
);
550 RemoveEntryList (&Default
->Link
);
558 while (!IsListEmpty (&Statement
->OptionListHead
)) {
559 Link
= GetFirstNode (&Statement
->OptionListHead
);
560 Option
= QUESTION_OPTION_FROM_LINK (Link
);
561 RemoveEntryList (&Option
->Link
);
567 // Free Inconsistent List
569 while (!IsListEmpty (&Statement
->InconsistentListHead
)) {
570 Link
= GetFirstNode (&Statement
->InconsistentListHead
);
571 Expression
= FORM_EXPRESSION_FROM_LINK (Link
);
572 RemoveEntryList (&Expression
->Link
);
574 DestroyExpression (Expression
);
578 // Free NoSubmit List
580 while (!IsListEmpty (&Statement
->NoSubmitListHead
)) {
581 Link
= GetFirstNode (&Statement
->NoSubmitListHead
);
582 Expression
= FORM_EXPRESSION_FROM_LINK (Link
);
583 RemoveEntryList (&Expression
->Link
);
585 DestroyExpression (Expression
);
588 if (Statement
->VariableName
!= NULL
) {
589 FreePool (Statement
->VariableName
);
591 if (Statement
->BlockName
!= NULL
) {
592 FreePool (Statement
->BlockName
);
598 Free resources of a Form.
600 @param Form Pointer of the Form.
605 IN OUT FORM_BROWSER_FORM
*Form
609 FORM_EXPRESSION
*Expression
;
610 FORM_BROWSER_STATEMENT
*Statement
;
613 // Free Form Expressions
615 while (!IsListEmpty (&Form
->ExpressionListHead
)) {
616 Link
= GetFirstNode (&Form
->ExpressionListHead
);
617 Expression
= FORM_EXPRESSION_FROM_LINK (Link
);
618 RemoveEntryList (&Expression
->Link
);
620 DestroyExpression (Expression
);
624 // Free Statements/Questions
626 while (!IsListEmpty (&Form
->StatementListHead
)) {
627 Link
= GetFirstNode (&Form
->StatementListHead
);
628 Statement
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
629 RemoveEntryList (&Statement
->Link
);
631 DestroyStatement (Statement
);
642 Free resources allocated for a FormSet.
644 @param FormSet Pointer of the FormSet
649 IN OUT FORM_BROWSER_FORMSET
*FormSet
653 FORMSET_STORAGE
*Storage
;
654 FORMSET_DEFAULTSTORE
*DefaultStore
;
655 FORM_EXPRESSION
*Expression
;
656 FORM_BROWSER_FORM
*Form
;
658 if (FormSet
->IfrBinaryData
== NULL
) {
660 // Uninitialized FormSet
667 // Free IFR binary buffer
669 FreePool (FormSet
->IfrBinaryData
);
672 // Free FormSet Storage
674 if (FormSet
->StorageListHead
.ForwardLink
!= NULL
) {
675 while (!IsListEmpty (&FormSet
->StorageListHead
)) {
676 Link
= GetFirstNode (&FormSet
->StorageListHead
);
677 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
678 RemoveEntryList (&Storage
->Link
);
680 DestroyStorage (Storage
);
685 // Free FormSet Default Store
687 if (FormSet
->DefaultStoreListHead
.ForwardLink
!= NULL
) {
688 while (!IsListEmpty (&FormSet
->DefaultStoreListHead
)) {
689 Link
= GetFirstNode (&FormSet
->DefaultStoreListHead
);
690 DefaultStore
= FORMSET_DEFAULTSTORE_FROM_LINK (Link
);
691 RemoveEntryList (&DefaultStore
->Link
);
693 FreePool (DefaultStore
);
698 // Free Formset Expressions
700 while (!IsListEmpty (&FormSet
->ExpressionListHead
)) {
701 Link
= GetFirstNode (&FormSet
->ExpressionListHead
);
702 Expression
= FORM_EXPRESSION_FROM_LINK (Link
);
703 RemoveEntryList (&Expression
->Link
);
705 DestroyExpression (Expression
);
711 if (FormSet
->FormListHead
.ForwardLink
!= NULL
) {
712 while (!IsListEmpty (&FormSet
->FormListHead
)) {
713 Link
= GetFirstNode (&FormSet
->FormListHead
);
714 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
715 RemoveEntryList (&Form
->Link
);
721 if (FormSet
->StatementBuffer
!= NULL
) {
722 FreePool (FormSet
->StatementBuffer
);
724 if (FormSet
->ExpressionBuffer
!= NULL
) {
725 FreePool (FormSet
->ExpressionBuffer
);
733 Tell whether this Operand is an Expression OpCode or not
735 @param Operand Operand of an IFR OpCode.
737 @retval TRUE This is an Expression OpCode.
738 @retval FALSE Not an Expression OpCode.
746 if (((Operand
>= EFI_IFR_EQ_ID_VAL_OP
) && (Operand
<= EFI_IFR_NOT_OP
)) ||
747 ((Operand
>= EFI_IFR_MATCH_OP
) && (Operand
<= EFI_IFR_SPAN_OP
)) ||
748 (Operand
== EFI_IFR_CATENATE_OP
) ||
749 (Operand
== EFI_IFR_TO_LOWER_OP
) ||
750 (Operand
== EFI_IFR_TO_UPPER_OP
) ||
751 (Operand
== EFI_IFR_VERSION_OP
)
761 Calculate number of Statemens(Questions) and Expression OpCodes.
763 @param FormSet The FormSet to be counted.
764 @param NumberOfStatement Number of Statemens(Questions)
765 @param NumberOfExpression Number of Expression OpCodes
770 IN FORM_BROWSER_FORMSET
*FormSet
,
771 IN OUT UINT16
*NumberOfStatement
,
772 IN OUT UINT16
*NumberOfExpression
775 UINT16 StatementCount
;
776 UINT16 ExpressionCount
;
785 while (Offset
< FormSet
->IfrBinaryLength
) {
786 OpCodeData
= FormSet
->IfrBinaryData
+ Offset
;
787 OpCodeLen
= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
790 if (IsExpressionOpCode (((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
)) {
797 *NumberOfStatement
= StatementCount
;
798 *NumberOfExpression
= ExpressionCount
;
804 Parse opcodes in the formset IFR binary.
806 @param FormSet Pointer of the FormSet data structure.
808 @retval EFI_SUCCESS Opcode parse success.
809 @retval Other Opcode parse fail.
814 IN FORM_BROWSER_FORMSET
*FormSet
819 FORM_BROWSER_FORM
*CurrentForm
;
820 FORM_BROWSER_STATEMENT
*CurrentStatement
;
821 EXPRESSION_OPCODE
*ExpressionOpCode
;
822 FORM_EXPRESSION
*CurrentExpression
;
829 FORMSET_STORAGE
*Storage
;
830 FORMSET_DEFAULTSTORE
*DefaultStore
;
831 QUESTION_DEFAULT
*CurrentDefault
;
832 QUESTION_OPTION
*CurrentOption
;
835 UINT16 NumberOfStatement
;
836 UINT16 NumberOfExpression
;
837 EFI_IMAGE_ID
*ImageId
;
838 BOOLEAN SuppressForQuestion
;
839 BOOLEAN SuppressForOption
;
840 BOOLEAN InScopeOptionSuppress
;
841 FORM_EXPRESSION
*OptionSuppressExpression
;
842 BOOLEAN InScopeFormSuppress
;
843 FORM_EXPRESSION
*FormSuppressExpression
;
844 UINT16 DepthOfDisable
;
845 BOOLEAN OpCodeDisabled
;
846 BOOLEAN SingleOpCodeExpression
;
847 BOOLEAN InScopeDefault
;
848 EFI_HII_VALUE
*Value
;
850 mInScopeSubtitle
= FALSE
;
851 SuppressForQuestion
= FALSE
;
852 SuppressForOption
= FALSE
;
853 InScopeFormSuppress
= FALSE
;
854 mInScopeSuppress
= FALSE
;
855 InScopeOptionSuppress
= FALSE
;
856 mInScopeGrayOut
= FALSE
;
857 mInScopeDisable
= FALSE
;
859 OpCodeDisabled
= FALSE
;
860 SingleOpCodeExpression
= FALSE
;
861 InScopeDefault
= FALSE
;
862 CurrentExpression
= NULL
;
863 CurrentDefault
= NULL
;
864 CurrentOption
= NULL
;
865 OptionSuppressExpression
= NULL
;
866 FormSuppressExpression
= NULL
;
870 // Get the number of Statements and Expressions
872 CountOpCodes (FormSet
, &NumberOfStatement
, &NumberOfExpression
);
875 FormSet
->StatementBuffer
= AllocateZeroPool (NumberOfStatement
* sizeof (FORM_BROWSER_STATEMENT
));
876 if (FormSet
->StatementBuffer
== NULL
) {
877 return EFI_OUT_OF_RESOURCES
;
880 mExpressionOpCodeIndex
= 0;
881 FormSet
->ExpressionBuffer
= AllocateZeroPool (NumberOfExpression
* sizeof (EXPRESSION_OPCODE
));
882 if (FormSet
->ExpressionBuffer
== NULL
) {
883 return EFI_OUT_OF_RESOURCES
;
886 InitializeListHead (&FormSet
->StorageListHead
);
887 InitializeListHead (&FormSet
->DefaultStoreListHead
);
888 InitializeListHead (&FormSet
->FormListHead
);
891 CurrentStatement
= NULL
;
896 while (OpCodeOffset
< FormSet
->IfrBinaryLength
) {
897 OpCodeData
= FormSet
->IfrBinaryData
+ OpCodeOffset
;
899 OpCodeLength
= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
900 OpCodeOffset
+= OpCodeLength
;
901 Operand
= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
;
902 Scope
= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Scope
;
905 // If scope bit set, push onto scope stack
911 if (OpCodeDisabled
) {
913 // DisableIf Expression is evaluated to be TRUE, try to find its end.
914 // Here only cares the EFI_IFR_DISABLE_IF and EFI_IFR_END
916 if (Operand
== EFI_IFR_DISABLE_IF_OP
) {
918 } else if (Operand
== EFI_IFR_END_OP
) {
919 Status
= PopScope (&ScopeOpCode
);
920 if (EFI_ERROR (Status
)) {
924 if (ScopeOpCode
== EFI_IFR_DISABLE_IF_OP
) {
925 if (DepthOfDisable
== 0) {
926 mInScopeDisable
= FALSE
;
927 OpCodeDisabled
= FALSE
;
936 if (IsExpressionOpCode (Operand
)) {
937 ExpressionOpCode
= &FormSet
->ExpressionBuffer
[mExpressionOpCodeIndex
];
938 mExpressionOpCodeIndex
++;
940 ExpressionOpCode
->Signature
= EXPRESSION_OPCODE_SIGNATURE
;
941 ExpressionOpCode
->Operand
= Operand
;
942 Value
= &ExpressionOpCode
->Value
;
945 case EFI_IFR_EQ_ID_VAL_OP
:
946 CopyMem (&ExpressionOpCode
->QuestionId
, &((EFI_IFR_EQ_ID_VAL
*) OpCodeData
)->QuestionId
, sizeof (EFI_QUESTION_ID
));
948 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_16
;
949 CopyMem (&Value
->Value
.u16
, &((EFI_IFR_EQ_ID_VAL
*) OpCodeData
)->Value
, sizeof (UINT16
));
952 case EFI_IFR_EQ_ID_ID_OP
:
953 CopyMem (&ExpressionOpCode
->QuestionId
, &((EFI_IFR_EQ_ID_ID
*) OpCodeData
)->QuestionId1
, sizeof (EFI_QUESTION_ID
));
954 CopyMem (&ExpressionOpCode
->QuestionId2
, &((EFI_IFR_EQ_ID_ID
*) OpCodeData
)->QuestionId2
, sizeof (EFI_QUESTION_ID
));
957 case EFI_IFR_EQ_ID_LIST_OP
:
958 CopyMem (&ExpressionOpCode
->QuestionId
, &((EFI_IFR_EQ_ID_VAL_LIST
*) OpCodeData
)->QuestionId
, sizeof (EFI_QUESTION_ID
));
959 CopyMem (&ExpressionOpCode
->ListLength
, &((EFI_IFR_EQ_ID_VAL_LIST
*) OpCodeData
)->ListLength
, sizeof (UINT16
));
960 ExpressionOpCode
->ValueList
= AllocateCopyPool (ExpressionOpCode
->ListLength
* sizeof (UINT16
), &((EFI_IFR_EQ_ID_VAL_LIST
*) OpCodeData
)->ValueList
);
963 case EFI_IFR_TO_STRING_OP
:
964 case EFI_IFR_FIND_OP
:
965 ExpressionOpCode
->Format
= (( EFI_IFR_TO_STRING
*) OpCodeData
)->Format
;
968 case EFI_IFR_STRING_REF1_OP
:
969 Value
->Type
= EFI_IFR_TYPE_STRING
;
970 CopyMem (&Value
->Value
.string
, &(( EFI_IFR_STRING_REF1
*) OpCodeData
)->StringId
, sizeof (EFI_STRING_ID
));
973 case EFI_IFR_RULE_REF_OP
:
974 ExpressionOpCode
->RuleId
= (( EFI_IFR_RULE_REF
*) OpCodeData
)->RuleId
;
977 case EFI_IFR_SPAN_OP
:
978 ExpressionOpCode
->Flags
= (( EFI_IFR_SPAN
*) OpCodeData
)->Flags
;
981 case EFI_IFR_THIS_OP
:
982 ASSERT (CurrentStatement
!= NULL
);
983 ExpressionOpCode
->QuestionId
= CurrentStatement
->QuestionId
;
986 case EFI_IFR_QUESTION_REF1_OP
:
987 CopyMem (&ExpressionOpCode
->QuestionId
, &((EFI_IFR_EQ_ID_VAL_LIST
*) OpCodeData
)->QuestionId
, sizeof (EFI_QUESTION_ID
));
990 case EFI_IFR_QUESTION_REF3_OP
:
991 if (OpCodeLength
>= sizeof (EFI_IFR_QUESTION_REF3_2
)) {
992 CopyMem (&ExpressionOpCode
->DevicePath
, &(( EFI_IFR_QUESTION_REF3_2
*) OpCodeData
)->DevicePath
, sizeof (EFI_STRING_ID
));
994 if (OpCodeLength
>= sizeof (EFI_IFR_QUESTION_REF3_3
)) {
995 CopyMem (&ExpressionOpCode
->Guid
, &(( EFI_IFR_QUESTION_REF3_3
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
));
1003 case EFI_IFR_TRUE_OP
:
1004 Value
->Type
= EFI_IFR_TYPE_BOOLEAN
;
1005 Value
->Value
.b
= TRUE
;
1008 case EFI_IFR_FALSE_OP
:
1009 Value
->Type
= EFI_IFR_TYPE_BOOLEAN
;
1010 Value
->Value
.b
= FALSE
;
1013 case EFI_IFR_ONE_OP
:
1014 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_8
;
1015 Value
->Value
.u8
= 1;
1018 case EFI_IFR_ZERO_OP
:
1019 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_8
;
1020 Value
->Value
.u8
= 0;
1023 case EFI_IFR_ONES_OP
:
1024 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_64
;
1025 Value
->Value
.u64
= 0xffffffffffffffffULL
;
1028 case EFI_IFR_UINT8_OP
:
1029 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_8
;
1030 Value
->Value
.u8
= (( EFI_IFR_UINT8
*) OpCodeData
)->Value
;
1033 case EFI_IFR_UINT16_OP
:
1034 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_16
;
1035 CopyMem (&Value
->Value
.u16
, &(( EFI_IFR_UINT16
*) OpCodeData
)->Value
, sizeof (UINT16
));
1038 case EFI_IFR_UINT32_OP
:
1039 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_32
;
1040 CopyMem (&Value
->Value
.u32
, &(( EFI_IFR_UINT32
*) OpCodeData
)->Value
, sizeof (UINT32
));
1043 case EFI_IFR_UINT64_OP
:
1044 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_64
;
1045 CopyMem (&Value
->Value
.u64
, &(( EFI_IFR_UINT64
*) OpCodeData
)->Value
, sizeof (UINT64
));
1048 case EFI_IFR_UNDEFINED_OP
:
1049 Value
->Type
= EFI_IFR_TYPE_UNDEFINED
;
1052 case EFI_IFR_VERSION_OP
:
1053 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_16
;
1054 Value
->Value
.u16
= EFI_IFR_SPECIFICATION_VERSION
;
1061 ASSERT (CurrentExpression
!= NULL
);
1062 InsertTailList (&CurrentExpression
->OpCodeListHead
, &ExpressionOpCode
->Link
);
1064 if (SingleOpCodeExpression
) {
1066 // There are two cases to indicate the end of an Expression:
1067 // for single OpCode expression: one Expression OpCode
1068 // for expression consists of more than one OpCode: EFI_IFR_END
1070 SingleOpCodeExpression
= FALSE
;
1072 if (mInScopeDisable
&& CurrentForm
== NULL
) {
1074 // This is DisableIf expression for Form, it should be a constant expression
1076 Status
= EvaluateExpression (FormSet
, CurrentForm
, CurrentExpression
);
1077 if (EFI_ERROR (Status
)) {
1081 if (CurrentExpression
->Result
.Type
!= EFI_IFR_TYPE_BOOLEAN
) {
1082 return EFI_INVALID_PARAMETER
;
1085 OpCodeDisabled
= CurrentExpression
->Result
.Value
.b
;
1088 CurrentExpression
= NULL
;
1099 case EFI_IFR_FORM_SET_OP
:
1101 // Check the formset GUID
1103 if (CompareMem (&FormSet
->Guid
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
)) != 0) {
1104 return EFI_INVALID_PARAMETER
;
1107 CopyMem (&FormSet
->FormSetTitle
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->FormSetTitle
, sizeof (EFI_STRING_ID
));
1108 CopyMem (&FormSet
->Help
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Help
, sizeof (EFI_STRING_ID
));
1111 // The formset OpCode contains ClassGuid
1113 FormSet
->NumberOfClassGuid
= (UINT8
) (((EFI_IFR_FORM_SET
*) OpCodeData
)->Flags
& 0x3);
1114 CopyMem (FormSet
->ClassGuid
, OpCodeData
+ sizeof (EFI_IFR_FORM_SET
), FormSet
->NumberOfClassGuid
* sizeof (EFI_GUID
));
1116 InitializeListHead (&FormSet
->ExpressionListHead
);
1119 case EFI_IFR_FORM_OP
:
1121 // Create a new Form for this FormSet
1123 CurrentForm
= AllocateZeroPool (sizeof (FORM_BROWSER_FORM
));
1124 ASSERT (CurrentForm
!= NULL
);
1125 CurrentForm
->Signature
= FORM_BROWSER_FORM_SIGNATURE
;
1126 InitializeListHead (&CurrentForm
->ExpressionListHead
);
1127 InitializeListHead (&CurrentForm
->StatementListHead
);
1129 CopyMem (&CurrentForm
->FormId
, &((EFI_IFR_FORM
*) OpCodeData
)->FormId
, sizeof (UINT16
));
1130 CopyMem (&CurrentForm
->FormTitle
, &((EFI_IFR_FORM
*) OpCodeData
)->FormTitle
, sizeof (EFI_STRING_ID
));
1132 if (InScopeFormSuppress
) {
1134 // Form is inside of suppressif
1136 CurrentForm
->SuppressExpression
= FormSuppressExpression
;
1141 // Enter scope of a Form, suppressif will be used for Question or Option
1143 SuppressForQuestion
= TRUE
;
1147 // Insert into Form list of this FormSet
1149 InsertTailList (&FormSet
->FormListHead
, &CurrentForm
->Link
);
1155 case EFI_IFR_VARSTORE_OP
:
1157 // Create a buffer Storage for this FormSet
1159 Storage
= CreateStorage (FormSet
);
1160 Storage
->Type
= EFI_HII_VARSTORE_BUFFER
;
1162 CopyMem (&Storage
->VarStoreId
, &((EFI_IFR_VARSTORE
*) OpCodeData
)->VarStoreId
, sizeof (EFI_VARSTORE_ID
));
1163 CopyMem (&Storage
->Guid
, &((EFI_IFR_VARSTORE
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
));
1164 CopyMem (&Storage
->Size
, &((EFI_IFR_VARSTORE
*) OpCodeData
)->Size
, sizeof (UINT16
));
1166 Storage
->Buffer
= AllocateZeroPool (Storage
->Size
);
1167 Storage
->EditBuffer
= AllocateZeroPool (Storage
->Size
);
1169 AsciiString
= (CHAR8
*) ((EFI_IFR_VARSTORE
*) OpCodeData
)->Name
;
1170 Storage
->Name
= AllocateZeroPool (AsciiStrSize (AsciiString
) * 2);
1171 ASSERT (Storage
->Name
!= NULL
);
1172 for (Index
= 0; AsciiString
[Index
] != 0; Index
++) {
1173 Storage
->Name
[Index
] = (CHAR16
) AsciiString
[Index
];
1177 // Initialize <ConfigHdr>
1179 InitializeConfigHdr (FormSet
, Storage
);
1182 case EFI_IFR_VARSTORE_NAME_VALUE_OP
:
1184 // Create a name/value Storage for this FormSet
1186 Storage
= CreateStorage (FormSet
);
1187 Storage
->Type
= EFI_HII_VARSTORE_NAME_VALUE
;
1189 CopyMem (&Storage
->VarStoreId
, &((EFI_IFR_VARSTORE_NAME_VALUE
*) OpCodeData
)->VarStoreId
, sizeof (EFI_VARSTORE_ID
));
1190 CopyMem (&Storage
->Guid
, &((EFI_IFR_VARSTORE_NAME_VALUE
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
));
1193 // Initialize <ConfigHdr>
1195 InitializeConfigHdr (FormSet
, Storage
);
1198 case EFI_IFR_VARSTORE_EFI_OP
:
1200 // Create a EFI variable Storage for this FormSet
1202 Storage
= CreateStorage (FormSet
);
1203 Storage
->Type
= EFI_HII_VARSTORE_EFI_VARIABLE
;
1205 CopyMem (&Storage
->VarStoreId
, &((EFI_IFR_VARSTORE_EFI
*) OpCodeData
)->VarStoreId
, sizeof (EFI_VARSTORE_ID
));
1206 CopyMem (&Storage
->Guid
, &((EFI_IFR_VARSTORE_EFI
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
));
1207 CopyMem (&Storage
->Attributes
, &((EFI_IFR_VARSTORE_EFI
*) OpCodeData
)->Attributes
, sizeof (UINT32
));
1213 case EFI_IFR_DEFAULTSTORE_OP
:
1214 DefaultStore
= AllocateZeroPool (sizeof (FORMSET_DEFAULTSTORE
));
1215 ASSERT (DefaultStore
!= NULL
);
1216 DefaultStore
->Signature
= FORMSET_DEFAULTSTORE_SIGNATURE
;
1218 CopyMem (&DefaultStore
->DefaultId
, &((EFI_IFR_DEFAULTSTORE
*) OpCodeData
)->DefaultId
, sizeof (UINT16
));
1219 CopyMem (&DefaultStore
->DefaultName
, &((EFI_IFR_DEFAULTSTORE
*) OpCodeData
)->DefaultName
, sizeof (EFI_STRING_ID
));
1222 // Insert to DefaultStore list of this Formset
1224 InsertTailList (&FormSet
->DefaultStoreListHead
, &DefaultStore
->Link
);
1230 case EFI_IFR_SUBTITLE_OP
:
1231 CurrentStatement
= CreateStatement (OpCodeData
, FormSet
, CurrentForm
);
1232 ASSERT (CurrentStatement
!= NULL
);
1234 CurrentStatement
->Flags
= ((EFI_IFR_SUBTITLE
*) OpCodeData
)->Flags
;
1237 mInScopeSubtitle
= TRUE
;
1241 case EFI_IFR_TEXT_OP
:
1242 CurrentStatement
= CreateStatement (OpCodeData
, FormSet
, CurrentForm
);
1243 ASSERT (CurrentStatement
!= NULL
);
1245 CopyMem (&CurrentStatement
->TextTwo
, &((EFI_IFR_TEXT
*) OpCodeData
)->TextTwo
, sizeof (EFI_STRING_ID
));
1248 case EFI_IFR_RESET_BUTTON_OP
:
1249 CurrentStatement
= CreateStatement (OpCodeData
, FormSet
, CurrentForm
);
1250 ASSERT (CurrentStatement
!= NULL
);
1251 CopyMem (&CurrentStatement
->DefaultId
, &((EFI_IFR_RESET_BUTTON
*) OpCodeData
)->DefaultId
, sizeof (EFI_DEFAULT_ID
));
1257 case EFI_IFR_ACTION_OP
:
1258 CurrentStatement
= CreateQuestion (OpCodeData
, FormSet
, CurrentForm
);
1259 ASSERT (CurrentStatement
!= NULL
);
1260 CurrentStatement
->HiiValue
.Type
= EFI_IFR_TYPE_ACTION
;
1262 if (OpCodeLength
== sizeof (EFI_IFR_ACTION_1
)) {
1264 // No QuestionConfig present, so no configuration string will be processed
1266 CurrentStatement
->QuestionConfig
= 0;
1268 CopyMem (&CurrentStatement
->QuestionConfig
, &((EFI_IFR_ACTION
*) OpCodeData
)->QuestionConfig
, sizeof (EFI_STRING_ID
));
1272 case EFI_IFR_REF_OP
:
1273 CurrentStatement
= CreateQuestion (OpCodeData
, FormSet
, CurrentForm
);
1274 ASSERT (CurrentStatement
!= NULL
);
1275 CurrentStatement
->HiiValue
.Type
= EFI_IFR_TYPE_UNDEFINED
;
1276 CopyMem (&CurrentStatement
->RefFormId
, &((EFI_IFR_REF
*) OpCodeData
)->FormId
, sizeof (EFI_FORM_ID
));
1277 if (OpCodeLength
>= sizeof (EFI_IFR_REF2
)) {
1278 CopyMem (&CurrentStatement
->RefQuestionId
, &((EFI_IFR_REF2
*) OpCodeData
)->QuestionId
, sizeof (EFI_QUESTION_ID
));
1280 if (OpCodeLength
>= sizeof (EFI_IFR_REF3
)) {
1281 CopyMem (&CurrentStatement
->RefFormSetId
, &((EFI_IFR_REF3
*) OpCodeData
)->FormSetId
, sizeof (EFI_GUID
));
1283 if (OpCodeLength
>= sizeof (EFI_IFR_REF4
)) {
1284 CopyMem (&CurrentStatement
->RefDevicePath
, &((EFI_IFR_REF4
*) OpCodeData
)->DevicePath
, sizeof (EFI_STRING_ID
));
1290 case EFI_IFR_ONE_OF_OP
:
1291 case EFI_IFR_NUMERIC_OP
:
1292 CurrentStatement
= CreateQuestion (OpCodeData
, FormSet
, CurrentForm
);
1293 ASSERT(CurrentStatement
!= NULL
);
1295 CurrentStatement
->Flags
= ((EFI_IFR_ONE_OF
*) OpCodeData
)->Flags
;
1296 Value
= &CurrentStatement
->HiiValue
;
1298 switch (CurrentStatement
->Flags
& EFI_IFR_NUMERIC_SIZE
) {
1299 case EFI_IFR_NUMERIC_SIZE_1
:
1300 CurrentStatement
->Minimum
= ((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u8
.MinValue
;
1301 CurrentStatement
->Maximum
= ((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u8
.MaxValue
;
1302 CurrentStatement
->Step
= ((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u8
.Step
;
1303 CurrentStatement
->StorageWidth
= sizeof (UINT8
);
1304 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_8
;
1307 case EFI_IFR_NUMERIC_SIZE_2
:
1308 CopyMem (&CurrentStatement
->Minimum
, &((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u16
.MinValue
, sizeof (UINT16
));
1309 CopyMem (&CurrentStatement
->Maximum
, &((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u16
.MaxValue
, sizeof (UINT16
));
1310 CopyMem (&CurrentStatement
->Step
, &((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u16
.Step
, sizeof (UINT16
));
1311 CurrentStatement
->StorageWidth
= sizeof (UINT16
);
1312 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_16
;
1315 case EFI_IFR_NUMERIC_SIZE_4
:
1316 CopyMem (&CurrentStatement
->Minimum
, &((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u32
.MinValue
, sizeof (UINT32
));
1317 CopyMem (&CurrentStatement
->Maximum
, &((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u32
.MaxValue
, sizeof (UINT32
));
1318 CopyMem (&CurrentStatement
->Step
, &((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u32
.Step
, sizeof (UINT32
));
1319 CurrentStatement
->StorageWidth
= sizeof (UINT32
);
1320 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_32
;
1323 case EFI_IFR_NUMERIC_SIZE_8
:
1324 CopyMem (&CurrentStatement
->Minimum
, &((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u64
.MinValue
, sizeof (UINT64
));
1325 CopyMem (&CurrentStatement
->Maximum
, &((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u64
.MaxValue
, sizeof (UINT64
));
1326 CopyMem (&CurrentStatement
->Step
, &((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u64
.Step
, sizeof (UINT64
));
1327 CurrentStatement
->StorageWidth
= sizeof (UINT64
);
1328 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_64
;
1335 InitializeRequestElement (FormSet
, CurrentStatement
);
1337 if ((Operand
== EFI_IFR_ONE_OF_OP
) && Scope
!= 0) {
1338 SuppressForOption
= TRUE
;
1342 case EFI_IFR_ORDERED_LIST_OP
:
1343 CurrentStatement
= CreateQuestion (OpCodeData
, FormSet
, CurrentForm
);
1344 ASSERT(CurrentStatement
!= NULL
);
1346 CurrentStatement
->Flags
= ((EFI_IFR_ORDERED_LIST
*) OpCodeData
)->Flags
;
1347 CurrentStatement
->MaxContainers
= ((EFI_IFR_ORDERED_LIST
*) OpCodeData
)->MaxContainers
;
1349 CurrentStatement
->HiiValue
.Type
= EFI_IFR_TYPE_BUFFER
;
1352 SuppressForOption
= TRUE
;
1356 case EFI_IFR_CHECKBOX_OP
:
1357 CurrentStatement
= CreateQuestion (OpCodeData
, FormSet
, CurrentForm
);
1358 ASSERT(CurrentStatement
!= NULL
);
1360 CurrentStatement
->Flags
= ((EFI_IFR_CHECKBOX
*) OpCodeData
)->Flags
;
1361 CurrentStatement
->StorageWidth
= sizeof (BOOLEAN
);
1362 CurrentStatement
->HiiValue
.Type
= EFI_IFR_TYPE_BOOLEAN
;
1364 InitializeRequestElement (FormSet
, CurrentStatement
);
1368 case EFI_IFR_STRING_OP
:
1369 CurrentStatement
= CreateQuestion (OpCodeData
, FormSet
, CurrentForm
);
1370 ASSERT (CurrentStatement
!= NULL
);
1372 // MinSize is the minimum number of characters that can be accepted for this opcode,
1373 // MaxSize is the maximum number of characters that can be accepted for this opcode.
1374 // The characters are stored as Unicode, so the storage width should multiply 2.
1376 CurrentStatement
->Minimum
= ((EFI_IFR_STRING
*) OpCodeData
)->MinSize
;
1377 CurrentStatement
->Maximum
= ((EFI_IFR_STRING
*) OpCodeData
)->MaxSize
;
1378 CurrentStatement
->StorageWidth
= (UINT16
)((UINTN
) CurrentStatement
->Maximum
* sizeof (CHAR16
));
1379 CurrentStatement
->Flags
= ((EFI_IFR_STRING
*) OpCodeData
)->Flags
;
1381 CurrentStatement
->HiiValue
.Type
= EFI_IFR_TYPE_STRING
;
1382 CurrentStatement
->BufferValue
= AllocateZeroPool (CurrentStatement
->StorageWidth
+ sizeof (CHAR16
));
1384 InitializeRequestElement (FormSet
, CurrentStatement
);
1387 case EFI_IFR_PASSWORD_OP
:
1388 CurrentStatement
= CreateQuestion (OpCodeData
, FormSet
, CurrentForm
);
1389 ASSERT (CurrentStatement
!= NULL
);
1391 // MinSize is the minimum number of characters that can be accepted for this opcode,
1392 // MaxSize is the maximum number of characters that can be accepted for this opcode.
1393 // The characters are stored as Unicode, so the storage width should multiply 2.
1395 CopyMem (&CurrentStatement
->Minimum
, &((EFI_IFR_PASSWORD
*) OpCodeData
)->MinSize
, sizeof (UINT16
));
1396 CopyMem (&CurrentStatement
->Maximum
, &((EFI_IFR_PASSWORD
*) OpCodeData
)->MaxSize
, sizeof (UINT16
));
1397 CurrentStatement
->StorageWidth
= (UINT16
)((UINTN
) CurrentStatement
->Maximum
* sizeof (CHAR16
));
1399 CurrentStatement
->HiiValue
.Type
= EFI_IFR_TYPE_STRING
;
1400 CurrentStatement
->BufferValue
= AllocateZeroPool ((CurrentStatement
->StorageWidth
+ sizeof (CHAR16
)));
1402 InitializeRequestElement (FormSet
, CurrentStatement
);
1405 case EFI_IFR_DATE_OP
:
1406 CurrentStatement
= CreateQuestion (OpCodeData
, FormSet
, CurrentForm
);
1407 ASSERT(CurrentStatement
!= NULL
);
1409 CurrentStatement
->Flags
= ((EFI_IFR_DATE
*) OpCodeData
)->Flags
;
1410 CurrentStatement
->HiiValue
.Type
= EFI_IFR_TYPE_DATE
;
1412 if ((CurrentStatement
->Flags
& EFI_QF_DATE_STORAGE
) == QF_DATE_STORAGE_NORMAL
) {
1413 CurrentStatement
->StorageWidth
= sizeof (EFI_HII_DATE
);
1415 InitializeRequestElement (FormSet
, CurrentStatement
);
1418 // Don't assign storage for RTC type of date/time
1420 CurrentStatement
->Storage
= NULL
;
1421 CurrentStatement
->StorageWidth
= 0;
1425 case EFI_IFR_TIME_OP
:
1426 CurrentStatement
= CreateQuestion (OpCodeData
, FormSet
, CurrentForm
);
1427 ASSERT(CurrentStatement
!= NULL
);
1429 CurrentStatement
->Flags
= ((EFI_IFR_TIME
*) OpCodeData
)->Flags
;
1430 CurrentStatement
->HiiValue
.Type
= EFI_IFR_TYPE_TIME
;
1432 if ((CurrentStatement
->Flags
& QF_TIME_STORAGE
) == QF_TIME_STORAGE_NORMAL
) {
1433 CurrentStatement
->StorageWidth
= sizeof (EFI_IFR_TIME
);
1435 InitializeRequestElement (FormSet
, CurrentStatement
);
1438 // Don't assign storage for RTC type of date/time
1440 CurrentStatement
->Storage
= NULL
;
1441 CurrentStatement
->StorageWidth
= 0;
1448 case EFI_IFR_DEFAULT_OP
:
1450 // EFI_IFR_DEFAULT appear in scope of a Question,
1451 // It creates a default value for the current question.
1452 // A Question may have more than one Default value which have different default types.
1454 CurrentDefault
= AllocateZeroPool (sizeof (QUESTION_DEFAULT
));
1455 ASSERT (CurrentDefault
!= NULL
);
1456 CurrentDefault
->Signature
= QUESTION_DEFAULT_SIGNATURE
;
1458 CurrentDefault
->Value
.Type
= ((EFI_IFR_DEFAULT
*) OpCodeData
)->Type
;
1459 CopyMem (&CurrentDefault
->DefaultId
, &((EFI_IFR_DEFAULT
*) OpCodeData
)->DefaultId
, sizeof (UINT16
));
1460 CopyMem (&CurrentDefault
->Value
.Value
, &((EFI_IFR_DEFAULT
*) OpCodeData
)->Value
, sizeof (EFI_IFR_TYPE_VALUE
));
1461 ExtendValueToU64 (&CurrentDefault
->Value
);
1464 // Insert to Default Value list of current Question
1466 InsertTailList (&CurrentStatement
->DefaultListHead
, &CurrentDefault
->Link
);
1469 InScopeDefault
= TRUE
;
1476 case EFI_IFR_ONE_OF_OPTION_OP
:
1478 // EFI_IFR_ONE_OF_OPTION appear in scope of a Question.
1479 // It create a selection for use in current Question.
1481 CurrentOption
= AllocateZeroPool (sizeof (QUESTION_OPTION
));
1482 ASSERT (CurrentOption
!= NULL
);
1483 CurrentOption
->Signature
= QUESTION_OPTION_SIGNATURE
;
1485 CurrentOption
->Flags
= ((EFI_IFR_ONE_OF_OPTION
*) OpCodeData
)->Flags
;
1486 CurrentOption
->Value
.Type
= ((EFI_IFR_ONE_OF_OPTION
*) OpCodeData
)->Type
;
1487 CopyMem (&CurrentOption
->Text
, &((EFI_IFR_ONE_OF_OPTION
*) OpCodeData
)->Option
, sizeof (EFI_STRING_ID
));
1488 CopyMem (&CurrentOption
->Value
.Value
, &((EFI_IFR_ONE_OF_OPTION
*) OpCodeData
)->Value
, sizeof (EFI_IFR_TYPE_VALUE
));
1489 ExtendValueToU64 (&CurrentOption
->Value
);
1491 if (InScopeOptionSuppress
) {
1492 CurrentOption
->SuppressExpression
= OptionSuppressExpression
;
1496 // Insert to Option list of current Question
1498 InsertTailList (&CurrentStatement
->OptionListHead
, &CurrentOption
->Link
);
1501 // Now we know the Storage width of nested Ordered List
1503 if ((CurrentStatement
->Operand
== EFI_IFR_ORDERED_LIST_OP
) && (CurrentStatement
->BufferValue
== NULL
)) {
1505 switch (CurrentOption
->Value
.Type
) {
1506 case EFI_IFR_TYPE_NUM_SIZE_8
:
1510 case EFI_IFR_TYPE_NUM_SIZE_16
:
1514 case EFI_IFR_TYPE_NUM_SIZE_32
:
1518 case EFI_IFR_TYPE_NUM_SIZE_64
:
1524 // Invalid type for Ordered List
1529 CurrentStatement
->StorageWidth
= (UINT16
) (CurrentStatement
->MaxContainers
* Width
);
1530 CurrentStatement
->BufferValue
= AllocateZeroPool (CurrentStatement
->StorageWidth
);
1531 CurrentStatement
->ValueType
= CurrentOption
->Value
.Type
;
1533 InitializeRequestElement (FormSet
, CurrentStatement
);
1540 case EFI_IFR_NO_SUBMIT_IF_OP
:
1541 case EFI_IFR_INCONSISTENT_IF_OP
:
1543 // Create an Expression node
1545 CurrentExpression
= CreateExpression (CurrentForm
);
1546 CopyMem (&CurrentExpression
->Error
, &((EFI_IFR_INCONSISTENT_IF
*) OpCodeData
)->Error
, sizeof (EFI_STRING_ID
));
1548 if (Operand
== EFI_IFR_NO_SUBMIT_IF_OP
) {
1549 CurrentExpression
->Type
= EFI_HII_EXPRESSION_NO_SUBMIT_IF
;
1550 InsertTailList (&CurrentStatement
->NoSubmitListHead
, &CurrentExpression
->Link
);
1552 CurrentExpression
->Type
= EFI_HII_EXPRESSION_INCONSISTENT_IF
;
1553 InsertTailList (&CurrentStatement
->InconsistentListHead
, &CurrentExpression
->Link
);
1557 // Take a look at next OpCode to see whether current expression consists
1560 if (((EFI_IFR_OP_HEADER
*) (OpCodeData
+ OpCodeLength
))->Scope
== 0) {
1561 SingleOpCodeExpression
= TRUE
;
1565 case EFI_IFR_SUPPRESS_IF_OP
:
1567 // Question and Option will appear in scope of this OpCode
1569 CurrentExpression
= CreateExpression (CurrentForm
);
1570 CurrentExpression
->Type
= EFI_HII_EXPRESSION_SUPPRESS_IF
;
1572 if (CurrentForm
== NULL
) {
1573 InsertTailList (&FormSet
->ExpressionListHead
, &CurrentExpression
->Link
);
1575 InsertTailList (&CurrentForm
->ExpressionListHead
, &CurrentExpression
->Link
);
1578 if (SuppressForOption
) {
1579 InScopeOptionSuppress
= TRUE
;
1580 OptionSuppressExpression
= CurrentExpression
;
1581 } else if (SuppressForQuestion
) {
1582 mInScopeSuppress
= TRUE
;
1583 mSuppressExpression
= CurrentExpression
;
1585 InScopeFormSuppress
= TRUE
;
1586 FormSuppressExpression
= CurrentExpression
;
1590 // Take a look at next OpCode to see whether current expression consists
1593 if (((EFI_IFR_OP_HEADER
*) (OpCodeData
+ OpCodeLength
))->Scope
== 0) {
1594 SingleOpCodeExpression
= TRUE
;
1598 case EFI_IFR_GRAY_OUT_IF_OP
:
1600 // Questions will appear in scope of this OpCode
1602 CurrentExpression
= CreateExpression (CurrentForm
);
1603 CurrentExpression
->Type
= EFI_HII_EXPRESSION_GRAY_OUT_IF
;
1604 InsertTailList (&CurrentForm
->ExpressionListHead
, &CurrentExpression
->Link
);
1606 mInScopeGrayOut
= TRUE
;
1607 mGrayOutExpression
= CurrentExpression
;
1610 // Take a look at next OpCode to see whether current expression consists
1613 if (((EFI_IFR_OP_HEADER
*) (OpCodeData
+ OpCodeLength
))->Scope
== 0) {
1614 SingleOpCodeExpression
= TRUE
;
1618 case EFI_IFR_DISABLE_IF_OP
:
1620 // The DisableIf expression should only rely on constant, so it could be
1621 // evaluated at initialization and it will not be queued
1623 CurrentExpression
= AllocateZeroPool (sizeof (FORM_EXPRESSION
));
1624 ASSERT (CurrentExpression
!= NULL
);
1625 CurrentExpression
->Signature
= FORM_EXPRESSION_SIGNATURE
;
1626 CurrentExpression
->Type
= EFI_HII_EXPRESSION_DISABLE_IF
;
1627 InitializeListHead (&CurrentExpression
->OpCodeListHead
);
1629 if (CurrentForm
!= NULL
) {
1631 // This is DisableIf for Question, enqueue it to Form expression list
1633 InsertTailList (&CurrentForm
->ExpressionListHead
, &CurrentExpression
->Link
);
1636 mDisableExpression
= CurrentExpression
;
1637 mInScopeDisable
= TRUE
;
1638 OpCodeDisabled
= FALSE
;
1641 // Take a look at next OpCode to see whether current expression consists
1644 if (((EFI_IFR_OP_HEADER
*) (OpCodeData
+ OpCodeLength
))->Scope
== 0) {
1645 SingleOpCodeExpression
= TRUE
;
1652 case EFI_IFR_VALUE_OP
:
1653 CurrentExpression
= CreateExpression (CurrentForm
);
1654 CurrentExpression
->Type
= EFI_HII_EXPRESSION_VALUE
;
1655 InsertTailList (&CurrentForm
->ExpressionListHead
, &CurrentExpression
->Link
);
1657 if (InScopeDefault
) {
1659 // Used for default (EFI_IFR_DEFAULT)
1661 CurrentDefault
->ValueExpression
= CurrentExpression
;
1664 // If used for a question, then the question will be read-only
1667 // Make sure CurrentStatement is not NULL.
1668 // If it is NULL, 1) ParseOpCodes functions may parse the IFR wrongly. Or 2) the IFR
1669 // file is wrongly generated by tools such as VFR Compiler. There may be a bug in VFR Compiler.
1671 ASSERT (CurrentStatement
!= NULL
);
1672 CurrentStatement
->ValueExpression
= CurrentExpression
;
1676 // Take a look at next OpCode to see whether current expression consists
1679 if (((EFI_IFR_OP_HEADER
*) (OpCodeData
+ OpCodeLength
))->Scope
== 0) {
1680 SingleOpCodeExpression
= TRUE
;
1684 case EFI_IFR_RULE_OP
:
1685 CurrentExpression
= CreateExpression (CurrentForm
);
1686 CurrentExpression
->Type
= EFI_HII_EXPRESSION_RULE
;
1688 CurrentExpression
->RuleId
= ((EFI_IFR_RULE
*) OpCodeData
)->RuleId
;
1689 InsertTailList (&CurrentForm
->ExpressionListHead
, &CurrentExpression
->Link
);
1692 // Take a look at next OpCode to see whether current expression consists
1695 if (((EFI_IFR_OP_HEADER
*) (OpCodeData
+ OpCodeLength
))->Scope
== 0) {
1696 SingleOpCodeExpression
= TRUE
;
1703 case EFI_IFR_IMAGE_OP
:
1705 // Get ScopeOpcode from top of stack
1707 PopScope (&ScopeOpCode
);
1708 PushScope (ScopeOpCode
);
1710 switch (ScopeOpCode
) {
1711 case EFI_IFR_FORM_SET_OP
:
1712 ImageId
= &FormSet
->ImageId
;
1715 case EFI_IFR_FORM_OP
:
1716 ASSERT (CurrentForm
!= NULL
);
1717 ImageId
= &CurrentForm
->ImageId
;
1720 case EFI_IFR_ONE_OF_OPTION_OP
:
1721 ImageId
= &CurrentOption
->ImageId
;
1726 // Make sure CurrentStatement is not NULL.
1727 // If it is NULL, 1) ParseOpCodes functions may parse the IFR wrongly. Or 2) the IFR
1728 // file is wrongly generated by tools such as VFR Compiler.
1730 ASSERT (CurrentStatement
!= NULL
);
1731 ImageId
= &CurrentStatement
->ImageId
;
1735 ASSERT (ImageId
!= NULL
);
1736 CopyMem (ImageId
, &((EFI_IFR_IMAGE
*) OpCodeData
)->Id
, sizeof (EFI_IMAGE_ID
));
1742 case EFI_IFR_REFRESH_OP
:
1743 ASSERT (CurrentStatement
!= NULL
);
1744 CurrentStatement
->RefreshInterval
= ((EFI_IFR_REFRESH
*) OpCodeData
)->RefreshInterval
;
1750 case EFI_IFR_GUID_OP
:
1751 if (CompareGuid (&gEfiIfrTianoGuid
, (EFI_GUID
*)(OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
)))) {
1753 // Tiano specific GUIDed opcodes
1755 switch (((EFI_IFR_GUID_LABEL
*) OpCodeData
)->ExtendOpCode
) {
1756 case EFI_IFR_EXTEND_OP_LABEL
:
1758 // just ignore label
1762 case EFI_IFR_EXTEND_OP_BANNER
:
1764 // By SubClass to get Banner Data from Front Page
1766 if (FormSet
->SubClass
== EFI_FRONT_PAGE_SUBCLASS
) {
1768 &gBannerData
->Banner
[((EFI_IFR_GUID_BANNER
*) OpCodeData
)->LineNumber
][
1769 ((EFI_IFR_GUID_BANNER
*) OpCodeData
)->Alignment
],
1770 &((EFI_IFR_GUID_BANNER
*) OpCodeData
)->Title
,
1771 sizeof (EFI_STRING_ID
)
1776 case EFI_IFR_EXTEND_OP_CLASS
:
1777 CopyMem (&FormSet
->Class
, &((EFI_IFR_GUID_CLASS
*) OpCodeData
)->Class
, sizeof (UINT16
));
1780 case EFI_IFR_EXTEND_OP_SUBCLASS
:
1781 CopyMem (&FormSet
->SubClass
, &((EFI_IFR_GUID_SUBCLASS
*) OpCodeData
)->SubClass
, sizeof (UINT16
));
1794 case EFI_IFR_END_OP
:
1795 Status
= PopScope (&ScopeOpCode
);
1796 if (EFI_ERROR (Status
)) {
1801 switch (ScopeOpCode
) {
1802 case EFI_IFR_FORM_SET_OP
:
1804 // End of FormSet, update FormSet IFR binary length
1805 // to stop parsing substantial OpCodes
1807 FormSet
->IfrBinaryLength
= OpCodeOffset
;
1810 case EFI_IFR_FORM_OP
:
1815 SuppressForQuestion
= FALSE
;
1818 case EFI_IFR_ONE_OF_OPTION_OP
:
1822 CurrentOption
= NULL
;
1825 case EFI_IFR_SUBTITLE_OP
:
1826 mInScopeSubtitle
= FALSE
;
1829 case EFI_IFR_NO_SUBMIT_IF_OP
:
1830 case EFI_IFR_INCONSISTENT_IF_OP
:
1832 // Ignore end of EFI_IFR_NO_SUBMIT_IF and EFI_IFR_INCONSISTENT_IF
1836 case EFI_IFR_SUPPRESS_IF_OP
:
1837 if (SuppressForOption
) {
1838 InScopeOptionSuppress
= FALSE
;
1839 } else if (SuppressForQuestion
) {
1840 mInScopeSuppress
= FALSE
;
1842 InScopeFormSuppress
= FALSE
;
1846 case EFI_IFR_GRAY_OUT_IF_OP
:
1847 mInScopeGrayOut
= FALSE
;
1850 case EFI_IFR_DISABLE_IF_OP
:
1851 mInScopeDisable
= FALSE
;
1852 OpCodeDisabled
= FALSE
;
1855 case EFI_IFR_ONE_OF_OP
:
1856 case EFI_IFR_ORDERED_LIST_OP
:
1857 SuppressForOption
= FALSE
;
1860 case EFI_IFR_DEFAULT_OP
:
1861 InScopeDefault
= FALSE
;
1865 if (IsExpressionOpCode (ScopeOpCode
)) {
1866 if (mInScopeDisable
&& CurrentForm
== NULL
) {
1868 // This is DisableIf expression for Form, it should be a constant expression
1870 ASSERT (CurrentExpression
!= NULL
);
1871 Status
= EvaluateExpression (FormSet
, CurrentForm
, CurrentExpression
);
1872 if (EFI_ERROR (Status
)) {
1876 if (CurrentExpression
->Result
.Type
!= EFI_IFR_TYPE_BOOLEAN
) {
1877 return EFI_INVALID_PARAMETER
;
1880 OpCodeDisabled
= CurrentExpression
->Result
.Value
.b
;
1882 // DisableIf Expression is only used once and not quequed, free it
1884 DestroyExpression (CurrentExpression
);
1888 // End of current Expression
1890 CurrentExpression
= NULL
;