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 FORM_EXPRESSION
*mSuppressExpression
;
25 FORM_EXPRESSION
*mGrayOutExpression
;
27 EFI_GUID gTianoHiiIfrGuid
= EFI_IFR_TIANO_GUID
;
28 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID mFrameworkHiiCompatibilityGuid
= EFI_IFR_FRAMEWORK_GUID
;
32 Initialize Statement header members.
34 @param OpCodeData Pointer of the raw OpCode data.
35 @param FormSet Pointer of the current FormSe.
36 @param Form Pointer of the current Form.
38 @return The Statement.
41 FORM_BROWSER_STATEMENT
*
44 IN OUT FORM_BROWSER_FORMSET
*FormSet
,
45 IN OUT FORM_BROWSER_FORM
*Form
48 FORM_BROWSER_STATEMENT
*Statement
;
49 EFI_IFR_STATEMENT_HEADER
*StatementHdr
;
53 // We are currently not in a Form Scope, so just skip this Statement
58 Statement
= &FormSet
->StatementBuffer
[mStatementIndex
];
61 InitializeListHead (&Statement
->DefaultListHead
);
62 InitializeListHead (&Statement
->OptionListHead
);
63 InitializeListHead (&Statement
->InconsistentListHead
);
64 InitializeListHead (&Statement
->NoSubmitListHead
);
66 Statement
->Signature
= FORM_BROWSER_STATEMENT_SIGNATURE
;
68 Statement
->Operand
= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
;
70 StatementHdr
= (EFI_IFR_STATEMENT_HEADER
*) (OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
));
71 CopyMem (&Statement
->Prompt
, &StatementHdr
->Prompt
, sizeof (EFI_STRING_ID
));
72 CopyMem (&Statement
->Help
, &StatementHdr
->Help
, sizeof (EFI_STRING_ID
));
74 if (mInScopeSuppress
) {
75 Statement
->SuppressExpression
= mSuppressExpression
;
78 if (mInScopeGrayOut
) {
79 Statement
->GrayOutExpression
= mGrayOutExpression
;
82 Statement
->InSubtitle
= mInScopeSubtitle
;
85 // Insert this Statement into current Form
87 InsertTailList (&Form
->StatementListHead
, &Statement
->Link
);
93 Convert a numeric value to a Unicode String and insert it to String Package.
94 This string is used as the Unicode Name for the EFI Variable. This is to support
95 the deprecated vareqval opcode.
97 @param FormSet The FormSet.
98 @param Statement The numeric question whose VarStoreInfo.VarName is the
99 numeric value which is used to produce the Unicode Name
100 for the EFI Variable.
102 If the Statement is NULL, the ASSERT.
103 If the opcode is not Numeric, then ASSERT.
105 @retval EFI_SUCCESS The funtion always succeeds.
108 UpdateCheckBoxStringToken (
109 IN CONST FORM_BROWSER_FORMSET
*FormSet
,
110 IN FORM_BROWSER_STATEMENT
*Statement
113 CHAR16 Str
[MAXIMUM_VALUE_CHARACTERS
];
117 ASSERT (Statement
!= NULL
);
118 ASSERT (Statement
->Operand
== EFI_IFR_NUMERIC_OP
);
120 UnicodeValueToString (Str
, 0, Statement
->VarStoreInfo
.VarName
, MAXIMUM_VALUE_CHARACTERS
- 1);
122 Status
= HiiLibNewString (FormSet
->HiiHandle
, &Id
, Str
);
124 if (EFI_ERROR (Status
)) {
128 Statement
->VarStoreInfo
.VarName
= Id
;
134 Check if the next opcode is the EFI_IFR_EXTEND_OP_VAREQNAME.
136 @param OpCodeData The current opcode.
142 IsNextOpCodeGuidedVarEqName (
149 OpCodeData
+= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
150 if (*OpCodeData
== EFI_IFR_GUID_OP
) {
151 if (CompareGuid (&mFrameworkHiiCompatibilityGuid
, (EFI_GUID
*)(OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
)))) {
153 // Specific GUIDed opcodes to support IFR generated from Framework HII VFR
155 if ((((EFI_IFR_GUID_VAREQNAME
*) OpCodeData
)->ExtendOpCode
) == EFI_IFR_EXTEND_OP_VAREQNAME
) {
165 Initialize Question's members.
167 @param OpCodeData Pointer of the raw OpCode data.
168 @param FormSet Pointer of the current FormSet.
169 @param Form Pointer of the current Form.
171 @return The Question.
174 FORM_BROWSER_STATEMENT
*
176 IN UINT8
*OpCodeData
,
177 IN OUT FORM_BROWSER_FORMSET
*FormSet
,
178 IN OUT FORM_BROWSER_FORM
*Form
181 FORM_BROWSER_STATEMENT
*Statement
;
182 EFI_IFR_QUESTION_HEADER
*QuestionHdr
;
184 FORMSET_STORAGE
*Storage
;
185 NAME_VALUE_NODE
*NameValueNode
;
188 Statement
= CreateStatement (OpCodeData
, FormSet
, Form
);
189 if (Statement
== NULL
) {
193 QuestionHdr
= (EFI_IFR_QUESTION_HEADER
*) (OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
));
194 CopyMem (&Statement
->QuestionId
, &QuestionHdr
->QuestionId
, sizeof (EFI_QUESTION_ID
));
195 CopyMem (&Statement
->VarStoreId
, &QuestionHdr
->VarStoreId
, sizeof (EFI_VARSTORE_ID
));
196 CopyMem (&Statement
->VarStoreInfo
.VarOffset
, &QuestionHdr
->VarStoreInfo
.VarOffset
, sizeof (UINT16
));
198 Statement
->QuestionFlags
= QuestionHdr
->Flags
;
200 if (Statement
->VarStoreId
== 0) {
202 // VarStoreId of zero indicates no variable storage
208 // Take a look at next OpCode to see whether it is a GUIDed opcode to support
209 // Framework Compatibility
211 if (FeaturePcdGet (PcdFrameworkHiiCompatibilitySupport
)) {
212 if ((*OpCodeData
== EFI_IFR_NUMERIC_OP
) && IsNextOpCodeGuidedVarEqName (OpCodeData
)) {
213 Status
= UpdateCheckBoxStringToken (FormSet
, Statement
);
214 if (EFI_ERROR (Status
)) {
221 // Find Storage for this Question
223 Link
= GetFirstNode (&FormSet
->StorageListHead
);
224 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
225 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
227 if (Storage
->VarStoreId
== Statement
->VarStoreId
) {
228 Statement
->Storage
= Storage
;
232 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
234 ASSERT (Statement
->Storage
!= NULL
);
237 // Initialilze varname for Name/Value or EFI Variable
239 if ((Statement
->Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) ||
240 (Statement
->Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
)) {
241 Statement
->VariableName
= GetToken (Statement
->VarStoreInfo
.VarName
, FormSet
->HiiHandle
);
242 ASSERT (Statement
->VariableName
!= NULL
);
244 if (Statement
->Storage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
) {
246 // Insert to Name/Value varstore list
248 NameValueNode
= AllocateZeroPool (sizeof (NAME_VALUE_NODE
));
249 ASSERT (NameValueNode
!= NULL
);
250 NameValueNode
->Signature
= NAME_VALUE_NODE_SIGNATURE
;
251 NameValueNode
->Name
= AllocateCopyPool (StrSize (Statement
->VariableName
), Statement
->VariableName
);
252 ASSERT (NameValueNode
->Name
!= NULL
);
253 NameValueNode
->Value
= AllocateZeroPool (0x10);
254 ASSERT (NameValueNode
->Value
!= NULL
);
255 NameValueNode
->EditValue
= AllocateZeroPool (0x10);
256 ASSERT (NameValueNode
->EditValue
!= NULL
);
258 InsertTailList (&Statement
->Storage
->NameValueListHead
, &NameValueNode
->Link
);
267 Allocate a FORM_EXPRESSION node.
269 @param Form The Form associated with this Expression
271 @return Pointer to a FORM_EXPRESSION data structure.
276 IN OUT FORM_BROWSER_FORM
*Form
279 FORM_EXPRESSION
*Expression
;
281 Expression
= AllocateZeroPool (sizeof (FORM_EXPRESSION
));
282 ASSERT (Expression
!= NULL
);
283 Expression
->Signature
= FORM_EXPRESSION_SIGNATURE
;
284 InitializeListHead (&Expression
->OpCodeListHead
);
291 Allocate a FORMSET_STORAGE data structure and insert to FormSet Storage List.
293 @param FormSet Pointer of the current FormSet
295 @return Pointer to a FORMSET_STORAGE data structure.
300 IN FORM_BROWSER_FORMSET
*FormSet
303 FORMSET_STORAGE
*Storage
;
305 Storage
= AllocateZeroPool (sizeof (FORMSET_STORAGE
));
306 ASSERT (Storage
!= NULL
);
307 Storage
->Signature
= FORMSET_STORAGE_SIGNATURE
;
308 InitializeListHead (&Storage
->NameValueListHead
);
309 InsertTailList (&FormSet
->StorageListHead
, &Storage
->Link
);
316 Create ConfigHdr string for a storage.
318 @param FormSet Pointer of the current FormSet
319 @param Storage Pointer of the storage
321 @retval EFI_SUCCESS Initialize ConfigHdr success
325 InitializeConfigHdr (
326 IN FORM_BROWSER_FORMSET
*FormSet
,
327 IN OUT FORMSET_STORAGE
*Storage
334 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) {
335 Name
= Storage
->Name
;
341 Status
= ConstructConfigHdr (
346 FormSet
->DriverHandle
348 if (Status
== EFI_BUFFER_TOO_SMALL
) {
349 Storage
->ConfigHdr
= AllocateZeroPool (StrBufferLen
);
350 Status
= ConstructConfigHdr (
355 FormSet
->DriverHandle
359 if (EFI_ERROR (Status
)) {
363 Storage
->ConfigRequest
= AllocateCopyPool (StrBufferLen
, Storage
->ConfigHdr
);
364 Storage
->SpareStrLen
= 0;
371 Initialize Request Element of a Question. <RequestElement> ::= '&'<BlockName> | '&'<Label>
373 @param FormSet Pointer of the current FormSet.
374 @param Question The Question to be initialized.
376 @retval EFI_SUCCESS Function success.
377 @retval EFI_INVALID_PARAMETER No storage associated with the Question.
381 InitializeRequestElement (
382 IN OUT FORM_BROWSER_FORMSET
*FormSet
,
383 IN OUT FORM_BROWSER_STATEMENT
*Question
386 FORMSET_STORAGE
*Storage
;
390 CHAR16 RequestElement
[30];
392 Storage
= Question
->Storage
;
393 if (Storage
== NULL
) {
394 return EFI_INVALID_PARAMETER
;
397 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
399 // <ConfigRequest> is unnecessary for EFI variable storage,
400 // GetVariable()/SetVariable() will be used to retrieve/save values
406 // Prepare <RequestElement>
408 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
) {
409 StrLen
= UnicodeSPrint (
411 30 * sizeof (CHAR16
),
412 L
"&OFFSET=%x&WIDTH=%x",
413 Question
->VarStoreInfo
.VarOffset
,
414 Question
->StorageWidth
416 Question
->BlockName
= AllocateCopyPool ((StrLen
+ 1) * sizeof (CHAR16
), RequestElement
);
418 StrLen
= UnicodeSPrint (RequestElement
, 30 * sizeof (CHAR16
), L
"&%s", Question
->VariableName
);
421 if ((Question
->Operand
== EFI_IFR_PASSWORD_OP
) && ((Question
->QuestionFlags
& EFI_IFR_FLAG_CALLBACK
) == EFI_IFR_FLAG_CALLBACK
)) {
423 // Password with CALLBACK flag is stored in encoded format,
424 // so don't need to append it to <ConfigRequest>
430 // Append <RequestElement> to <ConfigRequest>
432 if (StrLen
> Storage
->SpareStrLen
) {
434 // Old String buffer is not sufficient for RequestElement, allocate a new one
436 StringSize
= (Storage
->ConfigRequest
!= NULL
) ? StrSize (Storage
->ConfigRequest
) : sizeof (CHAR16
);
437 NewStr
= AllocateZeroPool (StringSize
+ CONFIG_REQUEST_STRING_INCREMENTAL
* sizeof (CHAR16
));
438 ASSERT (NewStr
!= NULL
);
439 if (Storage
->ConfigRequest
!= NULL
) {
440 CopyMem (NewStr
, Storage
->ConfigRequest
, StringSize
);
441 FreePool (Storage
->ConfigRequest
);
443 Storage
->ConfigRequest
= NewStr
;
444 Storage
->SpareStrLen
= CONFIG_REQUEST_STRING_INCREMENTAL
;
447 StrCat (Storage
->ConfigRequest
, RequestElement
);
448 Storage
->ElementCount
++;
449 Storage
->SpareStrLen
-= StrLen
;
456 Free resources of a Expression.
458 @param FormSet Pointer of the Expression
463 IN FORM_EXPRESSION
*Expression
467 EXPRESSION_OPCODE
*OpCode
;
469 while (!IsListEmpty (&Expression
->OpCodeListHead
)) {
470 Link
= GetFirstNode (&Expression
->OpCodeListHead
);
471 OpCode
= EXPRESSION_OPCODE_FROM_LINK (Link
);
472 RemoveEntryList (&OpCode
->Link
);
474 if (OpCode
->ValueList
!= NULL
) {
475 FreePool (OpCode
->ValueList
);
480 // Free this Expression
482 FreePool (Expression
);
487 Free resources of a storage.
489 @param Storage Pointer of the storage
494 IN FORMSET_STORAGE
*Storage
498 NAME_VALUE_NODE
*NameValueNode
;
500 if (Storage
== NULL
) {
504 if (Storage
->Name
!= NULL
) {
505 FreePool (Storage
->Name
);
507 if (Storage
->Buffer
!= NULL
) {
508 FreePool (Storage
->Buffer
);
510 if (Storage
->EditBuffer
!= NULL
) {
511 FreePool (Storage
->EditBuffer
);
514 while (!IsListEmpty (&Storage
->NameValueListHead
)) {
515 Link
= GetFirstNode (&Storage
->NameValueListHead
);
516 NameValueNode
= NAME_VALUE_NODE_FROM_LINK (Link
);
517 RemoveEntryList (&NameValueNode
->Link
);
519 if (NameValueNode
->Name
!= NULL
) {
520 FreePool (NameValueNode
->Name
);
522 if (NameValueNode
->Value
!= NULL
) {
523 FreePool (NameValueNode
->Value
);
525 if (NameValueNode
->EditValue
!= NULL
) {
526 FreePool (NameValueNode
->EditValue
);
528 FreePool (NameValueNode
);
531 if (Storage
->ConfigHdr
!= NULL
) {
532 FreePool (Storage
->ConfigHdr
);
534 if (Storage
->ConfigRequest
!= NULL
) {
535 FreePool (Storage
->ConfigRequest
);
543 Free resources of a Statement.
545 @param Statement Pointer of the Statement
550 IN OUT FORM_BROWSER_STATEMENT
*Statement
554 QUESTION_DEFAULT
*Default
;
555 QUESTION_OPTION
*Option
;
556 FORM_EXPRESSION
*Expression
;
559 // Free Default value List
561 while (!IsListEmpty (&Statement
->DefaultListHead
)) {
562 Link
= GetFirstNode (&Statement
->DefaultListHead
);
563 Default
= QUESTION_DEFAULT_FROM_LINK (Link
);
564 RemoveEntryList (&Default
->Link
);
572 while (!IsListEmpty (&Statement
->OptionListHead
)) {
573 Link
= GetFirstNode (&Statement
->OptionListHead
);
574 Option
= QUESTION_OPTION_FROM_LINK (Link
);
575 RemoveEntryList (&Option
->Link
);
581 // Free Inconsistent List
583 while (!IsListEmpty (&Statement
->InconsistentListHead
)) {
584 Link
= GetFirstNode (&Statement
->InconsistentListHead
);
585 Expression
= FORM_EXPRESSION_FROM_LINK (Link
);
586 RemoveEntryList (&Expression
->Link
);
588 DestroyExpression (Expression
);
592 // Free NoSubmit List
594 while (!IsListEmpty (&Statement
->NoSubmitListHead
)) {
595 Link
= GetFirstNode (&Statement
->NoSubmitListHead
);
596 Expression
= FORM_EXPRESSION_FROM_LINK (Link
);
597 RemoveEntryList (&Expression
->Link
);
599 DestroyExpression (Expression
);
602 if (Statement
->VariableName
!= NULL
) {
603 FreePool (Statement
->VariableName
);
605 if (Statement
->BlockName
!= NULL
) {
606 FreePool (Statement
->BlockName
);
612 Free resources of a Form.
614 @param Form Pointer of the Form.
619 IN OUT FORM_BROWSER_FORM
*Form
623 FORM_EXPRESSION
*Expression
;
624 FORM_BROWSER_STATEMENT
*Statement
;
627 // Free Form Expressions
629 while (!IsListEmpty (&Form
->ExpressionListHead
)) {
630 Link
= GetFirstNode (&Form
->ExpressionListHead
);
631 Expression
= FORM_EXPRESSION_FROM_LINK (Link
);
632 RemoveEntryList (&Expression
->Link
);
634 DestroyExpression (Expression
);
638 // Free Statements/Questions
640 while (!IsListEmpty (&Form
->StatementListHead
)) {
641 Link
= GetFirstNode (&Form
->StatementListHead
);
642 Statement
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
643 RemoveEntryList (&Statement
->Link
);
645 DestroyStatement (Statement
);
656 Free resources allocated for a FormSet.
658 @param FormSet Pointer of the FormSet
663 IN OUT FORM_BROWSER_FORMSET
*FormSet
667 FORMSET_STORAGE
*Storage
;
668 FORMSET_DEFAULTSTORE
*DefaultStore
;
669 FORM_BROWSER_FORM
*Form
;
672 // Free IFR binary buffer
674 FreePool (FormSet
->IfrBinaryData
);
677 // Free FormSet Storage
679 if (FormSet
->StorageListHead
.ForwardLink
!= NULL
) {
680 while (!IsListEmpty (&FormSet
->StorageListHead
)) {
681 Link
= GetFirstNode (&FormSet
->StorageListHead
);
682 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
683 RemoveEntryList (&Storage
->Link
);
685 DestroyStorage (Storage
);
690 // Free FormSet Default Store
692 if (FormSet
->DefaultStoreListHead
.ForwardLink
!= NULL
) {
693 while (!IsListEmpty (&FormSet
->DefaultStoreListHead
)) {
694 Link
= GetFirstNode (&FormSet
->DefaultStoreListHead
);
695 DefaultStore
= FORMSET_DEFAULTSTORE_FROM_LINK (Link
);
696 RemoveEntryList (&DefaultStore
->Link
);
698 FreePool (DefaultStore
);
705 if (FormSet
->FormListHead
.ForwardLink
!= NULL
) {
706 while (!IsListEmpty (&FormSet
->FormListHead
)) {
707 Link
= GetFirstNode (&FormSet
->FormListHead
);
708 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
709 RemoveEntryList (&Form
->Link
);
715 if (FormSet
->StatementBuffer
!= NULL
) {
716 FreePool (FormSet
->StatementBuffer
);
718 if (FormSet
->ExpressionBuffer
!= NULL
) {
719 FreePool (FormSet
->ExpressionBuffer
);
727 Tell whether this Operand is an Expression OpCode or not
729 @param Operand Operand of an IFR OpCode.
731 @retval TRUE This is an Expression OpCode.
732 @retval FALSE Not an Expression OpCode.
740 if (((Operand
>= EFI_IFR_EQ_ID_VAL_OP
) && (Operand
<= EFI_IFR_NOT_OP
)) ||
741 ((Operand
>= EFI_IFR_MATCH_OP
) && (Operand
<= EFI_IFR_SPAN_OP
)) ||
742 (Operand
== EFI_IFR_CATENATE_OP
) ||
743 (Operand
== EFI_IFR_TO_LOWER_OP
) ||
744 (Operand
== EFI_IFR_TO_UPPER_OP
) ||
745 (Operand
== EFI_IFR_VERSION_OP
)
755 Calculate number of Statemens(Questions) and Expression OpCodes.
757 @param FormSet The FormSet to be counted.
758 @param NumberOfStatement Number of Statemens(Questions)
759 @param NumberOfExpression Number of Expression OpCodes
764 IN FORM_BROWSER_FORMSET
*FormSet
,
765 IN OUT UINT16
*NumberOfStatement
,
766 IN OUT UINT16
*NumberOfExpression
769 UINT16 StatementCount
;
770 UINT16 ExpressionCount
;
779 while (Offset
< FormSet
->IfrBinaryLength
) {
780 OpCodeData
= FormSet
->IfrBinaryData
+ Offset
;
781 OpCodeLen
= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
784 if (IsExpressionOpCode (((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
)) {
791 *NumberOfStatement
= StatementCount
;
792 *NumberOfExpression
= ExpressionCount
;
798 Parse opcodes in the formset IFR binary.
800 @param FormSet Pointer of the FormSet data structure.
802 @retval EFI_SUCCESS Opcode parse success.
803 @retval Other Opcode parse fail.
808 IN FORM_BROWSER_FORMSET
*FormSet
813 FORM_BROWSER_FORM
*CurrentForm
;
814 FORM_BROWSER_STATEMENT
*CurrentStatement
;
815 EXPRESSION_OPCODE
*ExpressionOpCode
;
816 FORM_EXPRESSION
*CurrentExpression
;
823 FORMSET_STORAGE
*Storage
;
824 FORMSET_DEFAULTSTORE
*DefaultStore
;
825 QUESTION_DEFAULT
*CurrentDefault
;
826 QUESTION_OPTION
*CurrentOption
;
828 UINT16 NumberOfStatement
;
829 UINT16 NumberOfExpression
;
830 EFI_IMAGE_ID
*ImageId
;
831 BOOLEAN SuppressForOption
;
832 BOOLEAN InScopeOptionSuppress
;
833 FORM_EXPRESSION
*OptionSuppressExpression
;
834 BOOLEAN InScopeDisable
;
835 UINT16 DepthOfDisable
;
836 BOOLEAN OpCodeDisabled
;
837 BOOLEAN SingleOpCodeExpression
;
838 BOOLEAN InScopeDefault
;
839 EFI_HII_VALUE
*Value
;
841 mInScopeSubtitle
= FALSE
;
842 SuppressForOption
= FALSE
;
843 mInScopeSuppress
= FALSE
;
844 InScopeOptionSuppress
= FALSE
;
845 mInScopeGrayOut
= FALSE
;
846 InScopeDisable
= FALSE
;
848 OpCodeDisabled
= FALSE
;
849 SingleOpCodeExpression
= FALSE
;
850 InScopeDefault
= FALSE
;
851 CurrentExpression
= NULL
;
852 CurrentDefault
= NULL
;
853 CurrentOption
= NULL
;
854 OptionSuppressExpression
= NULL
;
858 // Get the number of Statements and Expressions
860 CountOpCodes (FormSet
, &NumberOfStatement
, &NumberOfExpression
);
863 FormSet
->StatementBuffer
= AllocateZeroPool (NumberOfStatement
* sizeof (FORM_BROWSER_STATEMENT
));
864 if (FormSet
->StatementBuffer
== NULL
) {
865 return EFI_OUT_OF_RESOURCES
;
868 mExpressionOpCodeIndex
= 0;
869 FormSet
->ExpressionBuffer
= AllocateZeroPool (NumberOfExpression
* sizeof (EXPRESSION_OPCODE
));
870 if (FormSet
->ExpressionBuffer
== NULL
) {
871 return EFI_OUT_OF_RESOURCES
;
874 InitializeListHead (&FormSet
->StorageListHead
);
875 InitializeListHead (&FormSet
->DefaultStoreListHead
);
876 InitializeListHead (&FormSet
->FormListHead
);
879 CurrentStatement
= NULL
;
884 while (OpCodeOffset
< FormSet
->IfrBinaryLength
) {
885 OpCodeData
= FormSet
->IfrBinaryData
+ OpCodeOffset
;
887 OpCodeLength
= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
888 OpCodeOffset
+= OpCodeLength
;
889 Operand
= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
;
890 Scope
= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Scope
;
893 // If scope bit set, push onto scope stack
899 if (OpCodeDisabled
) {
901 // DisableIf Expression is evaluated to be TRUE, try to find its end.
902 // Here only cares the EFI_IFR_DISABLE_IF and EFI_IFR_END
904 if (Operand
== EFI_IFR_DISABLE_IF_OP
) {
906 } else if (Operand
== EFI_IFR_END_OP
) {
907 Status
= PopScope (&ScopeOpCode
);
908 if (EFI_ERROR (Status
)) {
912 if (ScopeOpCode
== EFI_IFR_DISABLE_IF_OP
) {
913 if (DepthOfDisable
== 0) {
914 InScopeDisable
= FALSE
;
915 OpCodeDisabled
= FALSE
;
924 if (IsExpressionOpCode (Operand
)) {
925 ExpressionOpCode
= &FormSet
->ExpressionBuffer
[mExpressionOpCodeIndex
];
926 mExpressionOpCodeIndex
++;
928 ExpressionOpCode
->Signature
= EXPRESSION_OPCODE_SIGNATURE
;
929 ExpressionOpCode
->Operand
= Operand
;
930 Value
= &ExpressionOpCode
->Value
;
933 case EFI_IFR_EQ_ID_VAL_OP
:
934 CopyMem (&ExpressionOpCode
->QuestionId
, &((EFI_IFR_EQ_ID_VAL
*) OpCodeData
)->QuestionId
, sizeof (EFI_QUESTION_ID
));
936 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_16
;
937 CopyMem (&Value
->Value
.u16
, &((EFI_IFR_EQ_ID_VAL
*) OpCodeData
)->Value
, sizeof (UINT16
));
940 case EFI_IFR_EQ_ID_ID_OP
:
941 CopyMem (&ExpressionOpCode
->QuestionId
, &((EFI_IFR_EQ_ID_ID
*) OpCodeData
)->QuestionId1
, sizeof (EFI_QUESTION_ID
));
942 CopyMem (&ExpressionOpCode
->QuestionId2
, &((EFI_IFR_EQ_ID_ID
*) OpCodeData
)->QuestionId2
, sizeof (EFI_QUESTION_ID
));
945 case EFI_IFR_EQ_ID_LIST_OP
:
946 CopyMem (&ExpressionOpCode
->QuestionId
, &((EFI_IFR_EQ_ID_LIST
*) OpCodeData
)->QuestionId
, sizeof (EFI_QUESTION_ID
));
947 CopyMem (&ExpressionOpCode
->ListLength
, &((EFI_IFR_EQ_ID_LIST
*) OpCodeData
)->ListLength
, sizeof (UINT16
));
948 ExpressionOpCode
->ValueList
= AllocateCopyPool (ExpressionOpCode
->ListLength
* sizeof (UINT16
), &((EFI_IFR_EQ_ID_LIST
*) OpCodeData
)->ValueList
);
951 case EFI_IFR_TO_STRING_OP
:
952 case EFI_IFR_FIND_OP
:
953 ExpressionOpCode
->Format
= (( EFI_IFR_TO_STRING
*) OpCodeData
)->Format
;
956 case EFI_IFR_STRING_REF1_OP
:
957 Value
->Type
= EFI_IFR_TYPE_STRING
;
958 CopyMem (&Value
->Value
.string
, &(( EFI_IFR_STRING_REF1
*) OpCodeData
)->StringId
, sizeof (EFI_STRING_ID
));
961 case EFI_IFR_RULE_REF_OP
:
962 ExpressionOpCode
->RuleId
= (( EFI_IFR_RULE_REF
*) OpCodeData
)->RuleId
;
965 case EFI_IFR_SPAN_OP
:
966 ExpressionOpCode
->Flags
= (( EFI_IFR_SPAN
*) OpCodeData
)->Flags
;
969 case EFI_IFR_THIS_OP
:
970 ASSERT (CurrentStatement
!= NULL
);
971 ExpressionOpCode
->QuestionId
= CurrentStatement
->QuestionId
;
974 case EFI_IFR_QUESTION_REF1_OP
:
975 CopyMem (&ExpressionOpCode
->QuestionId
, &((EFI_IFR_EQ_ID_LIST
*) OpCodeData
)->QuestionId
, sizeof (EFI_QUESTION_ID
));
978 case EFI_IFR_QUESTION_REF3_OP
:
979 if (OpCodeLength
>= sizeof (EFI_IFR_QUESTION_REF3_2
)) {
980 CopyMem (&ExpressionOpCode
->DevicePath
, &(( EFI_IFR_QUESTION_REF3_2
*) OpCodeData
)->DevicePath
, sizeof (EFI_STRING_ID
));
982 if (OpCodeLength
>= sizeof (EFI_IFR_QUESTION_REF3_3
)) {
983 CopyMem (&ExpressionOpCode
->Guid
, &(( EFI_IFR_QUESTION_REF3_3
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
));
991 case EFI_IFR_TRUE_OP
:
992 Value
->Type
= EFI_IFR_TYPE_BOOLEAN
;
993 Value
->Value
.b
= TRUE
;
996 case EFI_IFR_FALSE_OP
:
997 Value
->Type
= EFI_IFR_TYPE_BOOLEAN
;
998 Value
->Value
.b
= FALSE
;
1001 case EFI_IFR_ONE_OP
:
1002 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_8
;
1003 Value
->Value
.u8
= 1;
1006 case EFI_IFR_ZERO_OP
:
1007 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_8
;
1008 Value
->Value
.u8
= 0;
1011 case EFI_IFR_ONES_OP
:
1012 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_64
;
1013 Value
->Value
.u64
= 0xffffffffffffffffULL
;
1016 case EFI_IFR_UINT8_OP
:
1017 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_8
;
1018 Value
->Value
.u8
= (( EFI_IFR_UINT8
*) OpCodeData
)->Value
;
1021 case EFI_IFR_UINT16_OP
:
1022 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_16
;
1023 CopyMem (&Value
->Value
.u16
, &(( EFI_IFR_UINT16
*) OpCodeData
)->Value
, sizeof (UINT16
));
1026 case EFI_IFR_UINT32_OP
:
1027 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_32
;
1028 CopyMem (&Value
->Value
.u32
, &(( EFI_IFR_UINT32
*) OpCodeData
)->Value
, sizeof (UINT32
));
1031 case EFI_IFR_UINT64_OP
:
1032 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_64
;
1033 CopyMem (&Value
->Value
.u64
, &(( EFI_IFR_UINT64
*) OpCodeData
)->Value
, sizeof (UINT64
));
1036 case EFI_IFR_UNDEFINED_OP
:
1037 Value
->Type
= EFI_IFR_TYPE_OTHER
;
1040 case EFI_IFR_VERSION_OP
:
1041 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_16
;
1042 Value
->Value
.u16
= EFI_IFR_SPECIFICATION_VERSION
;
1049 InsertTailList (&CurrentExpression
->OpCodeListHead
, &ExpressionOpCode
->Link
);
1051 if (SingleOpCodeExpression
) {
1053 // There are two cases to indicate the end of an Expression:
1054 // for single OpCode expression: one Expression OpCode
1055 // for expression consists of more than one OpCode: EFI_IFR_END
1057 SingleOpCodeExpression
= FALSE
;
1059 if (InScopeDisable
) {
1061 // Evaluate DisableIf expression
1063 Status
= EvaluateExpression (FormSet
, CurrentForm
, CurrentExpression
);
1064 if (EFI_ERROR (Status
)) {
1068 ASSERT (CurrentExpression
!= NULL
);
1069 if (CurrentExpression
->Result
.Type
!= EFI_IFR_TYPE_BOOLEAN
) {
1070 return EFI_INVALID_PARAMETER
;
1073 OpCodeDisabled
= CurrentExpression
->Result
.Value
.b
;
1076 CurrentExpression
= NULL
;
1087 case EFI_IFR_FORM_SET_OP
:
1089 // check the formset GUID
1091 if (CompareMem (&FormSet
->Guid
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
)) != 0) {
1092 return EFI_INVALID_PARAMETER
;
1095 CopyMem (&FormSet
->FormSetTitle
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->FormSetTitle
, sizeof (EFI_STRING_ID
));
1096 CopyMem (&FormSet
->Help
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Help
, sizeof (EFI_STRING_ID
));
1099 case EFI_IFR_FORM_OP
:
1101 // Create a new Form for this FormSet
1103 CurrentForm
= AllocateZeroPool (sizeof (FORM_BROWSER_FORM
));
1104 ASSERT (CurrentForm
!= NULL
);
1105 CurrentForm
->Signature
= FORM_BROWSER_FORM_SIGNATURE
;
1106 InitializeListHead (&CurrentForm
->ExpressionListHead
);
1107 InitializeListHead (&CurrentForm
->StatementListHead
);
1109 CopyMem (&CurrentForm
->FormId
, &((EFI_IFR_FORM
*) OpCodeData
)->FormId
, sizeof (UINT16
));
1110 CopyMem (&CurrentForm
->FormTitle
, &((EFI_IFR_FORM
*) OpCodeData
)->FormTitle
, sizeof (EFI_STRING_ID
));
1113 // Insert into Form list of this FormSet
1115 InsertTailList (&FormSet
->FormListHead
, &CurrentForm
->Link
);
1121 case EFI_IFR_VARSTORE_OP
:
1123 // Create a buffer Storage for this FormSet
1125 Storage
= CreateStorage (FormSet
);
1126 Storage
->Type
= EFI_HII_VARSTORE_BUFFER
;
1128 CopyMem (&Storage
->VarStoreId
, &((EFI_IFR_VARSTORE
*) OpCodeData
)->VarStoreId
, sizeof (EFI_VARSTORE_ID
));
1129 CopyMem (&Storage
->Guid
, &((EFI_IFR_VARSTORE
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
));
1130 CopyMem (&Storage
->Size
, &((EFI_IFR_VARSTORE
*) OpCodeData
)->Size
, sizeof (UINT16
));
1132 Storage
->Buffer
= AllocateZeroPool (Storage
->Size
);
1133 Storage
->EditBuffer
= AllocateZeroPool (Storage
->Size
);
1135 AsciiString
= (CHAR8
*) ((EFI_IFR_VARSTORE
*) OpCodeData
)->Name
;
1136 Storage
->Name
= AllocateZeroPool (AsciiStrSize (AsciiString
) * 2);
1137 ASSERT (Storage
->Name
!= NULL
);
1138 for (Index
= 0; AsciiString
[Index
] != 0; Index
++) {
1139 Storage
->Name
[Index
] = (CHAR16
) AsciiString
[Index
];
1143 // Initialize <ConfigHdr>
1145 InitializeConfigHdr (FormSet
, Storage
);
1148 case EFI_IFR_VARSTORE_NAME_VALUE_OP
:
1150 // Create a name/value Storage for this FormSet
1152 Storage
= CreateStorage (FormSet
);
1153 Storage
->Type
= EFI_HII_VARSTORE_NAME_VALUE
;
1155 CopyMem (&Storage
->VarStoreId
, &((EFI_IFR_VARSTORE_NAME_VALUE
*) OpCodeData
)->VarStoreId
, sizeof (EFI_VARSTORE_ID
));
1156 CopyMem (&Storage
->Guid
, &((EFI_IFR_VARSTORE_NAME_VALUE
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
));
1159 // Initialize <ConfigHdr>
1161 InitializeConfigHdr (FormSet
, Storage
);
1164 case EFI_IFR_VARSTORE_EFI_OP
:
1166 // Create a EFI variable Storage for this FormSet
1168 Storage
= CreateStorage (FormSet
);
1169 Storage
->Type
= EFI_HII_VARSTORE_EFI_VARIABLE
;
1171 CopyMem (&Storage
->VarStoreId
, &((EFI_IFR_VARSTORE_EFI
*) OpCodeData
)->VarStoreId
, sizeof (EFI_VARSTORE_ID
));
1172 CopyMem (&Storage
->Guid
, &((EFI_IFR_VARSTORE_EFI
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
));
1173 CopyMem (&Storage
->Attributes
, &((EFI_IFR_VARSTORE_EFI
*) OpCodeData
)->Attributes
, sizeof (UINT32
));
1179 case EFI_IFR_DEFAULTSTORE_OP
:
1180 DefaultStore
= AllocateZeroPool (sizeof (FORMSET_DEFAULTSTORE
));
1181 ASSERT (DefaultStore
!= NULL
);
1182 DefaultStore
->Signature
= FORMSET_DEFAULTSTORE_SIGNATURE
;
1184 CopyMem (&DefaultStore
->DefaultId
, &((EFI_IFR_DEFAULTSTORE
*) OpCodeData
)->DefaultId
, sizeof (UINT16
));
1185 CopyMem (&DefaultStore
->DefaultName
, &((EFI_IFR_DEFAULTSTORE
*) OpCodeData
)->DefaultName
, sizeof (EFI_STRING_ID
));
1188 // Insert to DefaultStore list of this Formset
1190 InsertTailList (&FormSet
->DefaultStoreListHead
, &DefaultStore
->Link
);
1196 case EFI_IFR_SUBTITLE_OP
:
1197 CurrentStatement
= CreateStatement (OpCodeData
, FormSet
, CurrentForm
);
1198 ASSERT (CurrentStatement
!= NULL
);
1200 CurrentStatement
->Flags
= ((EFI_IFR_SUBTITLE
*) OpCodeData
)->Flags
;
1203 mInScopeSubtitle
= TRUE
;
1207 case EFI_IFR_TEXT_OP
:
1208 CurrentStatement
= CreateStatement (OpCodeData
, FormSet
, CurrentForm
);
1209 ASSERT (CurrentStatement
!= NULL
);
1211 CopyMem (&CurrentStatement
->TextTwo
, &((EFI_IFR_TEXT
*) OpCodeData
)->TextTwo
, sizeof (EFI_STRING_ID
));
1217 case EFI_IFR_ACTION_OP
:
1218 CurrentStatement
= CreateQuestion (OpCodeData
, FormSet
, CurrentForm
);
1219 ASSERT (CurrentStatement
!= NULL
);
1221 if (OpCodeLength
== sizeof (EFI_IFR_ACTION_1
)) {
1223 // No QuestionConfig present, so no configuration string will be processed
1225 CurrentStatement
->QuestionConfig
= 0;
1227 CopyMem (&CurrentStatement
->QuestionConfig
, &((EFI_IFR_ACTION
*) OpCodeData
)->QuestionConfig
, sizeof (EFI_STRING_ID
));
1231 case EFI_IFR_RESET_BUTTON_OP
:
1232 CurrentStatement
= CreateQuestion (OpCodeData
, FormSet
, CurrentForm
);
1234 CopyMem (&CurrentStatement
->DefaultId
, &((EFI_IFR_RESET_BUTTON
*) OpCodeData
)->DefaultId
, sizeof (EFI_DEFAULT_ID
));
1237 case EFI_IFR_REF_OP
:
1238 CurrentStatement
= CreateQuestion (OpCodeData
, FormSet
, CurrentForm
);
1240 CopyMem (&CurrentStatement
->RefFormId
, &((EFI_IFR_REF
*) OpCodeData
)->FormId
, sizeof (EFI_FORM_ID
));
1241 if (OpCodeLength
>= sizeof (EFI_IFR_REF2
)) {
1242 CopyMem (&CurrentStatement
->RefQuestionId
, &((EFI_IFR_REF2
*) OpCodeData
)->QuestionId
, sizeof (EFI_QUESTION_ID
));
1244 if (OpCodeLength
>= sizeof (EFI_IFR_REF3
)) {
1245 CopyMem (&CurrentStatement
->RefFormSetId
, &((EFI_IFR_REF3
*) OpCodeData
)->FormSetId
, sizeof (EFI_GUID
));
1247 if (OpCodeLength
>= sizeof (EFI_IFR_REF4
)) {
1248 CopyMem (&CurrentStatement
->RefDevicePath
, &((EFI_IFR_REF4
*) OpCodeData
)->DevicePath
, sizeof (EFI_STRING_ID
));
1254 case EFI_IFR_ONE_OF_OP
:
1255 case EFI_IFR_NUMERIC_OP
:
1256 CurrentStatement
= CreateQuestion (OpCodeData
, FormSet
, CurrentForm
);
1258 CurrentStatement
->Flags
= ((EFI_IFR_ONE_OF
*) OpCodeData
)->Flags
;
1259 Value
= &CurrentStatement
->HiiValue
;
1261 switch (CurrentStatement
->Flags
& EFI_IFR_NUMERIC_SIZE
) {
1262 case EFI_IFR_NUMERIC_SIZE_1
:
1263 CurrentStatement
->Minimum
= ((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u8
.MinValue
;
1264 CurrentStatement
->Maximum
= ((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u8
.MaxValue
;
1265 CurrentStatement
->Step
= ((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u8
.Step
;
1266 CurrentStatement
->StorageWidth
= sizeof (UINT8
);
1267 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_8
;
1270 case EFI_IFR_NUMERIC_SIZE_2
:
1271 CopyMem (&CurrentStatement
->Minimum
, &((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u16
.MinValue
, sizeof (UINT16
));
1272 CopyMem (&CurrentStatement
->Maximum
, &((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u16
.MaxValue
, sizeof (UINT16
));
1273 CopyMem (&CurrentStatement
->Step
, &((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u16
.Step
, sizeof (UINT16
));
1274 CurrentStatement
->StorageWidth
= sizeof (UINT16
);
1275 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_16
;
1278 case EFI_IFR_NUMERIC_SIZE_4
:
1279 CopyMem (&CurrentStatement
->Minimum
, &((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u32
.MinValue
, sizeof (UINT32
));
1280 CopyMem (&CurrentStatement
->Maximum
, &((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u32
.MaxValue
, sizeof (UINT32
));
1281 CopyMem (&CurrentStatement
->Step
, &((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u32
.Step
, sizeof (UINT32
));
1282 CurrentStatement
->StorageWidth
= sizeof (UINT32
);
1283 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_32
;
1286 case EFI_IFR_NUMERIC_SIZE_8
:
1287 CopyMem (&CurrentStatement
->Minimum
, &((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u64
.MinValue
, sizeof (UINT64
));
1288 CopyMem (&CurrentStatement
->Maximum
, &((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u64
.MaxValue
, sizeof (UINT64
));
1289 CopyMem (&CurrentStatement
->Step
, &((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u64
.Step
, sizeof (UINT64
));
1290 CurrentStatement
->StorageWidth
= sizeof (UINT64
);
1291 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_64
;
1298 InitializeRequestElement (FormSet
, CurrentStatement
);
1300 if ((Operand
== EFI_IFR_ONE_OF_OP
) && Scope
!= 0) {
1301 SuppressForOption
= TRUE
;
1305 case EFI_IFR_ORDERED_LIST_OP
:
1306 CurrentStatement
= CreateQuestion (OpCodeData
, FormSet
, CurrentForm
);
1308 CurrentStatement
->Flags
= ((EFI_IFR_ORDERED_LIST
*) OpCodeData
)->Flags
;
1309 CurrentStatement
->MaxContainers
= ((EFI_IFR_ORDERED_LIST
*) OpCodeData
)->MaxContainers
;
1310 CurrentStatement
->StorageWidth
= (UINT16
)(CurrentStatement
->MaxContainers
* sizeof (UINT8
));
1311 InitializeRequestElement (FormSet
, CurrentStatement
);
1314 // No buffer type is defined in EFI_IFR_TYPE_VALUE, so a Configuration Driver
1315 // has to use FormBrowser2.Callback() to retrieve the uncommited data for
1316 // an interactive orderedlist (i.e. with EFI_IFR_FLAG_CALLBACK flag set).
1318 CurrentStatement
->HiiValue
.Type
= EFI_IFR_TYPE_OTHER
;
1319 CurrentStatement
->BufferValue
= AllocateZeroPool (CurrentStatement
->StorageWidth
);
1322 SuppressForOption
= TRUE
;
1326 case EFI_IFR_CHECKBOX_OP
:
1327 CurrentStatement
= CreateQuestion (OpCodeData
, FormSet
, CurrentForm
);
1329 CurrentStatement
->Flags
= ((EFI_IFR_CHECKBOX
*) OpCodeData
)->Flags
;
1330 CurrentStatement
->StorageWidth
= sizeof (BOOLEAN
);
1331 CurrentStatement
->HiiValue
.Type
= EFI_IFR_TYPE_BOOLEAN
;
1333 InitializeRequestElement (FormSet
, CurrentStatement
);
1337 case EFI_IFR_STRING_OP
:
1338 CurrentStatement
= CreateQuestion (OpCodeData
, FormSet
, CurrentForm
);
1341 // MinSize is the minimum number of characters that can be accepted for this opcode,
1342 // MaxSize is the maximum number of characters that can be accepted for this opcode.
1343 // The characters are stored as Unicode, so the storage width should multiply 2.
1345 CurrentStatement
->Minimum
= ((EFI_IFR_STRING
*) OpCodeData
)->MinSize
;
1346 CurrentStatement
->Maximum
= ((EFI_IFR_STRING
*) OpCodeData
)->MaxSize
;
1347 CurrentStatement
->StorageWidth
= (UINT16
)((UINTN
) CurrentStatement
->Maximum
* sizeof (CHAR16
));
1348 CurrentStatement
->Flags
= ((EFI_IFR_STRING
*) OpCodeData
)->Flags
;
1350 CurrentStatement
->HiiValue
.Type
= EFI_IFR_TYPE_STRING
;
1351 CurrentStatement
->BufferValue
= AllocateZeroPool (CurrentStatement
->StorageWidth
+ sizeof (CHAR16
));
1353 InitializeRequestElement (FormSet
, CurrentStatement
);
1356 case EFI_IFR_PASSWORD_OP
:
1357 CurrentStatement
= CreateQuestion (OpCodeData
, FormSet
, CurrentForm
);
1360 // MinSize is the minimum number of characters that can be accepted for this opcode,
1361 // MaxSize is the maximum number of characters that can be accepted for this opcode.
1362 // The characters are stored as Unicode, so the storage width should multiply 2.
1364 CopyMem (&CurrentStatement
->Minimum
, &((EFI_IFR_PASSWORD
*) OpCodeData
)->MinSize
, sizeof (UINT16
));
1365 CopyMem (&CurrentStatement
->Maximum
, &((EFI_IFR_PASSWORD
*) OpCodeData
)->MaxSize
, sizeof (UINT16
));
1366 CurrentStatement
->StorageWidth
= (UINT16
)((UINTN
) CurrentStatement
->Maximum
* sizeof (CHAR16
));
1368 CurrentStatement
->HiiValue
.Type
= EFI_IFR_TYPE_STRING
;
1369 CurrentStatement
->BufferValue
= AllocateZeroPool ((CurrentStatement
->StorageWidth
+ sizeof (CHAR16
)));
1371 InitializeRequestElement (FormSet
, CurrentStatement
);
1374 case EFI_IFR_DATE_OP
:
1375 CurrentStatement
= CreateQuestion (OpCodeData
, FormSet
, CurrentForm
);
1377 CurrentStatement
->Flags
= ((EFI_IFR_DATE
*) OpCodeData
)->Flags
;
1378 CurrentStatement
->HiiValue
.Type
= EFI_IFR_TYPE_DATE
;
1380 if ((CurrentStatement
->Flags
& EFI_QF_DATE_STORAGE
) == QF_DATE_STORAGE_NORMAL
) {
1381 CurrentStatement
->StorageWidth
= sizeof (EFI_HII_DATE
);
1383 InitializeRequestElement (FormSet
, CurrentStatement
);
1386 // Don't assign storage for RTC type of date/time
1388 CurrentStatement
->Storage
= NULL
;
1389 CurrentStatement
->StorageWidth
= 0;
1393 case EFI_IFR_TIME_OP
:
1394 CurrentStatement
= CreateQuestion (OpCodeData
, FormSet
, CurrentForm
);
1396 CurrentStatement
->Flags
= ((EFI_IFR_TIME
*) OpCodeData
)->Flags
;
1397 CurrentStatement
->HiiValue
.Type
= EFI_IFR_TYPE_TIME
;
1399 if ((CurrentStatement
->Flags
& QF_TIME_STORAGE
) == QF_TIME_STORAGE_NORMAL
) {
1400 CurrentStatement
->StorageWidth
= sizeof (EFI_IFR_TIME
);
1402 InitializeRequestElement (FormSet
, CurrentStatement
);
1405 // Don't assign storage for RTC type of date/time
1407 CurrentStatement
->Storage
= NULL
;
1408 CurrentStatement
->StorageWidth
= 0;
1415 case EFI_IFR_DEFAULT_OP
:
1417 // EFI_IFR_DEFAULT appear in scope of a Question,
1418 // It creates a default value for the current question.
1419 // A Question may have more than one Default value which have different default types.
1421 CurrentDefault
= AllocateZeroPool (sizeof (QUESTION_DEFAULT
));
1422 ASSERT (CurrentDefault
!= NULL
);
1423 CurrentDefault
->Signature
= QUESTION_DEFAULT_SIGNATURE
;
1425 CurrentDefault
->Value
.Type
= ((EFI_IFR_DEFAULT
*) OpCodeData
)->Type
;
1426 CopyMem (&CurrentDefault
->DefaultId
, &((EFI_IFR_DEFAULT
*) OpCodeData
)->DefaultId
, sizeof (UINT16
));
1427 CopyMem (&CurrentDefault
->Value
.Value
, &((EFI_IFR_DEFAULT
*) OpCodeData
)->Value
, sizeof (EFI_IFR_TYPE_VALUE
));
1428 ExtendValueToU64 (&CurrentDefault
->Value
);
1431 // Insert to Default Value list of current Question
1433 InsertTailList (&CurrentStatement
->DefaultListHead
, &CurrentDefault
->Link
);
1436 InScopeDefault
= TRUE
;
1443 case EFI_IFR_ONE_OF_OPTION_OP
:
1445 // EFI_IFR_ONE_OF_OPTION appear in scope of a Question.
1446 // It create a selection for use in current Question.
1448 CurrentOption
= AllocateZeroPool (sizeof (QUESTION_OPTION
));
1449 ASSERT (CurrentOption
!= NULL
);
1450 CurrentOption
->Signature
= QUESTION_OPTION_SIGNATURE
;
1452 CurrentOption
->Flags
= ((EFI_IFR_ONE_OF_OPTION
*) OpCodeData
)->Flags
;
1453 CurrentOption
->Value
.Type
= ((EFI_IFR_ONE_OF_OPTION
*) OpCodeData
)->Type
;
1454 CopyMem (&CurrentOption
->Text
, &((EFI_IFR_ONE_OF_OPTION
*) OpCodeData
)->Option
, sizeof (EFI_STRING_ID
));
1455 CopyMem (&CurrentOption
->Value
.Value
, &((EFI_IFR_ONE_OF_OPTION
*) OpCodeData
)->Value
, sizeof (EFI_IFR_TYPE_VALUE
));
1456 ExtendValueToU64 (&CurrentOption
->Value
);
1458 if (InScopeOptionSuppress
) {
1459 CurrentOption
->SuppressExpression
= OptionSuppressExpression
;
1463 // Insert to Option list of current Question
1465 InsertTailList (&CurrentStatement
->OptionListHead
, &CurrentOption
->Link
);
1471 case EFI_IFR_NO_SUBMIT_IF_OP
:
1472 case EFI_IFR_INCONSISTENT_IF_OP
:
1474 // Create an Expression node
1476 CurrentExpression
= CreateExpression (CurrentForm
);
1477 CopyMem (&CurrentExpression
->Error
, &((EFI_IFR_INCONSISTENT_IF
*) OpCodeData
)->Error
, sizeof (EFI_STRING_ID
));
1479 if (Operand
== EFI_IFR_NO_SUBMIT_IF_OP
) {
1480 CurrentExpression
->Type
= EFI_HII_EXPRESSION_NO_SUBMIT_IF
;
1481 InsertTailList (&CurrentStatement
->NoSubmitListHead
, &CurrentExpression
->Link
);
1483 CurrentExpression
->Type
= EFI_HII_EXPRESSION_INCONSISTENT_IF
;
1484 InsertTailList (&CurrentStatement
->InconsistentListHead
, &CurrentExpression
->Link
);
1488 case EFI_IFR_SUPPRESS_IF_OP
:
1490 // Question and Option will appear in scope of this OpCode
1492 CurrentExpression
= CreateExpression (CurrentForm
);
1493 CurrentExpression
->Type
= EFI_HII_EXPRESSION_SUPPRESS_IF
;
1494 InsertTailList (&CurrentForm
->ExpressionListHead
, &CurrentExpression
->Link
);
1496 if (SuppressForOption
) {
1497 InScopeOptionSuppress
= TRUE
;
1498 OptionSuppressExpression
= CurrentExpression
;
1500 mInScopeSuppress
= TRUE
;
1501 mSuppressExpression
= CurrentExpression
;
1505 case EFI_IFR_GRAY_OUT_IF_OP
:
1507 // Questions will appear in scope of this OpCode
1509 CurrentExpression
= CreateExpression (CurrentForm
);
1510 CurrentExpression
->Type
= EFI_HII_EXPRESSION_GRAY_OUT_IF
;
1511 InsertTailList (&CurrentForm
->ExpressionListHead
, &CurrentExpression
->Link
);
1513 mInScopeGrayOut
= TRUE
;
1514 mGrayOutExpression
= CurrentExpression
;
1517 case EFI_IFR_DISABLE_IF_OP
:
1519 // The DisableIf expression should only rely on constant, so it could be
1520 // evaluated at initialization and it will not be queued
1522 CurrentExpression
= AllocateZeroPool (sizeof (FORM_EXPRESSION
));
1523 ASSERT (CurrentExpression
!= NULL
);
1524 CurrentExpression
->Signature
= FORM_EXPRESSION_SIGNATURE
;
1525 CurrentExpression
->Type
= EFI_HII_EXPRESSION_DISABLE_IF
;
1526 InitializeListHead (&CurrentExpression
->OpCodeListHead
);
1528 InScopeDisable
= TRUE
;
1529 OpCodeDisabled
= FALSE
;
1532 // Take a look at next OpCode to see whether current expression consists
1535 if (((EFI_IFR_OP_HEADER
*) (OpCodeData
+ OpCodeLength
))->Scope
== 0) {
1536 SingleOpCodeExpression
= TRUE
;
1543 case EFI_IFR_VALUE_OP
:
1544 CurrentExpression
= CreateExpression (CurrentForm
);
1545 CurrentExpression
->Type
= EFI_HII_EXPRESSION_VALUE
;
1546 InsertTailList (&CurrentForm
->ExpressionListHead
, &CurrentExpression
->Link
);
1548 if (InScopeDefault
) {
1550 // Used for default (EFI_IFR_DEFAULT)
1552 CurrentDefault
->ValueExpression
= CurrentExpression
;
1555 // If used for a question, then the question will be read-only
1558 // Make sure CurrentStatement is not NULL.
1559 // If it is NULL, 1) ParseOpCodes functions may parse the IFR wrongly. Or 2) the IFR
1560 // file is wrongly generated by tools such as VFR Compiler. There may be a bug in VFR Compiler.
1562 ASSERT (CurrentStatement
!= NULL
);
1563 CurrentStatement
->ValueExpression
= CurrentExpression
;
1567 case EFI_IFR_RULE_OP
:
1568 CurrentExpression
= CreateExpression (CurrentForm
);
1569 CurrentExpression
->Type
= EFI_HII_EXPRESSION_RULE
;
1571 CurrentExpression
->RuleId
= ((EFI_IFR_RULE
*) OpCodeData
)->RuleId
;
1572 InsertTailList (&CurrentForm
->ExpressionListHead
, &CurrentExpression
->Link
);
1578 case EFI_IFR_IMAGE_OP
:
1580 // Get ScopeOpcode from top of stack
1582 PopScope (&ScopeOpCode
);
1583 PushScope (ScopeOpCode
);
1585 switch (ScopeOpCode
) {
1586 case EFI_IFR_FORM_SET_OP
:
1587 ImageId
= &FormSet
->ImageId
;
1590 case EFI_IFR_FORM_OP
:
1591 ASSERT (CurrentForm
!= NULL
);
1592 ImageId
= &CurrentForm
->ImageId
;
1595 case EFI_IFR_ONE_OF_OPTION_OP
:
1596 ImageId
= &CurrentOption
->ImageId
;
1601 // Make sure CurrentStatement is not NULL.
1602 // If it is NULL, 1) ParseOpCodes functions may parse the IFR wrongly. Or 2) the IFR
1603 // file is wrongly generated by tools such as VFR Compiler.
1605 ASSERT (CurrentStatement
!= NULL
);
1606 ImageId
= &CurrentStatement
->ImageId
;
1610 ASSERT (ImageId
!= NULL
);
1611 CopyMem (ImageId
, &((EFI_IFR_IMAGE
*) OpCodeData
)->Id
, sizeof (EFI_IMAGE_ID
));
1617 case EFI_IFR_REFRESH_OP
:
1618 ASSERT (CurrentStatement
!= NULL
);
1619 CurrentStatement
->RefreshInterval
= ((EFI_IFR_REFRESH
*) OpCodeData
)->RefreshInterval
;
1625 case EFI_IFR_GUID_OP
:
1626 if (CompareGuid (&gTianoHiiIfrGuid
, (EFI_GUID
*)(OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
)))) {
1628 // Tiano specific GUIDed opcodes
1630 switch (((EFI_IFR_GUID_LABEL
*) OpCodeData
)->ExtendOpCode
) {
1631 case EFI_IFR_EXTEND_OP_LABEL
:
1633 // just ignore label
1637 case EFI_IFR_EXTEND_OP_BANNER
:
1638 if (FormSet
->SubClass
== EFI_FRONT_PAGE_SUBCLASS
) {
1640 &BannerData
->Banner
[((EFI_IFR_GUID_BANNER
*) OpCodeData
)->LineNumber
][
1641 ((EFI_IFR_GUID_BANNER
*) OpCodeData
)->Alignment
],
1642 &((EFI_IFR_GUID_BANNER
*) OpCodeData
)->Title
,
1643 sizeof (EFI_STRING_ID
)
1648 case EFI_IFR_EXTEND_OP_CLASS
:
1649 CopyMem (&FormSet
->Class
, &((EFI_IFR_GUID_CLASS
*) OpCodeData
)->Class
, sizeof (UINT16
));
1652 case EFI_IFR_EXTEND_OP_SUBCLASS
:
1653 CopyMem (&FormSet
->SubClass
, &((EFI_IFR_GUID_SUBCLASS
*) OpCodeData
)->SubClass
, sizeof (UINT16
));
1666 case EFI_IFR_END_OP
:
1667 Status
= PopScope (&ScopeOpCode
);
1668 if (EFI_ERROR (Status
)) {
1673 switch (ScopeOpCode
) {
1674 case EFI_IFR_FORM_SET_OP
:
1676 // End of FormSet, update FormSet IFR binary length
1677 // to stop parsing substantial OpCodes
1679 FormSet
->IfrBinaryLength
= OpCodeOffset
;
1682 case EFI_IFR_FORM_OP
:
1689 case EFI_IFR_ONE_OF_OPTION_OP
:
1693 CurrentOption
= NULL
;
1696 case EFI_IFR_SUBTITLE_OP
:
1697 mInScopeSubtitle
= FALSE
;
1700 case EFI_IFR_NO_SUBMIT_IF_OP
:
1701 case EFI_IFR_INCONSISTENT_IF_OP
:
1703 // Ignore end of EFI_IFR_NO_SUBMIT_IF and EFI_IFR_INCONSISTENT_IF
1707 case EFI_IFR_SUPPRESS_IF_OP
:
1708 if (SuppressForOption
) {
1709 InScopeOptionSuppress
= FALSE
;
1711 mInScopeSuppress
= FALSE
;
1715 case EFI_IFR_GRAY_OUT_IF_OP
:
1716 mInScopeGrayOut
= FALSE
;
1719 case EFI_IFR_DISABLE_IF_OP
:
1720 InScopeDisable
= FALSE
;
1721 OpCodeDisabled
= FALSE
;
1724 case EFI_IFR_ONE_OF_OP
:
1725 case EFI_IFR_ORDERED_LIST_OP
:
1726 SuppressForOption
= FALSE
;
1729 case EFI_IFR_DEFAULT_OP
:
1730 InScopeDefault
= FALSE
;
1734 if (IsExpressionOpCode (ScopeOpCode
)) {
1735 if (InScopeDisable
) {
1737 // Evaluate DisableIf expression
1739 Status
= EvaluateExpression (FormSet
, CurrentForm
, CurrentExpression
);
1740 if (EFI_ERROR (Status
)) {
1744 ASSERT (CurrentExpression
!= NULL
);
1745 if (CurrentExpression
->Result
.Type
!= EFI_IFR_TYPE_BOOLEAN
) {
1746 return EFI_INVALID_PARAMETER
;
1749 OpCodeDisabled
= CurrentExpression
->Result
.Value
.b
;
1751 // DisableIf Expression is only used once and not quequed, free it
1753 DestroyExpression (CurrentExpression
);
1757 // End of current Expression
1759 CurrentExpression
= NULL
;