2 Parser for IFR binary encoding.
4 Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
5 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.
17 UINT16 mStatementIndex
;
18 UINT16 mExpressionOpCodeIndex
;
19 EFI_QUESTION_ID mUsedQuestionId
;
20 extern LIST_ENTRY gBrowserStorageList
;
22 Initialize Statement header members.
24 @param OpCodeData Pointer of the raw OpCode data.
25 @param FormSet Pointer of the current FormSet.
26 @param Form Pointer of the current Form.
28 @return The Statement.
31 FORM_BROWSER_STATEMENT
*
34 IN OUT FORM_BROWSER_FORMSET
*FormSet
,
35 IN OUT FORM_BROWSER_FORM
*Form
38 FORM_BROWSER_STATEMENT
*Statement
;
39 EFI_IFR_STATEMENT_HEADER
*StatementHdr
;
40 INTN ConditionalExprCount
;
44 // Only guid op may out side the form level.
46 ASSERT (((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
== EFI_IFR_GUID_OP
);
49 Statement
= &FormSet
->StatementBuffer
[mStatementIndex
];
52 InitializeListHead (&Statement
->DefaultListHead
);
53 InitializeListHead (&Statement
->OptionListHead
);
54 InitializeListHead (&Statement
->InconsistentListHead
);
55 InitializeListHead (&Statement
->NoSubmitListHead
);
56 InitializeListHead (&Statement
->WarningListHead
);
58 Statement
->Signature
= FORM_BROWSER_STATEMENT_SIGNATURE
;
60 Statement
->Operand
= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
;
61 Statement
->OpCode
= (EFI_IFR_OP_HEADER
*) OpCodeData
;
62 Statement
->QuestionReferToBitField
= FALSE
;
64 StatementHdr
= (EFI_IFR_STATEMENT_HEADER
*) (OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
));
65 CopyMem (&Statement
->Prompt
, &StatementHdr
->Prompt
, sizeof (EFI_STRING_ID
));
66 CopyMem (&Statement
->Help
, &StatementHdr
->Help
, sizeof (EFI_STRING_ID
));
68 ConditionalExprCount
= GetConditionalExpressionCount(ExpressStatement
);
69 if (ConditionalExprCount
> 0) {
71 // Form is inside of suppressif
74 Statement
->Expression
= (FORM_EXPRESSION_LIST
*) AllocatePool(
75 (UINTN
) (sizeof(FORM_EXPRESSION_LIST
) + ((ConditionalExprCount
-1) * sizeof(FORM_EXPRESSION
*))));
76 ASSERT (Statement
->Expression
!= NULL
);
77 Statement
->Expression
->Count
= (UINTN
) ConditionalExprCount
;
78 Statement
->Expression
->Signature
= FORM_EXPRESSION_LIST_SIGNATURE
;
79 CopyMem (Statement
->Expression
->Expression
, GetConditionalExpressionList(ExpressStatement
), (UINTN
) (sizeof (FORM_EXPRESSION
*) * ConditionalExprCount
));
83 // Insert this Statement into current Form
86 InsertTailList (&FormSet
->StatementListOSF
, &Statement
->Link
);
88 InsertTailList (&Form
->StatementListHead
, &Statement
->Link
);
94 Convert a numeric value to a Unicode String and insert it to String Package.
95 This string is used as the Unicode Name for the EFI Variable. This is to support
96 the deprecated vareqval opcode.
98 @param FormSet The FormSet.
99 @param Statement The numeric question whose VarStoreInfo.VarName is the
100 numeric value which is used to produce the Unicode Name
101 for the EFI Variable.
103 If the Statement is NULL, the ASSERT.
104 If the opcode is not Numeric, then ASSERT.
106 @retval EFI_SUCCESS The funtion always succeeds.
109 UpdateCheckBoxStringToken (
110 IN CONST FORM_BROWSER_FORMSET
*FormSet
,
111 IN FORM_BROWSER_STATEMENT
*Statement
114 CHAR16 Str
[MAXIMUM_VALUE_CHARACTERS
];
117 ASSERT (Statement
!= NULL
);
118 ASSERT (Statement
->Operand
== EFI_IFR_NUMERIC_OP
);
120 UnicodeValueToStringS (Str
, sizeof (Str
), 0, Statement
->VarStoreInfo
.VarName
, MAXIMUM_VALUE_CHARACTERS
- 1);
122 Id
= HiiSetString (FormSet
->HiiHandle
, 0, Str
, NULL
);
124 return EFI_OUT_OF_RESOURCES
;
127 Statement
->VarStoreInfo
.VarName
= Id
;
133 Check if the next opcode is the EFI_IFR_EXTEND_OP_VAREQNAME.
135 @param OpCodeData The current opcode.
141 IsNextOpCodeGuidedVarEqName (
148 OpCodeData
+= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
149 if (*OpCodeData
== EFI_IFR_GUID_OP
) {
150 if (CompareGuid (&gEfiIfrFrameworkGuid
, (EFI_GUID
*)(OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
)))) {
152 // Specific GUIDed opcodes to support IFR generated from Framework HII VFR
154 if ((((EFI_IFR_GUID_VAREQNAME
*) OpCodeData
)->ExtendOpCode
) == EFI_IFR_EXTEND_OP_VAREQNAME
) {
164 Initialize Question's members.
166 @param OpCodeData Pointer of the raw OpCode data.
167 @param FormSet Pointer of the current FormSet.
168 @param Form Pointer of the current Form.
170 @return The Question.
173 FORM_BROWSER_STATEMENT
*
175 IN UINT8
*OpCodeData
,
176 IN OUT FORM_BROWSER_FORMSET
*FormSet
,
177 IN OUT FORM_BROWSER_FORM
*Form
180 FORM_BROWSER_STATEMENT
*Statement
;
181 EFI_IFR_QUESTION_HEADER
*QuestionHdr
;
183 FORMSET_STORAGE
*Storage
;
184 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 (PcdFrameworkCompatibilitySupport
)) {
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
->BrowserStorage
;
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 // Check whether old string node already exist.
249 if (!IsListEmpty(&Statement
->Storage
->NameValueListHead
)) {
250 Link
= GetFirstNode (&Statement
->Storage
->NameValueListHead
);
251 while (!IsNull (&Statement
->Storage
->NameValueListHead
, Link
)) {
252 NameValueNode
= NAME_VALUE_NODE_FROM_LINK (Link
);
254 if (StrCmp (Statement
->VariableName
, NameValueNode
->Name
) == 0) {
259 Link
= GetNextNode (&Statement
->Storage
->NameValueListHead
, Link
);
265 // Insert to Name/Value varstore list
267 NameValueNode
= AllocateZeroPool (sizeof (NAME_VALUE_NODE
));
268 ASSERT (NameValueNode
!= NULL
);
269 NameValueNode
->Signature
= NAME_VALUE_NODE_SIGNATURE
;
270 NameValueNode
->Name
= AllocateCopyPool (StrSize (Statement
->VariableName
), Statement
->VariableName
);
271 ASSERT (NameValueNode
->Name
!= NULL
);
272 NameValueNode
->Value
= AllocateZeroPool (0x10);
273 ASSERT (NameValueNode
->Value
!= NULL
);
274 NameValueNode
->EditValue
= AllocateZeroPool (0x10);
275 ASSERT (NameValueNode
->EditValue
!= NULL
);
277 InsertTailList (&Statement
->Storage
->NameValueListHead
, &NameValueNode
->Link
);
287 Allocate a FORM_EXPRESSION node.
289 @param Form The Form associated with this Expression
290 @param OpCode The binary opcode data.
292 @return Pointer to a FORM_EXPRESSION data structure.
297 IN OUT FORM_BROWSER_FORM
*Form
,
301 FORM_EXPRESSION
*Expression
;
303 Expression
= AllocateZeroPool (sizeof (FORM_EXPRESSION
));
304 ASSERT (Expression
!= NULL
);
305 Expression
->Signature
= FORM_EXPRESSION_SIGNATURE
;
306 InitializeListHead (&Expression
->OpCodeListHead
);
307 Expression
->OpCode
= (EFI_IFR_OP_HEADER
*) OpCode
;
313 Create ConfigHdr string for a storage.
315 @param FormSet Pointer of the current FormSet
316 @param Storage Pointer of the storage
318 @retval EFI_SUCCESS Initialize ConfigHdr success
322 InitializeConfigHdr (
323 IN FORM_BROWSER_FORMSET
*FormSet
,
324 IN OUT FORMSET_STORAGE
*Storage
329 if (Storage
->BrowserStorage
->Type
== EFI_HII_VARSTORE_BUFFER
||
330 Storage
->BrowserStorage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
) {
331 Name
= Storage
->BrowserStorage
->Name
;
336 Storage
->ConfigHdr
= HiiConstructConfigHdr (
337 &Storage
->BrowserStorage
->Guid
,
339 FormSet
->DriverHandle
342 if (Storage
->ConfigHdr
== NULL
) {
343 return EFI_NOT_FOUND
;
350 Find the global storage link base on the input storate type, name and guid.
352 For EFI_HII_VARSTORE_EFI_VARIABLE and EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER,
353 same guid + name = same storage
355 For EFI_HII_VARSTORE_NAME_VALUE:
356 same guid + HiiHandle = same storage
358 For EFI_HII_VARSTORE_BUFFER:
359 same guid + name + HiiHandle = same storage
361 @param StorageType Storage type.
362 @param StorageGuid Storage guid.
363 @param StorageName Storage Name.
364 @param HiiHandle HiiHandle for this varstore.
366 @return Pointer to a GLOBAL_STORAGE data structure.
371 IN UINT8 StorageType
,
372 IN EFI_GUID
*StorageGuid
,
373 IN CHAR16
*StorageName
,
374 IN EFI_HII_HANDLE HiiHandle
378 BROWSER_STORAGE
*BrowserStorage
;
380 Link
= GetFirstNode (&gBrowserStorageList
);
381 while (!IsNull (&gBrowserStorageList
, Link
)) {
382 BrowserStorage
= BROWSER_STORAGE_FROM_LINK (Link
);
383 Link
= GetNextNode (&gBrowserStorageList
, Link
);
385 if ((BrowserStorage
->Type
== StorageType
) && CompareGuid (&BrowserStorage
->Guid
, StorageGuid
)) {
386 if (StorageType
== EFI_HII_VARSTORE_NAME_VALUE
) {
387 if (BrowserStorage
->HiiHandle
== HiiHandle
) {
388 return BrowserStorage
;
394 ASSERT (StorageName
!= NULL
);
395 if (StrCmp (BrowserStorage
->Name
, StorageName
) == 0) {
396 if (StorageType
== EFI_HII_VARSTORE_EFI_VARIABLE
|| StorageType
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
) {
397 return BrowserStorage
;
398 } else if (StorageType
== EFI_HII_VARSTORE_BUFFER
&& BrowserStorage
->HiiHandle
== HiiHandle
) {
399 return BrowserStorage
;
409 Intialize the Global Storage.
411 @param BrowserStorage Pointer to the global storage.
412 @param StorageType Storage type.
413 @param OpCodeData Binary data for this opcode.
417 IntializeBrowserStorage (
418 IN BROWSER_STORAGE
*BrowserStorage
,
419 IN UINT8 StorageType
,
423 switch (StorageType
) {
424 case EFI_HII_VARSTORE_BUFFER
:
425 CopyMem (&BrowserStorage
->Guid
, &((EFI_IFR_VARSTORE
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
));
426 CopyMem (&BrowserStorage
->Size
, &((EFI_IFR_VARSTORE
*) OpCodeData
)->Size
, sizeof (UINT16
));
428 BrowserStorage
->Buffer
= AllocateZeroPool (BrowserStorage
->Size
);
429 BrowserStorage
->EditBuffer
= AllocateZeroPool (BrowserStorage
->Size
);
432 case EFI_HII_VARSTORE_EFI_VARIABLE
:
433 case EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
:
434 CopyMem (&BrowserStorage
->Guid
, &((EFI_IFR_VARSTORE_EFI
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
));
435 CopyMem (&BrowserStorage
->Attributes
, &((EFI_IFR_VARSTORE_EFI
*) OpCodeData
)->Attributes
, sizeof (UINT32
));
436 CopyMem (&BrowserStorage
->Size
, &((EFI_IFR_VARSTORE_EFI
*) OpCodeData
)->Size
, sizeof (UINT16
));
438 if (StorageType
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
) {
439 BrowserStorage
->Buffer
= AllocateZeroPool (BrowserStorage
->Size
);
440 BrowserStorage
->EditBuffer
= AllocateZeroPool (BrowserStorage
->Size
);
444 case EFI_HII_VARSTORE_NAME_VALUE
:
445 CopyMem (&BrowserStorage
->Guid
, &((EFI_IFR_VARSTORE_NAME_VALUE
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
));
447 InitializeListHead (&BrowserStorage
->NameValueListHead
);
457 Allocate a FORMSET_STORAGE data structure and insert to FormSet Storage List.
459 @param FormSet Pointer of the current FormSet
460 @param StorageType Storage type.
461 @param OpCodeData Binary data for this opcode.
463 @return Pointer to a FORMSET_STORAGE data structure.
468 IN FORM_BROWSER_FORMSET
*FormSet
,
469 IN UINT8 StorageType
,
473 FORMSET_STORAGE
*Storage
;
474 CHAR16
*UnicodeString
;
476 BROWSER_STORAGE
*BrowserStorage
;
477 EFI_GUID
*StorageGuid
;
480 UnicodeString
= NULL
;
482 switch (StorageType
) {
483 case EFI_HII_VARSTORE_BUFFER
:
484 StorageGuid
= (EFI_GUID
*) (CHAR8
*) &((EFI_IFR_VARSTORE
*) OpCodeData
)->Guid
;
485 StorageName
= (CHAR8
*) ((EFI_IFR_VARSTORE
*) OpCodeData
)->Name
;
488 case EFI_HII_VARSTORE_EFI_VARIABLE
:
489 case EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
:
490 StorageGuid
= (EFI_GUID
*) (CHAR8
*) &((EFI_IFR_VARSTORE_EFI
*) OpCodeData
)->Guid
;
491 StorageName
= (CHAR8
*) ((EFI_IFR_VARSTORE_EFI
*) OpCodeData
)->Name
;
495 ASSERT (StorageType
== EFI_HII_VARSTORE_NAME_VALUE
);
496 StorageGuid
= &((EFI_IFR_VARSTORE_NAME_VALUE
*) OpCodeData
)->Guid
;
500 if (StorageType
!= EFI_HII_VARSTORE_NAME_VALUE
) {
501 ASSERT (StorageName
!= NULL
);
503 UnicodeString
= AllocateZeroPool (AsciiStrSize (StorageName
) * 2);
504 ASSERT (UnicodeString
!= NULL
);
505 for (Index
= 0; StorageName
[Index
] != 0; Index
++) {
506 UnicodeString
[Index
] = (CHAR16
) StorageName
[Index
];
510 Storage
= AllocateZeroPool (sizeof (FORMSET_STORAGE
));
511 ASSERT (Storage
!= NULL
);
512 Storage
->Signature
= FORMSET_STORAGE_SIGNATURE
;
513 InsertTailList (&FormSet
->StorageListHead
, &Storage
->Link
);
515 BrowserStorage
= FindStorageInList(StorageType
, StorageGuid
, UnicodeString
, FormSet
->HiiHandle
);
516 if (BrowserStorage
== NULL
) {
517 BrowserStorage
= AllocateZeroPool (sizeof (BROWSER_STORAGE
));
518 ASSERT (BrowserStorage
!= NULL
);
520 BrowserStorage
->Signature
= BROWSER_STORAGE_SIGNATURE
;
521 InsertTailList (&gBrowserStorageList
, &BrowserStorage
->Link
);
523 IntializeBrowserStorage (BrowserStorage
, StorageType
, OpCodeData
);
524 BrowserStorage
->Type
= StorageType
;
525 if (StorageType
!= EFI_HII_VARSTORE_NAME_VALUE
) {
526 BrowserStorage
->Name
= UnicodeString
;
529 BrowserStorage
->HiiHandle
= FormSet
->HiiHandle
;
531 BrowserStorage
->Initialized
= FALSE
;
534 Storage
->BrowserStorage
= BrowserStorage
;
535 InitializeConfigHdr (FormSet
, Storage
);
536 Storage
->ConfigRequest
= AllocateCopyPool (StrSize (Storage
->ConfigHdr
), Storage
->ConfigHdr
);
537 Storage
->SpareStrLen
= 0;
543 Get Formset_storage base on the input varstoreid info.
545 @param FormSet Pointer of the current FormSet.
546 @param VarStoreId Varstore ID info.
548 @return Pointer to a FORMSET_STORAGE data structure.
553 IN FORM_BROWSER_FORMSET
*FormSet
,
554 IN EFI_VARSTORE_ID VarStoreId
557 FORMSET_STORAGE
*FormsetStorage
;
562 FormsetStorage
= NULL
;
564 // Find Formset Storage for this Question
566 Link
= GetFirstNode (&FormSet
->StorageListHead
);
567 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
568 FormsetStorage
= FORMSET_STORAGE_FROM_LINK (Link
);
570 if (FormsetStorage
->VarStoreId
== VarStoreId
) {
575 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
578 return Found
? FormsetStorage
: NULL
;
582 Get Formset_storage base on the input browser storage.
584 More than one formsets may share the same browser storage,
585 this function just get the first formset storage which
586 share the browser storage.
588 @param Storage browser storage info.
590 @return Pointer to a FORMSET_STORAGE data structure.
595 GetFstStgFromBrsStg (
596 IN BROWSER_STORAGE
*Storage
599 FORMSET_STORAGE
*FormsetStorage
;
601 LIST_ENTRY
*FormsetLink
;
602 FORM_BROWSER_FORMSET
*FormSet
;
606 FormsetStorage
= NULL
;
608 FormsetLink
= GetFirstNode (&gBrowserFormSetList
);
609 while (!IsNull (&gBrowserFormSetList
, FormsetLink
)) {
610 FormSet
= FORM_BROWSER_FORMSET_FROM_LINK (FormsetLink
);
611 FormsetLink
= GetNextNode (&gBrowserFormSetList
, FormsetLink
);
613 Link
= GetFirstNode (&FormSet
->StorageListHead
);
614 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
615 FormsetStorage
= FORMSET_STORAGE_FROM_LINK (Link
);
616 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
618 if (FormsetStorage
->BrowserStorage
== Storage
) {
629 return Found
? FormsetStorage
: NULL
;
633 Initialize Request Element of a Question. <RequestElement> ::= '&'<BlockName> | '&'<Label>
635 @param FormSet Pointer of the current FormSet.
636 @param Question The Question to be initialized.
637 @param Form Pointer of the current form.
639 @retval EFI_SUCCESS Function success.
640 @retval EFI_INVALID_PARAMETER No storage associated with the Question.
644 InitializeRequestElement (
645 IN OUT FORM_BROWSER_FORMSET
*FormSet
,
646 IN OUT FORM_BROWSER_STATEMENT
*Question
,
647 IN OUT FORM_BROWSER_FORM
*Form
650 BROWSER_STORAGE
*Storage
;
651 FORMSET_STORAGE
*FormsetStorage
;
655 CHAR16 RequestElement
[30];
658 FORM_BROWSER_CONFIG_REQUEST
*ConfigInfo
;
661 Storage
= Question
->Storage
;
662 if (Storage
== NULL
) {
663 return EFI_INVALID_PARAMETER
;
666 if (Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
) {
668 // <ConfigRequest> is unnecessary for EFI variable storage,
669 // GetVariable()/SetVariable() will be used to retrieve/save values
675 // Prepare <RequestElement>
677 if (Storage
->Type
== EFI_HII_VARSTORE_BUFFER
||
678 Storage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
) {
679 StrLen
= UnicodeSPrint (
681 30 * sizeof (CHAR16
),
682 L
"&OFFSET=%04x&WIDTH=%04x",
683 Question
->VarStoreInfo
.VarOffset
,
684 Question
->StorageWidth
686 HiiToLower(RequestElement
);
687 Question
->BlockName
= AllocateCopyPool ((StrLen
+ 1) * sizeof (CHAR16
), RequestElement
);
689 StrLen
= UnicodeSPrint (RequestElement
, 30 * sizeof (CHAR16
), L
"&%s", Question
->VariableName
);
692 if ((Question
->Operand
== EFI_IFR_PASSWORD_OP
) && ((Question
->QuestionFlags
& EFI_IFR_FLAG_CALLBACK
) == EFI_IFR_FLAG_CALLBACK
)) {
694 // Password with CALLBACK flag is stored in encoded format,
695 // so don't need to append it to <ConfigRequest>
701 // Find Formset Storage for this Question
703 FormsetStorage
= GetFstStgFromVarId(FormSet
, Question
->VarStoreId
);
704 ASSERT (FormsetStorage
!= NULL
);
705 StringSize
= (FormsetStorage
->ConfigRequest
!= NULL
) ? StrSize (FormsetStorage
->ConfigRequest
) : sizeof (CHAR16
);
706 MaxLen
= StringSize
/ sizeof (CHAR16
) + FormsetStorage
->SpareStrLen
;
709 // Append <RequestElement> to <ConfigRequest>
711 if (StrLen
> FormsetStorage
->SpareStrLen
) {
713 // Old String buffer is not sufficient for RequestElement, allocate a new one
715 MaxLen
= StringSize
/ sizeof (CHAR16
) + CONFIG_REQUEST_STRING_INCREMENTAL
;
716 NewStr
= AllocateZeroPool (MaxLen
* sizeof (CHAR16
));
717 ASSERT (NewStr
!= NULL
);
718 if (FormsetStorage
->ConfigRequest
!= NULL
) {
719 CopyMem (NewStr
, FormsetStorage
->ConfigRequest
, StringSize
);
720 FreePool (FormsetStorage
->ConfigRequest
);
722 FormsetStorage
->ConfigRequest
= NewStr
;
723 FormsetStorage
->SpareStrLen
= CONFIG_REQUEST_STRING_INCREMENTAL
;
726 StrCatS (FormsetStorage
->ConfigRequest
, MaxLen
, RequestElement
);
727 FormsetStorage
->ElementCount
++;
728 FormsetStorage
->SpareStrLen
-= StrLen
;
731 // Update the Config Request info saved in the form.
735 Link
= GetFirstNode (&Form
->ConfigRequestHead
);
736 while (!IsNull (&Form
->ConfigRequestHead
, Link
)) {
737 ConfigInfo
= FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link
);
739 if (ConfigInfo
!= NULL
&& ConfigInfo
->Storage
== FormsetStorage
->BrowserStorage
) {
744 Link
= GetNextNode (&Form
->ConfigRequestHead
, Link
);
748 ConfigInfo
= AllocateZeroPool(sizeof (FORM_BROWSER_CONFIG_REQUEST
));
749 ASSERT (ConfigInfo
!= NULL
);
750 ConfigInfo
->Signature
= FORM_BROWSER_CONFIG_REQUEST_SIGNATURE
;
751 ConfigInfo
->ConfigRequest
= AllocateCopyPool (StrSize (FormsetStorage
->ConfigHdr
), FormsetStorage
->ConfigHdr
);
752 ASSERT (ConfigInfo
->ConfigRequest
!= NULL
);
753 ConfigInfo
->SpareStrLen
= 0;
754 ConfigInfo
->Storage
= FormsetStorage
->BrowserStorage
;
755 InsertTailList(&Form
->ConfigRequestHead
, &ConfigInfo
->Link
);
757 StringSize
= (ConfigInfo
->ConfigRequest
!= NULL
) ? StrSize (ConfigInfo
->ConfigRequest
) : sizeof (CHAR16
);
758 MaxLen
= StringSize
/ sizeof (CHAR16
) + ConfigInfo
->SpareStrLen
;
761 // Append <RequestElement> to <ConfigRequest>
763 if (StrLen
> ConfigInfo
->SpareStrLen
) {
765 // Old String buffer is not sufficient for RequestElement, allocate a new one
767 MaxLen
= StringSize
/ sizeof (CHAR16
) + CONFIG_REQUEST_STRING_INCREMENTAL
;
768 NewStr
= AllocateZeroPool (MaxLen
* sizeof (CHAR16
));
769 ASSERT (NewStr
!= NULL
);
770 if (ConfigInfo
->ConfigRequest
!= NULL
) {
771 CopyMem (NewStr
, ConfigInfo
->ConfigRequest
, StringSize
);
772 FreePool (ConfigInfo
->ConfigRequest
);
774 ConfigInfo
->ConfigRequest
= NewStr
;
775 ConfigInfo
->SpareStrLen
= CONFIG_REQUEST_STRING_INCREMENTAL
;
778 StrCatS (ConfigInfo
->ConfigRequest
, MaxLen
, RequestElement
);
779 ConfigInfo
->ElementCount
++;
780 ConfigInfo
->SpareStrLen
-= StrLen
;
786 Free resources of a Expression.
788 @param FormSet Pointer of the Expression
793 IN FORM_EXPRESSION
*Expression
797 EXPRESSION_OPCODE
*OpCode
;
798 LIST_ENTRY
*SubExpressionLink
;
799 FORM_EXPRESSION
*SubExpression
;
801 while (!IsListEmpty (&Expression
->OpCodeListHead
)) {
802 Link
= GetFirstNode (&Expression
->OpCodeListHead
);
803 OpCode
= EXPRESSION_OPCODE_FROM_LINK (Link
);
804 RemoveEntryList (&OpCode
->Link
);
806 if (OpCode
->ValueList
!= NULL
) {
807 FreePool (OpCode
->ValueList
);
810 if (OpCode
->ValueName
!= NULL
) {
811 FreePool (OpCode
->ValueName
);
814 if (OpCode
->MapExpressionList
.ForwardLink
!= NULL
) {
815 while (!IsListEmpty (&OpCode
->MapExpressionList
)) {
816 SubExpressionLink
= GetFirstNode(&OpCode
->MapExpressionList
);
817 SubExpression
= FORM_EXPRESSION_FROM_LINK (SubExpressionLink
);
818 RemoveEntryList(&SubExpression
->Link
);
819 DestroyExpression (SubExpression
);
825 // Free this Expression
827 FreePool (Expression
);
831 Free resources of a storage.
833 @param Storage Pointer of the storage
838 IN FORMSET_STORAGE
*Storage
841 if (Storage
== NULL
) {
845 if (Storage
->ConfigRequest
!= NULL
) {
846 FreePool (Storage
->ConfigRequest
);
854 Free resources of a Statement.
856 @param FormSet Pointer of the FormSet
857 @param Statement Pointer of the Statement
862 IN FORM_BROWSER_FORMSET
*FormSet
,
863 IN OUT FORM_BROWSER_STATEMENT
*Statement
867 QUESTION_DEFAULT
*Default
;
868 QUESTION_OPTION
*Option
;
869 FORM_EXPRESSION
*Expression
;
872 // Free Default value List
874 while (!IsListEmpty (&Statement
->DefaultListHead
)) {
875 Link
= GetFirstNode (&Statement
->DefaultListHead
);
876 Default
= QUESTION_DEFAULT_FROM_LINK (Link
);
877 RemoveEntryList (&Default
->Link
);
879 if (Default
->Value
.Buffer
!= NULL
) {
880 FreePool (Default
->Value
.Buffer
);
888 while (!IsListEmpty (&Statement
->OptionListHead
)) {
889 Link
= GetFirstNode (&Statement
->OptionListHead
);
890 Option
= QUESTION_OPTION_FROM_LINK (Link
);
891 if (Option
->SuppressExpression
!= NULL
) {
892 FreePool (Option
->SuppressExpression
);
894 RemoveEntryList (&Option
->Link
);
900 // Free Inconsistent List
902 while (!IsListEmpty (&Statement
->InconsistentListHead
)) {
903 Link
= GetFirstNode (&Statement
->InconsistentListHead
);
904 Expression
= FORM_EXPRESSION_FROM_LINK (Link
);
905 RemoveEntryList (&Expression
->Link
);
907 DestroyExpression (Expression
);
911 // Free NoSubmit List
913 while (!IsListEmpty (&Statement
->NoSubmitListHead
)) {
914 Link
= GetFirstNode (&Statement
->NoSubmitListHead
);
915 Expression
= FORM_EXPRESSION_FROM_LINK (Link
);
916 RemoveEntryList (&Expression
->Link
);
918 DestroyExpression (Expression
);
922 // Free WarningIf List
924 while (!IsListEmpty (&Statement
->WarningListHead
)) {
925 Link
= GetFirstNode (&Statement
->WarningListHead
);
926 Expression
= FORM_EXPRESSION_FROM_LINK (Link
);
927 RemoveEntryList (&Expression
->Link
);
929 DestroyExpression (Expression
);
932 if (Statement
->Expression
!= NULL
) {
933 FreePool (Statement
->Expression
);
936 if (Statement
->VariableName
!= NULL
) {
937 FreePool (Statement
->VariableName
);
939 if (Statement
->BlockName
!= NULL
) {
940 FreePool (Statement
->BlockName
);
942 if (Statement
->BufferValue
!= NULL
) {
943 FreePool (Statement
->BufferValue
);
945 if (Statement
->Operand
== EFI_IFR_STRING_OP
|| Statement
->Operand
== EFI_IFR_PASSWORD_OP
) {
946 DeleteString(Statement
->HiiValue
.Value
.string
, FormSet
->HiiHandle
);
952 Free resources of a Form.
954 @param FormSet Pointer of the FormSet
955 @param Form Pointer of the Form.
960 IN FORM_BROWSER_FORMSET
*FormSet
,
961 IN OUT FORM_BROWSER_FORM
*Form
965 FORM_EXPRESSION
*Expression
;
966 FORM_BROWSER_STATEMENT
*Statement
;
967 FORM_BROWSER_CONFIG_REQUEST
*ConfigInfo
;
970 // Free Form Expressions
972 while (!IsListEmpty (&Form
->ExpressionListHead
)) {
973 Link
= GetFirstNode (&Form
->ExpressionListHead
);
974 Expression
= FORM_EXPRESSION_FROM_LINK (Link
);
975 RemoveEntryList (&Expression
->Link
);
977 DestroyExpression (Expression
);
981 // Free Statements/Questions
983 while (!IsListEmpty (&Form
->StatementListHead
)) {
984 Link
= GetFirstNode (&Form
->StatementListHead
);
985 Statement
= FORM_BROWSER_STATEMENT_FROM_LINK (Link
);
986 RemoveEntryList (&Statement
->Link
);
988 DestroyStatement (FormSet
, Statement
);
992 // Free ConfigRequest string.
994 while (!IsListEmpty (&Form
->ConfigRequestHead
)) {
995 Link
= GetFirstNode (&Form
->ConfigRequestHead
);
996 ConfigInfo
= FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link
);
997 RemoveEntryList (&ConfigInfo
->Link
);
999 FreePool (ConfigInfo
->ConfigRequest
);
1000 FreePool (ConfigInfo
);
1003 if (Form
->SuppressExpression
!= NULL
) {
1004 FreePool (Form
->SuppressExpression
);
1007 UiFreeMenuList (&Form
->FormViewListHead
);
1017 Free resources allocated for a FormSet.
1019 @param FormSet Pointer of the FormSet
1024 IN OUT FORM_BROWSER_FORMSET
*FormSet
1028 FORMSET_STORAGE
*Storage
;
1029 FORMSET_DEFAULTSTORE
*DefaultStore
;
1030 FORM_EXPRESSION
*Expression
;
1031 FORM_BROWSER_FORM
*Form
;
1033 if (FormSet
->IfrBinaryData
== NULL
) {
1035 // Uninitialized FormSet
1042 // Free IFR binary buffer
1044 FreePool (FormSet
->IfrBinaryData
);
1047 // Free FormSet Storage
1049 if (FormSet
->StorageListHead
.ForwardLink
!= NULL
) {
1050 while (!IsListEmpty (&FormSet
->StorageListHead
)) {
1051 Link
= GetFirstNode (&FormSet
->StorageListHead
);
1052 Storage
= FORMSET_STORAGE_FROM_LINK (Link
);
1053 RemoveEntryList (&Storage
->Link
);
1055 DestroyStorage (Storage
);
1060 // Free FormSet Default Store
1062 if (FormSet
->DefaultStoreListHead
.ForwardLink
!= NULL
) {
1063 while (!IsListEmpty (&FormSet
->DefaultStoreListHead
)) {
1064 Link
= GetFirstNode (&FormSet
->DefaultStoreListHead
);
1065 DefaultStore
= FORMSET_DEFAULTSTORE_FROM_LINK (Link
);
1066 RemoveEntryList (&DefaultStore
->Link
);
1068 FreePool (DefaultStore
);
1073 // Free Formset Expressions
1075 while (!IsListEmpty (&FormSet
->ExpressionListHead
)) {
1076 Link
= GetFirstNode (&FormSet
->ExpressionListHead
);
1077 Expression
= FORM_EXPRESSION_FROM_LINK (Link
);
1078 RemoveEntryList (&Expression
->Link
);
1080 DestroyExpression (Expression
);
1086 if (FormSet
->FormListHead
.ForwardLink
!= NULL
) {
1087 while (!IsListEmpty (&FormSet
->FormListHead
)) {
1088 Link
= GetFirstNode (&FormSet
->FormListHead
);
1089 Form
= FORM_BROWSER_FORM_FROM_LINK (Link
);
1090 RemoveEntryList (&Form
->Link
);
1092 DestroyForm (FormSet
, Form
);
1096 if (FormSet
->StatementBuffer
!= NULL
) {
1097 FreePool (FormSet
->StatementBuffer
);
1099 if (FormSet
->ExpressionBuffer
!= NULL
) {
1100 FreePool (FormSet
->ExpressionBuffer
);
1108 Tell whether this Operand is an Expression OpCode or not
1110 @param Operand Operand of an IFR OpCode.
1112 @retval TRUE This is an Expression OpCode.
1113 @retval FALSE Not an Expression OpCode.
1117 IsExpressionOpCode (
1121 if (((Operand
>= EFI_IFR_EQ_ID_VAL_OP
) && (Operand
<= EFI_IFR_NOT_OP
)) ||
1122 ((Operand
>= EFI_IFR_MATCH_OP
) && (Operand
<= EFI_IFR_SET_OP
)) ||
1123 ((Operand
>= EFI_IFR_EQUAL_OP
) && (Operand
<= EFI_IFR_SPAN_OP
)) ||
1124 (Operand
== EFI_IFR_CATENATE_OP
) ||
1125 (Operand
== EFI_IFR_TO_LOWER_OP
) ||
1126 (Operand
== EFI_IFR_TO_UPPER_OP
) ||
1127 (Operand
== EFI_IFR_MAP_OP
) ||
1128 (Operand
== EFI_IFR_VERSION_OP
) ||
1129 (Operand
== EFI_IFR_SECURITY_OP
) ||
1130 (Operand
== EFI_IFR_MATCH2_OP
)) {
1138 Tell whether this Operand is an Statement OpCode.
1140 @param Operand Operand of an IFR OpCode.
1142 @retval TRUE This is an Statement OpCode.
1143 @retval FALSE Not an Statement OpCode.
1151 if ((Operand
== EFI_IFR_SUBTITLE_OP
) ||
1152 (Operand
== EFI_IFR_TEXT_OP
) ||
1153 (Operand
== EFI_IFR_RESET_BUTTON_OP
) ||
1154 (Operand
== EFI_IFR_REF_OP
) ||
1155 (Operand
== EFI_IFR_ACTION_OP
) ||
1156 (Operand
== EFI_IFR_NUMERIC_OP
) ||
1157 (Operand
== EFI_IFR_ORDERED_LIST_OP
) ||
1158 (Operand
== EFI_IFR_CHECKBOX_OP
) ||
1159 (Operand
== EFI_IFR_STRING_OP
) ||
1160 (Operand
== EFI_IFR_PASSWORD_OP
) ||
1161 (Operand
== EFI_IFR_DATE_OP
) ||
1162 (Operand
== EFI_IFR_TIME_OP
) ||
1163 (Operand
== EFI_IFR_GUID_OP
) ||
1164 (Operand
== EFI_IFR_ONE_OF_OP
)) {
1172 Tell whether this Operand is an known OpCode.
1174 @param Operand Operand of an IFR OpCode.
1176 @retval TRUE This is an Statement OpCode.
1177 @retval FALSE Not an Statement OpCode.
1185 return Operand
> EFI_IFR_MATCH2_OP
? TRUE
: FALSE
;
1189 Calculate number of Statemens(Questions) and Expression OpCodes.
1191 @param FormSet The FormSet to be counted.
1192 @param NumberOfStatement Number of Statemens(Questions)
1193 @param NumberOfExpression Number of Expression OpCodes
1198 IN FORM_BROWSER_FORMSET
*FormSet
,
1199 IN OUT UINT16
*NumberOfStatement
,
1200 IN OUT UINT16
*NumberOfExpression
1203 UINT16 StatementCount
;
1204 UINT16 ExpressionCount
;
1211 ExpressionCount
= 0;
1213 while (Offset
< FormSet
->IfrBinaryLength
) {
1214 OpCodeData
= FormSet
->IfrBinaryData
+ Offset
;
1215 OpCodeLen
= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
1216 Offset
+= OpCodeLen
;
1218 if (IsExpressionOpCode (((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
)) {
1225 *NumberOfStatement
= StatementCount
;
1226 *NumberOfExpression
= ExpressionCount
;
1232 Parse opcodes in the formset IFR binary.
1234 @param FormSet Pointer of the FormSet data structure.
1236 @retval EFI_SUCCESS Opcode parse success.
1237 @retval Other Opcode parse fail.
1242 IN FORM_BROWSER_FORMSET
*FormSet
1246 FORM_BROWSER_FORM
*CurrentForm
;
1247 FORM_BROWSER_STATEMENT
*CurrentStatement
;
1248 FORM_BROWSER_STATEMENT
*ParentStatement
;
1249 EXPRESSION_OPCODE
*ExpressionOpCode
;
1250 FORM_EXPRESSION
*CurrentExpression
;
1257 FORMSET_STORAGE
*Storage
;
1258 FORMSET_DEFAULTSTORE
*DefaultStore
;
1259 QUESTION_DEFAULT
*CurrentDefault
;
1260 QUESTION_OPTION
*CurrentOption
;
1262 UINT16 NumberOfStatement
;
1263 UINT16 NumberOfExpression
;
1264 EFI_IMAGE_ID
*ImageId
;
1265 BOOLEAN SuppressForQuestion
;
1266 BOOLEAN SuppressForOption
;
1267 UINT16 DepthOfDisable
;
1268 BOOLEAN OpCodeDisabled
;
1269 BOOLEAN SingleOpCodeExpression
;
1270 BOOLEAN InScopeDefault
;
1271 EFI_HII_VALUE
*Value
;
1272 EFI_IFR_FORM_MAP_METHOD
*MapMethod
;
1273 UINT8 MapScopeDepth
;
1275 FORMSET_STORAGE
*VarStorage
;
1276 LIST_ENTRY
*MapExpressionList
;
1277 EFI_VARSTORE_ID TempVarstoreId
;
1278 BOOLEAN InScopeDisable
;
1279 INTN ConditionalExprCount
;
1280 BOOLEAN InUnknownScope
;
1282 FORMSET_DEFAULTSTORE
*PreDefaultStore
;
1283 LIST_ENTRY
*DefaultLink
;
1284 BOOLEAN HaveInserted
;
1286 BOOLEAN QuestionReferBitField
;
1288 SuppressForQuestion
= FALSE
;
1289 SuppressForOption
= FALSE
;
1290 InScopeDisable
= FALSE
;
1292 OpCodeDisabled
= FALSE
;
1293 SingleOpCodeExpression
= FALSE
;
1294 InScopeDefault
= FALSE
;
1295 CurrentExpression
= NULL
;
1296 CurrentDefault
= NULL
;
1297 CurrentOption
= NULL
;
1303 MapExpressionList
= NULL
;
1305 ConditionalExprCount
= 0;
1306 InUnknownScope
= FALSE
;
1308 QuestionReferBitField
= FALSE
;
1311 // Get the number of Statements and Expressions
1313 CountOpCodes (FormSet
, &NumberOfStatement
, &NumberOfExpression
);
1315 mStatementIndex
= 0;
1316 mUsedQuestionId
= 1;
1317 FormSet
->StatementBuffer
= AllocateZeroPool (NumberOfStatement
* sizeof (FORM_BROWSER_STATEMENT
));
1318 if (FormSet
->StatementBuffer
== NULL
) {
1319 return EFI_OUT_OF_RESOURCES
;
1322 mExpressionOpCodeIndex
= 0;
1323 FormSet
->ExpressionBuffer
= AllocateZeroPool (NumberOfExpression
* sizeof (EXPRESSION_OPCODE
));
1324 if (FormSet
->ExpressionBuffer
== NULL
) {
1325 return EFI_OUT_OF_RESOURCES
;
1328 InitializeListHead (&FormSet
->StatementListOSF
);
1329 InitializeListHead (&FormSet
->StorageListHead
);
1330 InitializeListHead (&FormSet
->SaveFailStorageListHead
);
1331 InitializeListHead (&FormSet
->DefaultStoreListHead
);
1332 InitializeListHead (&FormSet
->FormListHead
);
1333 InitializeListHead (&FormSet
->ExpressionListHead
);
1334 ResetCurrentExpressionStack ();
1335 ResetMapExpressionListStack ();
1338 CurrentStatement
= NULL
;
1339 ParentStatement
= NULL
;
1344 while (OpCodeOffset
< FormSet
->IfrBinaryLength
) {
1345 OpCodeData
= FormSet
->IfrBinaryData
+ OpCodeOffset
;
1347 OpCodeLength
= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
1348 OpCodeOffset
+= OpCodeLength
;
1349 Operand
= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
;
1350 Scope
= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Scope
;
1352 if (InUnknownScope
) {
1353 if (Operand
== EFI_IFR_END_OP
) {
1356 if (UnknownDepth
== 0) {
1357 InUnknownScope
= FALSE
;
1368 if (IsUnKnownOpCode(Operand
)) {
1370 InUnknownScope
= TRUE
;
1378 // If scope bit set, push onto scope stack
1381 PushScope (Operand
);
1384 if (OpCodeDisabled
) {
1386 // DisableIf Expression is evaluated to be TRUE, try to find its end.
1387 // Here only cares the EFI_IFR_DISABLE_IF and EFI_IFR_END
1389 if (Operand
== EFI_IFR_DISABLE_IF_OP
) {
1391 } else if (Operand
== EFI_IFR_END_OP
) {
1392 Status
= PopScope (&ScopeOpCode
);
1393 if (EFI_ERROR (Status
)) {
1397 if (ScopeOpCode
== EFI_IFR_DISABLE_IF_OP
) {
1398 if (DepthOfDisable
== 0) {
1399 InScopeDisable
= FALSE
;
1400 OpCodeDisabled
= FALSE
;
1409 if (IsExpressionOpCode (Operand
)) {
1410 ExpressionOpCode
= &FormSet
->ExpressionBuffer
[mExpressionOpCodeIndex
];
1411 mExpressionOpCodeIndex
++;
1413 ExpressionOpCode
->Signature
= EXPRESSION_OPCODE_SIGNATURE
;
1414 ExpressionOpCode
->Operand
= Operand
;
1415 Value
= &ExpressionOpCode
->Value
;
1418 case EFI_IFR_EQ_ID_VAL_OP
:
1419 CopyMem (&ExpressionOpCode
->QuestionId
, &((EFI_IFR_EQ_ID_VAL
*) OpCodeData
)->QuestionId
, sizeof (EFI_QUESTION_ID
));
1421 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_16
;
1422 CopyMem (&Value
->Value
.u16
, &((EFI_IFR_EQ_ID_VAL
*) OpCodeData
)->Value
, sizeof (UINT16
));
1425 case EFI_IFR_EQ_ID_ID_OP
:
1426 CopyMem (&ExpressionOpCode
->QuestionId
, &((EFI_IFR_EQ_ID_ID
*) OpCodeData
)->QuestionId1
, sizeof (EFI_QUESTION_ID
));
1427 CopyMem (&ExpressionOpCode
->QuestionId2
, &((EFI_IFR_EQ_ID_ID
*) OpCodeData
)->QuestionId2
, sizeof (EFI_QUESTION_ID
));
1430 case EFI_IFR_EQ_ID_VAL_LIST_OP
:
1431 CopyMem (&ExpressionOpCode
->QuestionId
, &((EFI_IFR_EQ_ID_VAL_LIST
*) OpCodeData
)->QuestionId
, sizeof (EFI_QUESTION_ID
));
1432 CopyMem (&ExpressionOpCode
->ListLength
, &((EFI_IFR_EQ_ID_VAL_LIST
*) OpCodeData
)->ListLength
, sizeof (UINT16
));
1433 ExpressionOpCode
->ValueList
= AllocateCopyPool (ExpressionOpCode
->ListLength
* sizeof (UINT16
), &((EFI_IFR_EQ_ID_VAL_LIST
*) OpCodeData
)->ValueList
);
1436 case EFI_IFR_TO_STRING_OP
:
1437 case EFI_IFR_FIND_OP
:
1438 ExpressionOpCode
->Format
= (( EFI_IFR_TO_STRING
*) OpCodeData
)->Format
;
1441 case EFI_IFR_STRING_REF1_OP
:
1442 Value
->Type
= EFI_IFR_TYPE_STRING
;
1443 CopyMem (&Value
->Value
.string
, &(( EFI_IFR_STRING_REF1
*) OpCodeData
)->StringId
, sizeof (EFI_STRING_ID
));
1446 case EFI_IFR_RULE_REF_OP
:
1447 ExpressionOpCode
->RuleId
= (( EFI_IFR_RULE_REF
*) OpCodeData
)->RuleId
;
1450 case EFI_IFR_SPAN_OP
:
1451 ExpressionOpCode
->Flags
= (( EFI_IFR_SPAN
*) OpCodeData
)->Flags
;
1454 case EFI_IFR_THIS_OP
:
1455 ASSERT (ParentStatement
!= NULL
);
1456 ExpressionOpCode
->QuestionId
= ParentStatement
->QuestionId
;
1459 case EFI_IFR_SECURITY_OP
:
1460 CopyMem (&ExpressionOpCode
->Guid
, &((EFI_IFR_SECURITY
*) OpCodeData
)->Permissions
, sizeof (EFI_GUID
));
1463 case EFI_IFR_MATCH2_OP
:
1464 CopyMem (&ExpressionOpCode
->Guid
, &((EFI_IFR_MATCH2
*) OpCodeData
)->SyntaxType
, sizeof (EFI_GUID
));
1467 case EFI_IFR_GET_OP
:
1468 case EFI_IFR_SET_OP
:
1469 CopyMem (&TempVarstoreId
, &((EFI_IFR_GET
*) OpCodeData
)->VarStoreId
, sizeof (TempVarstoreId
));
1470 if (TempVarstoreId
!= 0) {
1471 if (FormSet
->StorageListHead
.ForwardLink
!= NULL
) {
1472 Link
= GetFirstNode (&FormSet
->StorageListHead
);
1473 while (!IsNull (&FormSet
->StorageListHead
, Link
)) {
1474 VarStorage
= FORMSET_STORAGE_FROM_LINK (Link
);
1475 if (VarStorage
->VarStoreId
== ((EFI_IFR_GET
*) OpCodeData
)->VarStoreId
) {
1476 ExpressionOpCode
->VarStorage
= VarStorage
->BrowserStorage
;
1479 Link
= GetNextNode (&FormSet
->StorageListHead
, Link
);
1482 if (ExpressionOpCode
->VarStorage
== NULL
) {
1484 // VarStorage is not found.
1486 return EFI_INVALID_PARAMETER
;
1489 ExpressionOpCode
->ValueType
= ((EFI_IFR_GET
*) OpCodeData
)->VarStoreType
;
1490 switch (ExpressionOpCode
->ValueType
) {
1491 case EFI_IFR_TYPE_BOOLEAN
:
1492 case EFI_IFR_TYPE_NUM_SIZE_8
:
1493 ExpressionOpCode
->ValueWidth
= 1;
1496 case EFI_IFR_TYPE_NUM_SIZE_16
:
1497 case EFI_IFR_TYPE_STRING
:
1498 ExpressionOpCode
->ValueWidth
= 2;
1501 case EFI_IFR_TYPE_NUM_SIZE_32
:
1502 ExpressionOpCode
->ValueWidth
= 4;
1505 case EFI_IFR_TYPE_NUM_SIZE_64
:
1506 ExpressionOpCode
->ValueWidth
= 8;
1509 case EFI_IFR_TYPE_DATE
:
1510 ExpressionOpCode
->ValueWidth
= (UINT8
) sizeof (EFI_IFR_DATE
);
1513 case EFI_IFR_TYPE_TIME
:
1514 ExpressionOpCode
->ValueWidth
= (UINT8
) sizeof (EFI_IFR_TIME
);
1517 case EFI_IFR_TYPE_REF
:
1518 ExpressionOpCode
->ValueWidth
= (UINT8
) sizeof (EFI_IFR_REF
);
1521 case EFI_IFR_TYPE_OTHER
:
1522 case EFI_IFR_TYPE_UNDEFINED
:
1523 case EFI_IFR_TYPE_ACTION
:
1524 case EFI_IFR_TYPE_BUFFER
:
1527 // Invalid value type for Get/Set opcode.
1529 return EFI_INVALID_PARAMETER
;
1531 CopyMem (&ExpressionOpCode
->VarStoreInfo
.VarName
, &((EFI_IFR_GET
*) OpCodeData
)->VarStoreInfo
.VarName
, sizeof (EFI_STRING_ID
));
1532 CopyMem (&ExpressionOpCode
->VarStoreInfo
.VarOffset
, &((EFI_IFR_GET
*) OpCodeData
)->VarStoreInfo
.VarOffset
, sizeof (UINT16
));
1533 if ((ExpressionOpCode
->VarStorage
!= NULL
) &&
1534 (ExpressionOpCode
->VarStorage
->Type
== EFI_HII_VARSTORE_NAME_VALUE
||
1535 ExpressionOpCode
->VarStorage
->Type
== EFI_HII_VARSTORE_EFI_VARIABLE
)) {
1536 ExpressionOpCode
->ValueName
= GetToken (ExpressionOpCode
->VarStoreInfo
.VarName
, FormSet
->HiiHandle
);
1537 if (ExpressionOpCode
->ValueName
== NULL
) {
1539 // String ID is invalid.
1541 return EFI_INVALID_PARAMETER
;
1546 case EFI_IFR_QUESTION_REF1_OP
:
1547 CopyMem (&ExpressionOpCode
->QuestionId
, &((EFI_IFR_EQ_ID_VAL_LIST
*) OpCodeData
)->QuestionId
, sizeof (EFI_QUESTION_ID
));
1550 case EFI_IFR_QUESTION_REF3_OP
:
1551 if (OpCodeLength
>= sizeof (EFI_IFR_QUESTION_REF3_2
)) {
1552 CopyMem (&ExpressionOpCode
->DevicePath
, &(( EFI_IFR_QUESTION_REF3_2
*) OpCodeData
)->DevicePath
, sizeof (EFI_STRING_ID
));
1554 if (OpCodeLength
>= sizeof (EFI_IFR_QUESTION_REF3_3
)) {
1555 CopyMem (&ExpressionOpCode
->Guid
, &(( EFI_IFR_QUESTION_REF3_3
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
));
1563 case EFI_IFR_TRUE_OP
:
1564 Value
->Type
= EFI_IFR_TYPE_BOOLEAN
;
1565 Value
->Value
.b
= TRUE
;
1568 case EFI_IFR_FALSE_OP
:
1569 Value
->Type
= EFI_IFR_TYPE_BOOLEAN
;
1570 Value
->Value
.b
= FALSE
;
1573 case EFI_IFR_ONE_OP
:
1574 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_8
;
1575 Value
->Value
.u8
= 1;
1578 case EFI_IFR_ZERO_OP
:
1579 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_8
;
1580 Value
->Value
.u8
= 0;
1583 case EFI_IFR_ONES_OP
:
1584 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_64
;
1585 Value
->Value
.u64
= 0xffffffffffffffffULL
;
1588 case EFI_IFR_UINT8_OP
:
1589 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_8
;
1590 Value
->Value
.u8
= (( EFI_IFR_UINT8
*) OpCodeData
)->Value
;
1593 case EFI_IFR_UINT16_OP
:
1594 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_16
;
1595 CopyMem (&Value
->Value
.u16
, &(( EFI_IFR_UINT16
*) OpCodeData
)->Value
, sizeof (UINT16
));
1598 case EFI_IFR_UINT32_OP
:
1599 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_32
;
1600 CopyMem (&Value
->Value
.u32
, &(( EFI_IFR_UINT32
*) OpCodeData
)->Value
, sizeof (UINT32
));
1603 case EFI_IFR_UINT64_OP
:
1604 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_64
;
1605 CopyMem (&Value
->Value
.u64
, &(( EFI_IFR_UINT64
*) OpCodeData
)->Value
, sizeof (UINT64
));
1608 case EFI_IFR_UNDEFINED_OP
:
1609 Value
->Type
= EFI_IFR_TYPE_UNDEFINED
;
1612 case EFI_IFR_VERSION_OP
:
1613 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_16
;
1614 Value
->Value
.u16
= EFI_IFR_SPECIFICATION_VERSION
;
1621 // Create sub expression nested in MAP opcode
1623 if (CurrentExpression
== NULL
&& MapScopeDepth
> 0) {
1624 CurrentExpression
= CreateExpression (CurrentForm
, OpCodeData
);
1625 ASSERT (MapExpressionList
!= NULL
);
1626 InsertTailList (MapExpressionList
, &CurrentExpression
->Link
);
1628 SingleOpCodeExpression
= TRUE
;
1631 ASSERT (CurrentExpression
!= NULL
);
1632 InsertTailList (&CurrentExpression
->OpCodeListHead
, &ExpressionOpCode
->Link
);
1633 if (Operand
== EFI_IFR_MAP_OP
) {
1635 // Store current Map Expression List.
1637 if (MapExpressionList
!= NULL
) {
1638 PushMapExpressionList (MapExpressionList
);
1641 // Initialize new Map Expression List.
1643 MapExpressionList
= &ExpressionOpCode
->MapExpressionList
;
1644 InitializeListHead (MapExpressionList
);
1646 // Store current expression.
1648 PushCurrentExpression (CurrentExpression
);
1649 CurrentExpression
= NULL
;
1651 } else if (SingleOpCodeExpression
) {
1653 // There are two cases to indicate the end of an Expression:
1654 // for single OpCode expression: one Expression OpCode
1655 // for expression consists of more than one OpCode: EFI_IFR_END
1657 SingleOpCodeExpression
= FALSE
;
1659 if (InScopeDisable
&& CurrentForm
== NULL
) {
1661 // This is DisableIf expression for Form, it should be a constant expression
1663 Status
= EvaluateExpression (FormSet
, CurrentForm
, CurrentExpression
);
1664 if (EFI_ERROR (Status
)) {
1668 OpCodeDisabled
= IsTrue(&CurrentExpression
->Result
);
1671 CurrentExpression
= NULL
;
1682 case EFI_IFR_FORM_SET_OP
:
1684 // Check the formset GUID
1686 if (CompareMem (&FormSet
->Guid
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
)) != 0) {
1687 return EFI_INVALID_PARAMETER
;
1690 CopyMem (&FormSet
->FormSetTitle
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->FormSetTitle
, sizeof (EFI_STRING_ID
));
1691 CopyMem (&FormSet
->Help
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Help
, sizeof (EFI_STRING_ID
));
1692 FormSet
->OpCode
= (EFI_IFR_OP_HEADER
*) OpCodeData
;//save the opcode address of formset
1694 if (OpCodeLength
> OFFSET_OF (EFI_IFR_FORM_SET
, Flags
)) {
1696 // The formset OpCode contains ClassGuid
1698 FormSet
->NumberOfClassGuid
= (UINT8
) (((EFI_IFR_FORM_SET
*) OpCodeData
)->Flags
& 0x3);
1699 CopyMem (FormSet
->ClassGuid
, OpCodeData
+ sizeof (EFI_IFR_FORM_SET
), FormSet
->NumberOfClassGuid
* sizeof (EFI_GUID
));
1703 case EFI_IFR_FORM_OP
:
1705 // Create a new Form for this FormSet
1707 CurrentForm
= AllocateZeroPool (sizeof (FORM_BROWSER_FORM
));
1708 ASSERT (CurrentForm
!= NULL
);
1709 CurrentForm
->Signature
= FORM_BROWSER_FORM_SIGNATURE
;
1710 InitializeListHead (&CurrentForm
->ExpressionListHead
);
1711 InitializeListHead (&CurrentForm
->StatementListHead
);
1712 InitializeListHead (&CurrentForm
->ConfigRequestHead
);
1713 InitializeListHead (&CurrentForm
->FormViewListHead
);
1715 CurrentForm
->FormType
= STANDARD_MAP_FORM_TYPE
;
1716 CopyMem (&CurrentForm
->FormId
, &((EFI_IFR_FORM
*) OpCodeData
)->FormId
, sizeof (UINT16
));
1717 CopyMem (&CurrentForm
->FormTitle
, &((EFI_IFR_FORM
*) OpCodeData
)->FormTitle
, sizeof (EFI_STRING_ID
));
1719 ConditionalExprCount
= GetConditionalExpressionCount(ExpressForm
);
1720 if ( ConditionalExprCount
> 0) {
1722 // Form is inside of suppressif
1724 CurrentForm
->SuppressExpression
= (FORM_EXPRESSION_LIST
*) AllocatePool(
1725 (UINTN
) (sizeof(FORM_EXPRESSION_LIST
) + ((ConditionalExprCount
-1) * sizeof(FORM_EXPRESSION
*))));
1726 ASSERT (CurrentForm
->SuppressExpression
!= NULL
);
1727 CurrentForm
->SuppressExpression
->Count
= (UINTN
) ConditionalExprCount
;
1728 CurrentForm
->SuppressExpression
->Signature
= FORM_EXPRESSION_LIST_SIGNATURE
;
1729 CopyMem (CurrentForm
->SuppressExpression
->Expression
, GetConditionalExpressionList(ExpressForm
), (UINTN
) (sizeof (FORM_EXPRESSION
*) * ConditionalExprCount
));
1734 // Enter scope of a Form, suppressif will be used for Question or Option
1736 SuppressForQuestion
= TRUE
;
1740 // Insert into Form list of this FormSet
1742 InsertTailList (&FormSet
->FormListHead
, &CurrentForm
->Link
);
1745 case EFI_IFR_FORM_MAP_OP
:
1747 // Create a new Form for this FormSet
1749 CurrentForm
= AllocateZeroPool (sizeof (FORM_BROWSER_FORM
));
1750 ASSERT (CurrentForm
!= NULL
);
1751 CurrentForm
->Signature
= FORM_BROWSER_FORM_SIGNATURE
;
1752 InitializeListHead (&CurrentForm
->ExpressionListHead
);
1753 InitializeListHead (&CurrentForm
->StatementListHead
);
1754 InitializeListHead (&CurrentForm
->ConfigRequestHead
);
1755 InitializeListHead (&CurrentForm
->FormViewListHead
);
1757 CopyMem (&CurrentForm
->FormId
, &((EFI_IFR_FORM
*) OpCodeData
)->FormId
, sizeof (UINT16
));
1759 MapMethod
= (EFI_IFR_FORM_MAP_METHOD
*) (OpCodeData
+ sizeof (EFI_IFR_FORM_MAP
));
1761 // FormMap Form must contain at least one Map Method.
1763 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
< ((UINTN
) (UINT8
*) (MapMethod
+ 1) - (UINTN
) OpCodeData
)) {
1764 return EFI_INVALID_PARAMETER
;
1767 // Try to find the standard form map method.
1769 while (((UINTN
) (UINT8
*) MapMethod
- (UINTN
) OpCodeData
) < ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
) {
1770 if (CompareGuid ((EFI_GUID
*) (VOID
*) &MapMethod
->MethodIdentifier
, &gEfiHiiStandardFormGuid
)) {
1771 CopyMem (&CurrentForm
->FormTitle
, &MapMethod
->MethodTitle
, sizeof (EFI_STRING_ID
));
1772 CurrentForm
->FormType
= STANDARD_MAP_FORM_TYPE
;
1778 // If the standard form map method is not found, the first map method title will be used.
1780 if (CurrentForm
->FormTitle
== 0) {
1781 MapMethod
= (EFI_IFR_FORM_MAP_METHOD
*) (OpCodeData
+ sizeof (EFI_IFR_FORM_MAP
));
1782 CopyMem (&CurrentForm
->FormTitle
, &MapMethod
->MethodTitle
, sizeof (EFI_STRING_ID
));
1785 ConditionalExprCount
= GetConditionalExpressionCount(ExpressForm
);
1786 if ( ConditionalExprCount
> 0) {
1788 // Form is inside of suppressif
1790 CurrentForm
->SuppressExpression
= (FORM_EXPRESSION_LIST
*) AllocatePool(
1791 (UINTN
) (sizeof(FORM_EXPRESSION_LIST
) + ((ConditionalExprCount
-1) * sizeof(FORM_EXPRESSION
*))));
1792 ASSERT (CurrentForm
->SuppressExpression
!= NULL
);
1793 CurrentForm
->SuppressExpression
->Count
= (UINTN
) ConditionalExprCount
;
1794 CurrentForm
->SuppressExpression
->Signature
= FORM_EXPRESSION_LIST_SIGNATURE
;
1795 CopyMem (CurrentForm
->SuppressExpression
->Expression
, GetConditionalExpressionList(ExpressForm
), (UINTN
) (sizeof (FORM_EXPRESSION
*) * ConditionalExprCount
));
1800 // Enter scope of a Form, suppressif will be used for Question or Option
1802 SuppressForQuestion
= TRUE
;
1806 // Insert into Form list of this FormSet
1808 InsertTailList (&FormSet
->FormListHead
, &CurrentForm
->Link
);
1814 case EFI_IFR_VARSTORE_OP
:
1816 // Create a buffer Storage for this FormSet
1818 Storage
= CreateStorage (FormSet
, EFI_HII_VARSTORE_BUFFER
, OpCodeData
);
1819 CopyMem (&Storage
->VarStoreId
, &((EFI_IFR_VARSTORE
*) OpCodeData
)->VarStoreId
, sizeof (EFI_VARSTORE_ID
));
1822 case EFI_IFR_VARSTORE_NAME_VALUE_OP
:
1824 // Create a name/value Storage for this FormSet
1826 Storage
= CreateStorage (FormSet
, EFI_HII_VARSTORE_NAME_VALUE
, OpCodeData
);
1827 CopyMem (&Storage
->VarStoreId
, &((EFI_IFR_VARSTORE_NAME_VALUE
*) OpCodeData
)->VarStoreId
, sizeof (EFI_VARSTORE_ID
));
1830 case EFI_IFR_VARSTORE_EFI_OP
:
1832 // Create a EFI variable Storage for this FormSet
1834 if (OpCodeLength
< sizeof (EFI_IFR_VARSTORE_EFI
)) {
1836 // Create efi varstore with format follow UEFI spec before 2.3.1.
1838 Storage
= CreateStorage (FormSet
, EFI_HII_VARSTORE_EFI_VARIABLE
, OpCodeData
);
1841 // Create efi varstore with format follow UEFI spec 2.3.1 and later.
1843 Storage
= CreateStorage (FormSet
, EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER
, OpCodeData
);
1845 CopyMem (&Storage
->VarStoreId
, &((EFI_IFR_VARSTORE_EFI
*) OpCodeData
)->VarStoreId
, sizeof (EFI_VARSTORE_ID
));
1851 case EFI_IFR_DEFAULTSTORE_OP
:
1852 HaveInserted
= FALSE
;
1853 DefaultStore
= AllocateZeroPool (sizeof (FORMSET_DEFAULTSTORE
));
1854 ASSERT (DefaultStore
!= NULL
);
1855 DefaultStore
->Signature
= FORMSET_DEFAULTSTORE_SIGNATURE
;
1857 CopyMem (&DefaultStore
->DefaultId
, &((EFI_IFR_DEFAULTSTORE
*) OpCodeData
)->DefaultId
, sizeof (UINT16
));
1858 CopyMem (&DefaultStore
->DefaultName
, &((EFI_IFR_DEFAULTSTORE
*) OpCodeData
)->DefaultName
, sizeof (EFI_STRING_ID
));
1860 // Insert it to the DefaultStore list of this Formset with ascending order.
1862 if (!IsListEmpty (&FormSet
->DefaultStoreListHead
)) {
1863 DefaultLink
= GetFirstNode (&FormSet
->DefaultStoreListHead
);
1864 while (!IsNull (&FormSet
->DefaultStoreListHead
, DefaultLink
)) {
1865 PreDefaultStore
= FORMSET_DEFAULTSTORE_FROM_LINK(DefaultLink
);
1866 DefaultLink
= GetNextNode (&FormSet
->DefaultStoreListHead
, DefaultLink
);
1867 if (DefaultStore
->DefaultId
< PreDefaultStore
->DefaultId
) {
1868 InsertTailList (&PreDefaultStore
->Link
, &DefaultStore
->Link
);
1869 HaveInserted
= TRUE
;
1874 if (!HaveInserted
) {
1875 InsertTailList (&FormSet
->DefaultStoreListHead
, &DefaultStore
->Link
);
1882 case EFI_IFR_SUBTITLE_OP
:
1883 CurrentStatement
= CreateStatement (OpCodeData
, FormSet
, CurrentForm
);
1884 ASSERT (CurrentStatement
!= NULL
);
1886 CurrentStatement
->Flags
= ((EFI_IFR_SUBTITLE
*) OpCodeData
)->Flags
;
1887 CurrentStatement
->FakeQuestionId
= mUsedQuestionId
++;
1890 case EFI_IFR_TEXT_OP
:
1891 CurrentStatement
= CreateStatement (OpCodeData
, FormSet
, CurrentForm
);
1892 ASSERT (CurrentStatement
!= NULL
);
1893 CurrentStatement
->FakeQuestionId
= mUsedQuestionId
++;
1894 CopyMem (&CurrentStatement
->TextTwo
, &((EFI_IFR_TEXT
*) OpCodeData
)->TextTwo
, sizeof (EFI_STRING_ID
));
1897 case EFI_IFR_RESET_BUTTON_OP
:
1898 CurrentStatement
= CreateStatement (OpCodeData
, FormSet
, CurrentForm
);
1899 ASSERT (CurrentStatement
!= NULL
);
1900 CurrentStatement
->FakeQuestionId
= mUsedQuestionId
++;
1901 CopyMem (&CurrentStatement
->DefaultId
, &((EFI_IFR_RESET_BUTTON
*) OpCodeData
)->DefaultId
, sizeof (EFI_DEFAULT_ID
));
1907 case EFI_IFR_ACTION_OP
:
1908 CurrentStatement
= CreateQuestion (OpCodeData
, FormSet
, CurrentForm
);
1909 ASSERT (CurrentStatement
!= NULL
);
1910 CurrentStatement
->HiiValue
.Type
= EFI_IFR_TYPE_ACTION
;
1912 if (OpCodeLength
== sizeof (EFI_IFR_ACTION_1
)) {
1914 // No QuestionConfig present, so no configuration string will be processed
1916 CurrentStatement
->QuestionConfig
= 0;
1918 CopyMem (&CurrentStatement
->QuestionConfig
, &((EFI_IFR_ACTION
*) OpCodeData
)->QuestionConfig
, sizeof (EFI_STRING_ID
));
1922 case EFI_IFR_REF_OP
:
1923 CurrentStatement
= CreateQuestion (OpCodeData
, FormSet
, CurrentForm
);
1924 ASSERT (CurrentStatement
!= NULL
);
1925 Value
= &CurrentStatement
->HiiValue
;
1926 Value
->Type
= EFI_IFR_TYPE_REF
;
1927 if (OpCodeLength
>= sizeof (EFI_IFR_REF
)) {
1928 CopyMem (&Value
->Value
.ref
.FormId
, &((EFI_IFR_REF
*) OpCodeData
)->FormId
, sizeof (EFI_FORM_ID
));
1930 if (OpCodeLength
>= sizeof (EFI_IFR_REF2
)) {
1931 CopyMem (&Value
->Value
.ref
.QuestionId
, &((EFI_IFR_REF2
*) OpCodeData
)->QuestionId
, sizeof (EFI_QUESTION_ID
));
1933 if (OpCodeLength
>= sizeof (EFI_IFR_REF3
)) {
1934 CopyMem (&Value
->Value
.ref
.FormSetGuid
, &((EFI_IFR_REF3
*) OpCodeData
)->FormSetId
, sizeof (EFI_GUID
));
1936 if (OpCodeLength
>= sizeof (EFI_IFR_REF4
)) {
1937 CopyMem (&Value
->Value
.ref
.DevicePath
, &((EFI_IFR_REF4
*) OpCodeData
)->DevicePath
, sizeof (EFI_STRING_ID
));
1942 CurrentStatement
->StorageWidth
= (UINT16
) sizeof (EFI_HII_REF
);
1943 InitializeRequestElement (FormSet
, CurrentStatement
, CurrentForm
);
1946 case EFI_IFR_ONE_OF_OP
:
1947 case EFI_IFR_NUMERIC_OP
:
1948 CurrentStatement
= CreateQuestion (OpCodeData
, FormSet
, CurrentForm
);
1949 ASSERT(CurrentStatement
!= NULL
);
1951 CurrentStatement
->Flags
= ((EFI_IFR_ONE_OF
*) OpCodeData
)->Flags
;
1952 Value
= &CurrentStatement
->HiiValue
;
1954 if (QuestionReferBitField
) {
1956 // Get the bit var store info (bit/byte offset, bit/byte offset)
1958 CurrentStatement
->QuestionReferToBitField
= TRUE
;
1959 CurrentStatement
->BitStorageWidth
= CurrentStatement
->Flags
& EDKII_IFR_NUMERIC_SIZE_BIT
;
1960 CurrentStatement
->BitVarOffset
= CurrentStatement
->VarStoreInfo
.VarOffset
;
1961 CurrentStatement
->VarStoreInfo
.VarOffset
= CurrentStatement
->BitVarOffset
/ 8;
1962 TotalBits
= CurrentStatement
->BitVarOffset
% 8 + CurrentStatement
->BitStorageWidth
;
1963 CurrentStatement
->StorageWidth
= (TotalBits
% 8 == 0? TotalBits
/ 8: TotalBits
/ 8 + 1);
1966 // Get the Minimum/Maximum/Step value(Note: bit field type has been stored as UINT32 type)
1968 CurrentStatement
->Minimum
= ((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u32
.MinValue
;
1969 CurrentStatement
->Maximum
= ((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u32
.MaxValue
;
1970 CurrentStatement
->Step
= ((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u32
.Step
;
1973 // Update the Flag and type of Minimum/Maximum/Step according to the actual width of bit field,
1974 // in order to make Browser handle these question with bit varstore correctly.
1976 ((EFI_IFR_NUMERIC
*) OpCodeData
)->Flags
&= EDKII_IFR_DISPLAY_BIT
;
1977 ((EFI_IFR_NUMERIC
*) OpCodeData
)->Flags
>>= 2;
1978 switch (CurrentStatement
->StorageWidth
) {
1980 ((EFI_IFR_NUMERIC
*) OpCodeData
)->Flags
|= EFI_IFR_TYPE_NUM_SIZE_8
;
1981 ((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u8
.MinValue
= (UINT8
)CurrentStatement
->Minimum
;
1982 ((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u8
.MaxValue
= (UINT8
)CurrentStatement
->Maximum
;
1983 ((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u8
.Step
= (UINT8
)CurrentStatement
->Step
;
1984 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_8
;
1987 ((EFI_IFR_NUMERIC
*) OpCodeData
)->Flags
|= EFI_IFR_TYPE_NUM_SIZE_16
;
1988 ((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u16
.MinValue
= (UINT16
)CurrentStatement
->Minimum
;
1989 ((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u16
.MaxValue
= (UINT16
)CurrentStatement
->Maximum
;
1990 ((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u16
.Step
= (UINT16
)CurrentStatement
->Step
;
1991 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_16
;
1995 ((EFI_IFR_NUMERIC
*) OpCodeData
)->Flags
|= EFI_IFR_TYPE_NUM_SIZE_32
;
1996 ((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u32
.MinValue
= (UINT32
)CurrentStatement
->Minimum
;
1997 ((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u32
.MaxValue
= (UINT32
)CurrentStatement
->Maximum
;
1998 ((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u32
.Step
= (UINT32
)CurrentStatement
->Step
;
1999 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_32
;
2005 switch (CurrentStatement
->Flags
& EFI_IFR_NUMERIC_SIZE
) {
2006 case EFI_IFR_NUMERIC_SIZE_1
:
2007 CurrentStatement
->Minimum
= ((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u8
.MinValue
;
2008 CurrentStatement
->Maximum
= ((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u8
.MaxValue
;
2009 CurrentStatement
->Step
= ((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u8
.Step
;
2010 CurrentStatement
->StorageWidth
= (UINT16
) sizeof (UINT8
);
2011 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_8
;
2014 case EFI_IFR_NUMERIC_SIZE_2
:
2015 CopyMem (&CurrentStatement
->Minimum
, &((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u16
.MinValue
, sizeof (UINT16
));
2016 CopyMem (&CurrentStatement
->Maximum
, &((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u16
.MaxValue
, sizeof (UINT16
));
2017 CopyMem (&CurrentStatement
->Step
, &((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u16
.Step
, sizeof (UINT16
));
2018 CurrentStatement
->StorageWidth
= (UINT16
) sizeof (UINT16
);
2019 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_16
;
2022 case EFI_IFR_NUMERIC_SIZE_4
:
2023 CopyMem (&CurrentStatement
->Minimum
, &((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u32
.MinValue
, sizeof (UINT32
));
2024 CopyMem (&CurrentStatement
->Maximum
, &((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u32
.MaxValue
, sizeof (UINT32
));
2025 CopyMem (&CurrentStatement
->Step
, &((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u32
.Step
, sizeof (UINT32
));
2026 CurrentStatement
->StorageWidth
= (UINT16
) sizeof (UINT32
);
2027 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_32
;
2030 case EFI_IFR_NUMERIC_SIZE_8
:
2031 CopyMem (&CurrentStatement
->Minimum
, &((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u64
.MinValue
, sizeof (UINT64
));
2032 CopyMem (&CurrentStatement
->Maximum
, &((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u64
.MaxValue
, sizeof (UINT64
));
2033 CopyMem (&CurrentStatement
->Step
, &((EFI_IFR_NUMERIC
*) OpCodeData
)->data
.u64
.Step
, sizeof (UINT64
));
2034 CurrentStatement
->StorageWidth
= (UINT16
) sizeof (UINT64
);
2035 Value
->Type
= EFI_IFR_TYPE_NUM_SIZE_64
;
2042 InitializeRequestElement (FormSet
, CurrentStatement
, CurrentForm
);
2044 if ((Operand
== EFI_IFR_ONE_OF_OP
) && Scope
!= 0) {
2045 SuppressForOption
= TRUE
;
2049 case EFI_IFR_ORDERED_LIST_OP
:
2050 CurrentStatement
= CreateQuestion (OpCodeData
, FormSet
, CurrentForm
);
2051 ASSERT(CurrentStatement
!= NULL
);
2053 CurrentStatement
->Flags
= ((EFI_IFR_ORDERED_LIST
*) OpCodeData
)->Flags
;
2054 CurrentStatement
->MaxContainers
= ((EFI_IFR_ORDERED_LIST
*) OpCodeData
)->MaxContainers
;
2056 CurrentStatement
->HiiValue
.Type
= EFI_IFR_TYPE_BUFFER
;
2057 CurrentStatement
->BufferValue
= NULL
;
2060 SuppressForOption
= TRUE
;
2064 case EFI_IFR_CHECKBOX_OP
:
2065 CurrentStatement
= CreateQuestion (OpCodeData
, FormSet
, CurrentForm
);
2066 ASSERT(CurrentStatement
!= NULL
);
2068 CurrentStatement
->Flags
= ((EFI_IFR_CHECKBOX
*) OpCodeData
)->Flags
;
2069 CurrentStatement
->StorageWidth
= (UINT16
) sizeof (BOOLEAN
);
2070 CurrentStatement
->HiiValue
.Type
= EFI_IFR_TYPE_BOOLEAN
;
2072 if (QuestionReferBitField
) {
2074 // Get the bit var store info (bit/byte offset, bit/byte offset)
2076 CurrentStatement
->QuestionReferToBitField
= TRUE
;
2077 CurrentStatement
->BitStorageWidth
= 1;
2078 CurrentStatement
->BitVarOffset
= CurrentStatement
->VarStoreInfo
.VarOffset
;
2079 CurrentStatement
->VarStoreInfo
.VarOffset
= CurrentStatement
->BitVarOffset
/ 8;
2080 TotalBits
= CurrentStatement
->BitVarOffset
% 8 + CurrentStatement
->BitStorageWidth
;
2081 CurrentStatement
->StorageWidth
= (TotalBits
% 8 == 0? TotalBits
/ 8: TotalBits
/ 8 + 1);
2084 InitializeRequestElement (FormSet
, CurrentStatement
, CurrentForm
);
2088 case EFI_IFR_STRING_OP
:
2089 CurrentStatement
= CreateQuestion (OpCodeData
, FormSet
, CurrentForm
);
2090 ASSERT (CurrentStatement
!= NULL
);
2092 // MinSize is the minimum number of characters that can be accepted for this opcode,
2093 // MaxSize is the maximum number of characters that can be accepted for this opcode.
2094 // The characters are stored as Unicode, so the storage width should multiply 2.
2096 CurrentStatement
->Minimum
= ((EFI_IFR_STRING
*) OpCodeData
)->MinSize
;
2097 CurrentStatement
->Maximum
= ((EFI_IFR_STRING
*) OpCodeData
)->MaxSize
;
2098 CurrentStatement
->StorageWidth
= (UINT16
)((UINTN
) CurrentStatement
->Maximum
* sizeof (CHAR16
));
2099 CurrentStatement
->Flags
= ((EFI_IFR_STRING
*) OpCodeData
)->Flags
;
2101 CurrentStatement
->HiiValue
.Type
= EFI_IFR_TYPE_STRING
;
2102 CurrentStatement
->BufferValue
= AllocateZeroPool (CurrentStatement
->StorageWidth
+ sizeof (CHAR16
));
2103 CurrentStatement
->HiiValue
.Value
.string
= NewString ((CHAR16
*) CurrentStatement
->BufferValue
, FormSet
->HiiHandle
);
2105 InitializeRequestElement (FormSet
, CurrentStatement
, CurrentForm
);
2108 case EFI_IFR_PASSWORD_OP
:
2109 CurrentStatement
= CreateQuestion (OpCodeData
, FormSet
, CurrentForm
);
2110 ASSERT (CurrentStatement
!= NULL
);
2112 // MinSize is the minimum number of characters that can be accepted for this opcode,
2113 // MaxSize is the maximum number of characters that can be accepted for this opcode.
2114 // The characters are stored as Unicode, so the storage width should multiply 2.
2116 CopyMem (&CurrentStatement
->Minimum
, &((EFI_IFR_PASSWORD
*) OpCodeData
)->MinSize
, sizeof (UINT16
));
2117 CopyMem (&CurrentStatement
->Maximum
, &((EFI_IFR_PASSWORD
*) OpCodeData
)->MaxSize
, sizeof (UINT16
));
2118 CurrentStatement
->StorageWidth
= (UINT16
)((UINTN
) CurrentStatement
->Maximum
* sizeof (CHAR16
));
2120 CurrentStatement
->HiiValue
.Type
= EFI_IFR_TYPE_STRING
;
2121 CurrentStatement
->BufferValue
= AllocateZeroPool ((CurrentStatement
->StorageWidth
+ sizeof (CHAR16
)));
2122 CurrentStatement
->HiiValue
.Value
.string
= NewString ((CHAR16
*) CurrentStatement
->BufferValue
, FormSet
->HiiHandle
);
2124 InitializeRequestElement (FormSet
, CurrentStatement
, CurrentForm
);
2127 case EFI_IFR_DATE_OP
:
2128 CurrentStatement
= CreateQuestion (OpCodeData
, FormSet
, CurrentForm
);
2129 ASSERT(CurrentStatement
!= NULL
);
2131 CurrentStatement
->Flags
= ((EFI_IFR_DATE
*) OpCodeData
)->Flags
;
2132 CurrentStatement
->HiiValue
.Type
= EFI_IFR_TYPE_DATE
;
2134 if ((CurrentStatement
->Flags
& EFI_QF_DATE_STORAGE
) == QF_DATE_STORAGE_NORMAL
) {
2135 CurrentStatement
->StorageWidth
= (UINT16
) sizeof (EFI_HII_DATE
);
2137 InitializeRequestElement (FormSet
, CurrentStatement
, CurrentForm
);
2140 // Don't assign storage for RTC type of date/time
2142 CurrentStatement
->Storage
= NULL
;
2143 CurrentStatement
->StorageWidth
= 0;
2147 case EFI_IFR_TIME_OP
:
2148 CurrentStatement
= CreateQuestion (OpCodeData
, FormSet
, CurrentForm
);
2149 ASSERT(CurrentStatement
!= NULL
);
2151 CurrentStatement
->Flags
= ((EFI_IFR_TIME
*) OpCodeData
)->Flags
;
2152 CurrentStatement
->HiiValue
.Type
= EFI_IFR_TYPE_TIME
;
2154 if ((CurrentStatement
->Flags
& QF_TIME_STORAGE
) == QF_TIME_STORAGE_NORMAL
) {
2155 CurrentStatement
->StorageWidth
= (UINT16
) sizeof (EFI_HII_TIME
);
2157 InitializeRequestElement (FormSet
, CurrentStatement
, CurrentForm
);
2160 // Don't assign storage for RTC type of date/time
2162 CurrentStatement
->Storage
= NULL
;
2163 CurrentStatement
->StorageWidth
= 0;
2170 case EFI_IFR_DEFAULT_OP
:
2172 // EFI_IFR_DEFAULT appear in scope of a Question,
2173 // It creates a default value for the current question.
2174 // A Question may have more than one Default value which have different default types.
2176 CurrentDefault
= AllocateZeroPool (sizeof (QUESTION_DEFAULT
));
2177 ASSERT (CurrentDefault
!= NULL
);
2178 CurrentDefault
->Signature
= QUESTION_DEFAULT_SIGNATURE
;
2180 CurrentDefault
->Value
.Type
= ((EFI_IFR_DEFAULT
*) OpCodeData
)->Type
;
2181 CopyMem (&CurrentDefault
->DefaultId
, &((EFI_IFR_DEFAULT
*) OpCodeData
)->DefaultId
, sizeof (UINT16
));
2182 if (CurrentDefault
->Value
.Type
== EFI_IFR_TYPE_BUFFER
) {
2183 CurrentDefault
->Value
.BufferLen
= (UINT16
) (OpCodeLength
- OFFSET_OF (EFI_IFR_DEFAULT
, Value
));
2184 CurrentDefault
->Value
.Buffer
= AllocateCopyPool (CurrentDefault
->Value
.BufferLen
, &((EFI_IFR_DEFAULT
*) OpCodeData
)->Value
);
2185 ASSERT (CurrentDefault
->Value
.Buffer
!= NULL
);
2187 CopyMem (&CurrentDefault
->Value
.Value
, &((EFI_IFR_DEFAULT
*) OpCodeData
)->Value
, OpCodeLength
- OFFSET_OF (EFI_IFR_DEFAULT
, Value
));
2188 ExtendValueToU64 (&CurrentDefault
->Value
);
2192 // Insert to Default Value list of current Question
2194 InsertTailList (&ParentStatement
->DefaultListHead
, &CurrentDefault
->Link
);
2197 InScopeDefault
= TRUE
;
2204 case EFI_IFR_ONE_OF_OPTION_OP
:
2205 ASSERT (ParentStatement
!= NULL
);
2206 if (ParentStatement
->Operand
== EFI_IFR_ORDERED_LIST_OP
&& ((((EFI_IFR_ONE_OF_OPTION
*) OpCodeData
)->Flags
& (EFI_IFR_OPTION_DEFAULT
| EFI_IFR_OPTION_DEFAULT_MFG
)) != 0)) {
2208 // It's keep the default value for ordered list opcode.
2210 CurrentDefault
= AllocateZeroPool (sizeof (QUESTION_DEFAULT
));
2211 ASSERT (CurrentDefault
!= NULL
);
2212 CurrentDefault
->Signature
= QUESTION_DEFAULT_SIGNATURE
;
2214 CurrentDefault
->Value
.Type
= EFI_IFR_TYPE_BUFFER
;
2215 if ((((EFI_IFR_ONE_OF_OPTION
*) OpCodeData
)->Flags
& EFI_IFR_OPTION_DEFAULT
) != 0) {
2216 CurrentDefault
->DefaultId
= EFI_HII_DEFAULT_CLASS_STANDARD
;
2218 CurrentDefault
->DefaultId
= EFI_HII_DEFAULT_CLASS_MANUFACTURING
;
2221 CurrentDefault
->Value
.BufferLen
= (UINT16
) (OpCodeLength
- OFFSET_OF (EFI_IFR_ONE_OF_OPTION
, Value
));
2222 CurrentDefault
->Value
.Buffer
= AllocateCopyPool (CurrentDefault
->Value
.BufferLen
, &((EFI_IFR_ONE_OF_OPTION
*) OpCodeData
)->Value
);
2223 ASSERT (CurrentDefault
->Value
.Buffer
!= NULL
);
2226 // Insert to Default Value list of current Question
2228 InsertTailList (&ParentStatement
->DefaultListHead
, &CurrentDefault
->Link
);
2233 // EFI_IFR_ONE_OF_OPTION appear in scope of a Question.
2234 // It create a selection for use in current Question.
2236 CurrentOption
= AllocateZeroPool (sizeof (QUESTION_OPTION
));
2237 ASSERT (CurrentOption
!= NULL
);
2238 CurrentOption
->Signature
= QUESTION_OPTION_SIGNATURE
;
2239 CurrentOption
->OpCode
= (EFI_IFR_ONE_OF_OPTION
*) OpCodeData
;
2241 CurrentOption
->Flags
= ((EFI_IFR_ONE_OF_OPTION
*) OpCodeData
)->Flags
;
2242 CurrentOption
->Value
.Type
= ((EFI_IFR_ONE_OF_OPTION
*) OpCodeData
)->Type
;
2243 CopyMem (&CurrentOption
->Text
, &((EFI_IFR_ONE_OF_OPTION
*) OpCodeData
)->Option
, sizeof (EFI_STRING_ID
));
2244 CopyMem (&CurrentOption
->Value
.Value
, &((EFI_IFR_ONE_OF_OPTION
*) OpCodeData
)->Value
, OpCodeLength
- OFFSET_OF (EFI_IFR_ONE_OF_OPTION
, Value
));
2245 ExtendValueToU64 (&CurrentOption
->Value
);
2247 ConditionalExprCount
= GetConditionalExpressionCount(ExpressOption
);
2248 if ( ConditionalExprCount
> 0) {
2250 // Form is inside of suppressif
2252 CurrentOption
->SuppressExpression
= (FORM_EXPRESSION_LIST
*) AllocatePool(
2253 (UINTN
) (sizeof(FORM_EXPRESSION_LIST
) + ((ConditionalExprCount
-1) * sizeof(FORM_EXPRESSION
*))));
2254 ASSERT (CurrentOption
->SuppressExpression
!= NULL
);
2255 CurrentOption
->SuppressExpression
->Count
= (UINTN
) ConditionalExprCount
;
2256 CurrentOption
->SuppressExpression
->Signature
= FORM_EXPRESSION_LIST_SIGNATURE
;
2257 CopyMem (CurrentOption
->SuppressExpression
->Expression
, GetConditionalExpressionList(ExpressOption
), (UINTN
) (sizeof (FORM_EXPRESSION
*) * ConditionalExprCount
));
2261 // Insert to Option list of current Question
2263 InsertTailList (&ParentStatement
->OptionListHead
, &CurrentOption
->Link
);
2265 // Now we know the Storage width of nested Ordered List
2267 if ((ParentStatement
->Operand
== EFI_IFR_ORDERED_LIST_OP
) && (ParentStatement
->BufferValue
== NULL
)) {
2269 switch (CurrentOption
->Value
.Type
) {
2270 case EFI_IFR_TYPE_NUM_SIZE_8
:
2274 case EFI_IFR_TYPE_NUM_SIZE_16
:
2278 case EFI_IFR_TYPE_NUM_SIZE_32
:
2282 case EFI_IFR_TYPE_NUM_SIZE_64
:
2288 // Invalid type for Ordered List
2293 ParentStatement
->StorageWidth
= (UINT16
) (ParentStatement
->MaxContainers
* Width
);
2294 ParentStatement
->BufferValue
= AllocateZeroPool (ParentStatement
->StorageWidth
);
2295 ParentStatement
->ValueType
= CurrentOption
->Value
.Type
;
2296 if (ParentStatement
->HiiValue
.Type
== EFI_IFR_TYPE_BUFFER
) {
2297 ParentStatement
->HiiValue
.Buffer
= ParentStatement
->BufferValue
;
2298 ParentStatement
->HiiValue
.BufferLen
= ParentStatement
->StorageWidth
;
2301 InitializeRequestElement (FormSet
, ParentStatement
, CurrentForm
);
2308 case EFI_IFR_NO_SUBMIT_IF_OP
:
2309 case EFI_IFR_INCONSISTENT_IF_OP
:
2311 // Create an Expression node
2313 CurrentExpression
= CreateExpression (CurrentForm
, OpCodeData
);
2314 CopyMem (&CurrentExpression
->Error
, &((EFI_IFR_INCONSISTENT_IF
*) OpCodeData
)->Error
, sizeof (EFI_STRING_ID
));
2316 if (Operand
== EFI_IFR_NO_SUBMIT_IF_OP
) {
2317 CurrentExpression
->Type
= EFI_HII_EXPRESSION_NO_SUBMIT_IF
;
2318 InsertTailList (&ParentStatement
->NoSubmitListHead
, &CurrentExpression
->Link
);
2320 CurrentExpression
->Type
= EFI_HII_EXPRESSION_INCONSISTENT_IF
;
2321 InsertTailList (&ParentStatement
->InconsistentListHead
, &CurrentExpression
->Link
);
2325 // Take a look at next OpCode to see whether current expression consists
2328 if (((EFI_IFR_OP_HEADER
*) (OpCodeData
+ OpCodeLength
))->Scope
== 0) {
2329 SingleOpCodeExpression
= TRUE
;
2333 case EFI_IFR_WARNING_IF_OP
:
2335 // Create an Expression node
2337 CurrentExpression
= CreateExpression (CurrentForm
, OpCodeData
);
2338 CopyMem (&CurrentExpression
->Error
, &((EFI_IFR_WARNING_IF
*) OpCodeData
)->Warning
, sizeof (EFI_STRING_ID
));
2339 CurrentExpression
->TimeOut
= ((EFI_IFR_WARNING_IF
*) OpCodeData
)->TimeOut
;
2340 CurrentExpression
->Type
= EFI_HII_EXPRESSION_WARNING_IF
;
2341 InsertTailList (&ParentStatement
->WarningListHead
, &CurrentExpression
->Link
);
2344 // Take a look at next OpCode to see whether current expression consists
2347 if (((EFI_IFR_OP_HEADER
*) (OpCodeData
+ OpCodeLength
))->Scope
== 0) {
2348 SingleOpCodeExpression
= TRUE
;
2352 case EFI_IFR_SUPPRESS_IF_OP
:
2354 // Question and Option will appear in scope of this OpCode
2356 CurrentExpression
= CreateExpression (CurrentForm
, OpCodeData
);
2357 CurrentExpression
->Type
= EFI_HII_EXPRESSION_SUPPRESS_IF
;
2359 if (CurrentForm
== NULL
) {
2360 InsertTailList (&FormSet
->ExpressionListHead
, &CurrentExpression
->Link
);
2362 InsertTailList (&CurrentForm
->ExpressionListHead
, &CurrentExpression
->Link
);
2365 if (SuppressForOption
) {
2366 PushConditionalExpression(CurrentExpression
, ExpressOption
);
2367 } else if (SuppressForQuestion
) {
2368 PushConditionalExpression(CurrentExpression
, ExpressStatement
);
2370 PushConditionalExpression(CurrentExpression
, ExpressForm
);
2374 // Take a look at next OpCode to see whether current expression consists
2377 if (((EFI_IFR_OP_HEADER
*) (OpCodeData
+ OpCodeLength
))->Scope
== 0) {
2378 SingleOpCodeExpression
= TRUE
;
2382 case EFI_IFR_GRAY_OUT_IF_OP
:
2384 // Questions will appear in scope of this OpCode
2386 CurrentExpression
= CreateExpression (CurrentForm
, OpCodeData
);
2387 CurrentExpression
->Type
= EFI_HII_EXPRESSION_GRAY_OUT_IF
;
2388 InsertTailList (&CurrentForm
->ExpressionListHead
, &CurrentExpression
->Link
);
2389 PushConditionalExpression(CurrentExpression
, ExpressStatement
);
2392 // Take a look at next OpCode to see whether current expression consists
2395 if (((EFI_IFR_OP_HEADER
*) (OpCodeData
+ OpCodeLength
))->Scope
== 0) {
2396 SingleOpCodeExpression
= TRUE
;
2400 case EFI_IFR_DISABLE_IF_OP
:
2402 // The DisableIf expression should only rely on constant, so it could be
2403 // evaluated at initialization and it will not be queued
2405 CurrentExpression
= AllocateZeroPool (sizeof (FORM_EXPRESSION
));
2406 ASSERT (CurrentExpression
!= NULL
);
2407 CurrentExpression
->Signature
= FORM_EXPRESSION_SIGNATURE
;
2408 CurrentExpression
->Type
= EFI_HII_EXPRESSION_DISABLE_IF
;
2409 InitializeListHead (&CurrentExpression
->OpCodeListHead
);
2411 if (CurrentForm
!= NULL
) {
2413 // This is DisableIf for Question, enqueue it to Form expression list
2415 InsertTailList (&CurrentForm
->ExpressionListHead
, &CurrentExpression
->Link
);
2416 PushConditionalExpression(CurrentExpression
, ExpressStatement
);
2419 OpCodeDisabled
= FALSE
;
2420 InScopeDisable
= TRUE
;
2422 // Take a look at next OpCode to see whether current expression consists
2425 if (((EFI_IFR_OP_HEADER
*) (OpCodeData
+ OpCodeLength
))->Scope
== 0) {
2426 SingleOpCodeExpression
= TRUE
;
2433 case EFI_IFR_VALUE_OP
:
2434 CurrentExpression
= CreateExpression (CurrentForm
, OpCodeData
);
2435 CurrentExpression
->Type
= EFI_HII_EXPRESSION_VALUE
;
2436 InsertTailList (&CurrentForm
->ExpressionListHead
, &CurrentExpression
->Link
);
2438 if (InScopeDefault
) {
2440 // Used for default (EFI_IFR_DEFAULT)
2442 CurrentDefault
->ValueExpression
= CurrentExpression
;
2445 // If used for a question, then the question will be read-only
2448 // Make sure CurrentStatement is not NULL.
2449 // If it is NULL, 1) ParseOpCodes functions may parse the IFR wrongly. Or 2) the IFR
2450 // file is wrongly generated by tools such as VFR Compiler. There may be a bug in VFR Compiler.
2452 ASSERT (ParentStatement
!= NULL
);
2453 ParentStatement
->ValueExpression
= CurrentExpression
;
2457 // Take a look at next OpCode to see whether current expression consists
2460 if (((EFI_IFR_OP_HEADER
*) (OpCodeData
+ OpCodeLength
))->Scope
== 0) {
2461 SingleOpCodeExpression
= TRUE
;
2465 case EFI_IFR_RULE_OP
:
2466 CurrentExpression
= CreateExpression (CurrentForm
, OpCodeData
);
2467 CurrentExpression
->Type
= EFI_HII_EXPRESSION_RULE
;
2469 CurrentExpression
->RuleId
= ((EFI_IFR_RULE
*) OpCodeData
)->RuleId
;
2470 InsertTailList (&CurrentForm
->ExpressionListHead
, &CurrentExpression
->Link
);
2473 // Take a look at next OpCode to see whether current expression consists
2476 if (((EFI_IFR_OP_HEADER
*) (OpCodeData
+ OpCodeLength
))->Scope
== 0) {
2477 SingleOpCodeExpression
= TRUE
;
2481 case EFI_IFR_READ_OP
:
2482 CurrentExpression
= CreateExpression (CurrentForm
, OpCodeData
);
2483 CurrentExpression
->Type
= EFI_HII_EXPRESSION_READ
;
2484 InsertTailList (&CurrentForm
->ExpressionListHead
, &CurrentExpression
->Link
);
2487 // Make sure CurrentStatement is not NULL.
2488 // If it is NULL, 1) ParseOpCodes functions may parse the IFR wrongly. Or 2) the IFR
2489 // file is wrongly generated by tools such as VFR Compiler. There may be a bug in VFR Compiler.
2491 ASSERT (ParentStatement
!= NULL
);
2492 ParentStatement
->ReadExpression
= CurrentExpression
;
2495 // Take a look at next OpCode to see whether current expression consists
2498 if (((EFI_IFR_OP_HEADER
*) (OpCodeData
+ OpCodeLength
))->Scope
== 0) {
2499 SingleOpCodeExpression
= TRUE
;
2503 case EFI_IFR_WRITE_OP
:
2504 CurrentExpression
= CreateExpression (CurrentForm
, OpCodeData
);
2505 CurrentExpression
->Type
= EFI_HII_EXPRESSION_WRITE
;
2506 InsertTailList (&CurrentForm
->ExpressionListHead
, &CurrentExpression
->Link
);
2509 // Make sure CurrentStatement is not NULL.
2510 // If it is NULL, 1) ParseOpCodes functions may parse the IFR wrongly. Or 2) the IFR
2511 // file is wrongly generated by tools such as VFR Compiler. There may be a bug in VFR Compiler.
2513 ASSERT (ParentStatement
!= NULL
);
2514 ParentStatement
->WriteExpression
= CurrentExpression
;
2517 // Take a look at next OpCode to see whether current expression consists
2520 if (((EFI_IFR_OP_HEADER
*) (OpCodeData
+ OpCodeLength
))->Scope
== 0) {
2521 SingleOpCodeExpression
= TRUE
;
2528 case EFI_IFR_IMAGE_OP
:
2530 // Get ScopeOpcode from top of stack
2532 PopScope (&ScopeOpCode
);
2533 PushScope (ScopeOpCode
);
2535 switch (ScopeOpCode
) {
2536 case EFI_IFR_FORM_SET_OP
:
2537 ImageId
= &FormSet
->ImageId
;
2540 case EFI_IFR_FORM_OP
:
2541 case EFI_IFR_FORM_MAP_OP
:
2542 ASSERT (CurrentForm
!= NULL
);
2543 ImageId
= &CurrentForm
->ImageId
;
2546 case EFI_IFR_ONE_OF_OPTION_OP
:
2547 ASSERT (CurrentOption
!= NULL
);
2548 ImageId
= &CurrentOption
->ImageId
;
2553 // Make sure CurrentStatement is not NULL.
2554 // If it is NULL, 1) ParseOpCodes functions may parse the IFR wrongly. Or 2) the IFR
2555 // file is wrongly generated by tools such as VFR Compiler.
2557 ASSERT (ParentStatement
!= NULL
);
2558 ImageId
= &ParentStatement
->ImageId
;
2562 ASSERT (ImageId
!= NULL
);
2563 CopyMem (ImageId
, &((EFI_IFR_IMAGE
*) OpCodeData
)->Id
, sizeof (EFI_IMAGE_ID
));
2569 case EFI_IFR_REFRESH_OP
:
2570 ASSERT (ParentStatement
!= NULL
);
2571 ParentStatement
->RefreshInterval
= ((EFI_IFR_REFRESH
*) OpCodeData
)->RefreshInterval
;
2577 case EFI_IFR_REFRESH_ID_OP
:
2579 // Get ScopeOpcode from top of stack
2581 PopScope (&ScopeOpCode
);
2582 PushScope (ScopeOpCode
);
2584 switch (ScopeOpCode
) {
2585 case EFI_IFR_FORM_OP
:
2586 case EFI_IFR_FORM_MAP_OP
:
2587 ASSERT (CurrentForm
!= NULL
);
2588 CopyMem (&CurrentForm
->RefreshGuid
, &((EFI_IFR_REFRESH_ID
*) OpCodeData
)->RefreshEventGroupId
, sizeof (EFI_GUID
));
2592 ASSERT (ParentStatement
!= NULL
);
2593 CopyMem (&ParentStatement
->RefreshGuid
, &((EFI_IFR_REFRESH_ID
*) OpCodeData
)->RefreshEventGroupId
, sizeof (EFI_GUID
));
2601 case EFI_IFR_MODAL_TAG_OP
:
2602 ASSERT (CurrentForm
!= NULL
);
2603 CurrentForm
->ModalForm
= TRUE
;
2607 // Lock tag, used by form and statement.
2609 case EFI_IFR_LOCKED_OP
:
2611 // Get ScopeOpcode from top of stack
2613 PopScope (&ScopeOpCode
);
2614 PushScope (ScopeOpCode
);
2615 switch (ScopeOpCode
) {
2616 case EFI_IFR_FORM_OP
:
2617 case EFI_IFR_FORM_MAP_OP
:
2618 ASSERT (CurrentForm
!= NULL
);
2619 CurrentForm
->Locked
= TRUE
;
2623 ASSERT (ParentStatement
!= NULL
);
2624 ParentStatement
->Locked
= TRUE
;
2631 case EFI_IFR_GUID_OP
:
2632 CurrentStatement
= CreateStatement (OpCodeData
, FormSet
, CurrentForm
);
2633 if (CompareGuid ((EFI_GUID
*)(OpCodeData
+ sizeof (EFI_IFR_OP_HEADER
)), &gEdkiiIfrBitVarstoreGuid
)) {
2635 QuestionReferBitField
= TRUE
;
2642 case EFI_IFR_END_OP
:
2643 QuestionReferBitField
= FALSE
;
2644 Status
= PopScope (&ScopeOpCode
);
2645 if (EFI_ERROR (Status
)) {
2651 // Parent statement end tag found, update ParentStatement info.
2653 if (IsStatementOpCode(ScopeOpCode
) && (ParentStatement
!= NULL
) && (ParentStatement
->Operand
== ScopeOpCode
)) {
2654 ParentStatement
= ParentStatement
->ParentStatement
;
2657 switch (ScopeOpCode
) {
2658 case EFI_IFR_FORM_SET_OP
:
2660 // End of FormSet, update FormSet IFR binary length
2661 // to stop parsing substantial OpCodes
2663 FormSet
->IfrBinaryLength
= OpCodeOffset
;
2666 case EFI_IFR_FORM_OP
:
2667 case EFI_IFR_FORM_MAP_OP
:
2672 SuppressForQuestion
= FALSE
;
2675 case EFI_IFR_ONE_OF_OPTION_OP
:
2679 CurrentOption
= NULL
;
2682 case EFI_IFR_NO_SUBMIT_IF_OP
:
2683 case EFI_IFR_INCONSISTENT_IF_OP
:
2684 case EFI_IFR_WARNING_IF_OP
:
2686 // Ignore end of EFI_IFR_NO_SUBMIT_IF and EFI_IFR_INCONSISTENT_IF
2690 case EFI_IFR_SUPPRESS_IF_OP
:
2691 if (SuppressForOption
) {
2692 PopConditionalExpression(ExpressOption
);
2693 } else if (SuppressForQuestion
) {
2694 PopConditionalExpression(ExpressStatement
);
2696 PopConditionalExpression(ExpressForm
);
2700 case EFI_IFR_GRAY_OUT_IF_OP
:
2701 PopConditionalExpression(ExpressStatement
);
2704 case EFI_IFR_DISABLE_IF_OP
:
2705 if (CurrentForm
!= NULL
) {
2706 PopConditionalExpression(ExpressStatement
);
2708 InScopeDisable
= FALSE
;
2709 OpCodeDisabled
= FALSE
;
2712 case EFI_IFR_ONE_OF_OP
:
2713 case EFI_IFR_ORDERED_LIST_OP
:
2714 SuppressForOption
= FALSE
;
2717 case EFI_IFR_DEFAULT_OP
:
2718 InScopeDefault
= FALSE
;
2721 case EFI_IFR_MAP_OP
:
2723 // Get current Map Expression List.
2725 Status
= PopMapExpressionList ((VOID
**) &MapExpressionList
);
2726 if (Status
== EFI_ACCESS_DENIED
) {
2727 MapExpressionList
= NULL
;
2730 // Get current expression.
2732 Status
= PopCurrentExpression ((VOID
**) &CurrentExpression
);
2733 ASSERT_EFI_ERROR (Status
);
2734 ASSERT (MapScopeDepth
> 0);
2739 if (IsExpressionOpCode (ScopeOpCode
)) {
2740 if (InScopeDisable
&& CurrentForm
== NULL
) {
2742 // This is DisableIf expression for Form, it should be a constant expression
2744 ASSERT (CurrentExpression
!= NULL
);
2745 Status
= EvaluateExpression (FormSet
, CurrentForm
, CurrentExpression
);
2746 if (EFI_ERROR (Status
)) {
2750 OpCodeDisabled
= IsTrue (&CurrentExpression
->Result
);
2753 // DisableIf Expression is only used once and not queued, free it
2755 DestroyExpression (CurrentExpression
);
2759 // End of current Expression
2761 CurrentExpression
= NULL
;
2771 if (IsStatementOpCode(Operand
)) {
2772 CurrentStatement
->ParentStatement
= ParentStatement
;
2775 // Scope != 0, other statements or options may nest in this statement.
2776 // Update the ParentStatement info.
2778 ParentStatement
= CurrentStatement
;