3 The definition of CFormPkg's member function
5 Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include "VfrFormPkg.h"
21 * The definition of CFormPkg's member function
24 SPendingAssign::SPendingAssign (
40 mKey
= new CHAR8
[strlen (Key
) + 1];
47 mMsg
= new CHAR8
[strlen (Msg
) + 1];
54 SPendingAssign::~SPendingAssign (
71 SPendingAssign::SetAddrAndLen (
81 SPendingAssign::AssignValue (
86 memmove (mAddr
, Addr
, (mLen
< Len
? mLen
: Len
));
91 SPendingAssign::GetKey (
107 mBufferNodeQueueHead
= NULL
;
108 mCurrBufferNode
= NULL
;
110 Node
= new SBufferNode
;
114 BufferStart
= new CHAR8
[BufferSize
];
115 if (BufferStart
== NULL
) {
118 BufferEnd
= BufferStart
+ BufferSize
;
120 memset (BufferStart
, 0, BufferSize
);
121 Node
->mBufferStart
= BufferStart
;
122 Node
->mBufferEnd
= BufferEnd
;
123 Node
->mBufferFree
= BufferStart
;
126 mBufferSize
= BufferSize
;
127 mBufferNodeQueueHead
= Node
;
128 mBufferNodeQueueTail
= Node
;
129 mCurrBufferNode
= Node
;
132 CFormPkg::~CFormPkg ()
135 SPendingAssign
*pPNode
;
137 while (mBufferNodeQueueHead
!= NULL
) {
138 pBNode
= mBufferNodeQueueHead
;
139 mBufferNodeQueueHead
= mBufferNodeQueueHead
->mNext
;
140 if (pBNode
->mBufferStart
!= NULL
) {
141 delete pBNode
->mBufferStart
;
145 mBufferNodeQueueTail
= NULL
;
146 mCurrBufferNode
= NULL
;
148 while (PendingAssignList
!= NULL
) {
149 pPNode
= PendingAssignList
;
150 PendingAssignList
= PendingAssignList
->mNext
;
153 PendingAssignList
= NULL
;
157 CFormPkg::CreateNewNode (
163 Node
= new SBufferNode
;
168 Node
->mBufferStart
= new CHAR8
[mBufferSize
];
169 if (Node
->mBufferStart
== NULL
) {
173 memset (Node
->mBufferStart
, 0, mBufferSize
);
174 Node
->mBufferEnd
= Node
->mBufferStart
+ mBufferSize
;
175 Node
->mBufferFree
= Node
->mBufferStart
;
183 CFormPkg::IfrBinBufferGet (
187 CHAR8
*BinBuffer
= NULL
;
188 SBufferNode
*Node
= NULL
;
190 if ((Len
== 0) || (Len
> mBufferSize
)) {
194 if ((mCurrBufferNode
->mBufferFree
+ Len
) <= mCurrBufferNode
->mBufferEnd
) {
195 BinBuffer
= mCurrBufferNode
->mBufferFree
;
196 mCurrBufferNode
->mBufferFree
+= Len
;
198 Node
= CreateNewNode ();
203 if (mBufferNodeQueueTail
== NULL
) {
204 mBufferNodeQueueHead
= mBufferNodeQueueTail
= Node
;
206 mBufferNodeQueueTail
->mNext
= Node
;
207 mBufferNodeQueueTail
= Node
;
209 mCurrBufferNode
= Node
;
214 BinBuffer
= mCurrBufferNode
->mBufferFree
;
215 mCurrBufferNode
->mBufferFree
+= Len
;
225 CFormPkg::GetPkgLength (
237 mReadBufferNode
= mBufferNodeQueueHead
;
238 mReadBufferOffset
= 0;
246 mReadBufferNode
= NULL
;
247 mReadBufferOffset
= 0;
258 if ((Size
== 0) || (Buffer
== NULL
)) {
262 if (mReadBufferNode
== NULL
) {
266 for (Index
= 0; Index
< Size
; Index
++) {
267 if ((mReadBufferNode
->mBufferStart
+ mReadBufferOffset
) < mReadBufferNode
->mBufferFree
) {
268 Buffer
[Index
] = mReadBufferNode
->mBufferStart
[mReadBufferOffset
++];
270 if ((mReadBufferNode
= mReadBufferNode
->mNext
) == NULL
) {
273 mReadBufferOffset
= 0;
283 CFormPkg::BuildPkgHdr (
284 OUT EFI_HII_PACKAGE_HEADER
**PkgHdr
287 if (PkgHdr
== NULL
) {
288 return VFR_RETURN_FATAL_ERROR
;
291 if (((*PkgHdr
) = new EFI_HII_PACKAGE_HEADER
) == NULL
) {
292 return VFR_RETURN_OUT_FOR_RESOURCES
;
295 (*PkgHdr
)->Type
= EFI_HII_PACKAGE_FORM
;
296 (*PkgHdr
)->Length
= mPkgLength
+ sizeof (EFI_HII_PACKAGE_HEADER
);
298 return VFR_RETURN_SUCCESS
;
303 OUT PACKAGE_DATA
&TBuffer
311 if (TBuffer
.Buffer
!= NULL
) {
312 delete TBuffer
.Buffer
;
315 TBuffer
.Size
= mPkgLength
;
316 TBuffer
.Buffer
= NULL
;
317 if (TBuffer
.Size
!= 0) {
318 TBuffer
.Buffer
= new CHAR8
[TBuffer
.Size
];
320 return VFR_RETURN_SUCCESS
;
323 Temp
= TBuffer
.Buffer
;
325 while ((Size
= Read (Buffer
, 1024)) != 0) {
326 memcpy (Temp
, Buffer
, Size
);
330 return VFR_RETURN_SUCCESS
;
337 IN PACKAGE_DATA
*PkgData
340 EFI_VFR_RETURN_CODE Ret
;
343 EFI_HII_PACKAGE_HEADER
*PkgHdr
;
345 if (Output
== NULL
) {
346 return VFR_RETURN_FATAL_ERROR
;
349 if ((Ret
= BuildPkgHdr(&PkgHdr
)) != VFR_RETURN_SUCCESS
) {
352 fwrite (PkgHdr
, sizeof (EFI_HII_PACKAGE_HEADER
), 1, Output
);
355 if (PkgData
== NULL
) {
357 while ((Size
= Read (Buffer
, 1024)) != 0) {
358 fwrite (Buffer
, Size
, 1, Output
);
362 fwrite (PkgData
->Buffer
, PkgData
->Size
, 1, Output
);
365 return VFR_RETURN_SUCCESS
;
369 CFormPkg::_WRITE_PKG_LINE (
372 IN CONST CHAR8
*LineHeader
,
379 if ((pFile
== NULL
) || (LineHeader
== NULL
) || (BlkBuf
== NULL
)) {
383 for (Index
= 0; Index
< BlkSize
; Index
++) {
384 if ((Index
% LineBytes
) == 0) {
385 fprintf (pFile
, "\n%s", LineHeader
);
387 fprintf (pFile
, "0x%02X, ", (UINT8
)BlkBuf
[Index
]);
392 CFormPkg::_WRITE_PKG_END (
395 IN CONST CHAR8
*LineHeader
,
402 if ((BlkSize
== 0) || (pFile
== NULL
) || (LineHeader
== NULL
) || (BlkBuf
== NULL
)) {
406 for (Index
= 0; Index
< BlkSize
- 1; Index
++) {
407 if ((Index
% LineBytes
) == 0) {
408 fprintf (pFile
, "\n%s", LineHeader
);
410 fprintf (pFile
, "0x%02X, ", (UINT8
)BlkBuf
[Index
]);
413 if ((Index
% LineBytes
) == 0) {
414 fprintf (pFile
, "\n%s", LineHeader
);
416 fprintf (pFile
, "0x%02X\n", (UINT8
)BlkBuf
[Index
]);
419 #define BYTES_PRE_LINE 0x10
420 UINT32 gAdjustOpcodeOffset
= 0;
421 BOOLEAN gNeedAdjustOpcode
= FALSE
;
422 UINT32 gAdjustOpcodeLen
= 0;
428 IN PACKAGE_DATA
*PkgData
431 EFI_VFR_RETURN_CODE Ret
;
432 CHAR8 Buffer
[BYTES_PRE_LINE
* 8];
433 EFI_HII_PACKAGE_HEADER
*PkgHdr
;
434 UINT32 PkgLength
= 0;
437 if ((BaseName
== NULL
) || (pFile
== NULL
)) {
438 return VFR_RETURN_FATAL_ERROR
;
441 fprintf (pFile
, "\nunsigned char %sBin[] = {\n", BaseName
);
443 if ((Ret
= BuildPkgHdr(&PkgHdr
)) != VFR_RETURN_SUCCESS
) {
448 // For framework vfr file, the extension framework header will be added.
450 if (VfrCompatibleMode
) {
451 fprintf (pFile
, " // FRAMEWORK PACKAGE HEADER Length\n");
452 PkgLength
= PkgHdr
->Length
+ sizeof (UINT32
) + 2;
453 _WRITE_PKG_LINE(pFile
, BYTES_PRE_LINE
, " ", (CHAR8
*)&PkgLength
, sizeof (UINT32
));
454 fprintf (pFile
, "\n\n // FRAMEWORK PACKAGE HEADER Type\n");
456 _WRITE_PKG_LINE(pFile
, BYTES_PRE_LINE
, " ", (CHAR8
*)&PkgLength
, sizeof (UINT16
));
458 fprintf (pFile
, " // ARRAY LENGTH\n");
459 PkgLength
= PkgHdr
->Length
+ sizeof (UINT32
);
460 _WRITE_PKG_LINE(pFile
, BYTES_PRE_LINE
, " ", (CHAR8
*)&PkgLength
, sizeof (UINT32
));
463 fprintf (pFile
, "\n\n // PACKAGE HEADER\n");
464 _WRITE_PKG_LINE(pFile
, BYTES_PRE_LINE
, " ", (CHAR8
*)PkgHdr
, sizeof (EFI_HII_PACKAGE_HEADER
));
465 PkgLength
= sizeof (EFI_HII_PACKAGE_HEADER
);
467 fprintf (pFile
, "\n\n // PACKAGE DATA\n");
469 if (PkgData
== NULL
) {
471 while ((ReadSize
= Read ((CHAR8
*)Buffer
, BYTES_PRE_LINE
* 8)) != 0) {
472 PkgLength
+= ReadSize
;
473 if (PkgLength
< PkgHdr
->Length
) {
474 _WRITE_PKG_LINE (pFile
, BYTES_PRE_LINE
, " ", Buffer
, ReadSize
);
476 _WRITE_PKG_END (pFile
, BYTES_PRE_LINE
, " ", Buffer
, ReadSize
);
481 if (PkgData
->Size
% BYTES_PRE_LINE
!= 0) {
482 PkgLength
= PkgData
->Size
- (PkgData
->Size
% BYTES_PRE_LINE
);
483 _WRITE_PKG_LINE (pFile
, BYTES_PRE_LINE
, " ", PkgData
->Buffer
, PkgLength
);
484 _WRITE_PKG_END (pFile
, BYTES_PRE_LINE
, " ", PkgData
->Buffer
+ PkgLength
, PkgData
->Size
% BYTES_PRE_LINE
);
486 PkgLength
= PkgData
->Size
- BYTES_PRE_LINE
;
487 _WRITE_PKG_LINE (pFile
, BYTES_PRE_LINE
, " ", PkgData
->Buffer
, PkgLength
);
488 _WRITE_PKG_END (pFile
, BYTES_PRE_LINE
, " ", PkgData
->Buffer
+ PkgLength
, BYTES_PRE_LINE
);
493 fprintf (pFile
, "\n};\n");
495 return VFR_RETURN_SUCCESS
;
499 CFormPkg::AssignPending (
507 SPendingAssign
*pNew
;
509 pNew
= new SPendingAssign (Key
, ValAddr
, ValLen
, LineNo
, Msg
);
511 return VFR_RETURN_OUT_FOR_RESOURCES
;
514 pNew
->mNext
= PendingAssignList
;
515 PendingAssignList
= pNew
;
516 return VFR_RETURN_SUCCESS
;
520 CFormPkg::DoPendingAssign (
526 SPendingAssign
*pNode
;
528 if ((Key
== NULL
) || (ValAddr
== NULL
)) {
532 for (pNode
= PendingAssignList
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
533 if (strcmp (pNode
->mKey
, Key
) == 0) {
534 pNode
->AssignValue (ValAddr
, ValLen
);
540 CFormPkg::HavePendingUnassigned (
544 SPendingAssign
*pNode
;
546 for (pNode
= PendingAssignList
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
547 if (pNode
->mFlag
== PENDING
) {
556 CFormPkg::PendingAssignPrintAll (
560 SPendingAssign
*pNode
;
562 for (pNode
= PendingAssignList
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
563 if (pNode
->mFlag
== PENDING
) {
564 gCVfrErrorHandle
.PrintMsg (pNode
->mLineNo
, pNode
->mKey
, "Error", pNode
->mMsg
);
570 CFormPkg::GetBinBufferNodeForAddr (
571 IN CHAR8
*BinBuffAddr
574 SBufferNode
*TmpNode
;
576 TmpNode
= mBufferNodeQueueHead
;
578 while (TmpNode
!= NULL
) {
579 if (TmpNode
->mBufferStart
<= BinBuffAddr
&& TmpNode
->mBufferFree
>= BinBuffAddr
) {
583 TmpNode
= TmpNode
->mNext
;
590 CFormPkg::GetNodeBefore(
591 IN SBufferNode
*CurrentNode
594 SBufferNode
*FirstNode
= mBufferNodeQueueHead
;
595 SBufferNode
*LastNode
= mBufferNodeQueueHead
;
597 while (FirstNode
!= NULL
) {
598 if (FirstNode
== CurrentNode
) {
602 LastNode
= FirstNode
;
603 FirstNode
= FirstNode
->mNext
;
606 if (FirstNode
== NULL
) {
614 CFormPkg::InsertNodeBefore(
615 IN SBufferNode
*CurrentNode
,
616 IN SBufferNode
*NewNode
619 SBufferNode
*LastNode
= GetNodeBefore (CurrentNode
);
621 if (LastNode
== NULL
) {
622 return VFR_RETURN_MISMATCHED
;
625 NewNode
->mNext
= LastNode
->mNext
;
626 LastNode
->mNext
= NewNode
;
628 return VFR_RETURN_SUCCESS
;
632 CFormPkg::GetBufAddrBaseOnOffset (
636 SBufferNode
*TmpNode
;
638 UINT32 CurrentBufLen
;
642 for (TmpNode
= mBufferNodeQueueHead
; TmpNode
!= NULL
; TmpNode
= TmpNode
->mNext
) {
643 CurrentBufLen
= TmpNode
->mBufferFree
- TmpNode
->mBufferStart
;
644 if (Offset
>= TotalBufLen
&& Offset
< TotalBufLen
+ CurrentBufLen
) {
645 return TmpNode
->mBufferStart
+ (Offset
- TotalBufLen
);
648 TotalBufLen
+= CurrentBufLen
;
655 CFormPkg::AdjustDynamicInsertOpcode (
656 IN CHAR8
*InserPositionAddr
,
657 IN CHAR8
*InsertOpcodeAddr
,
658 IN BOOLEAN CreateOpcodeAfterParsingVfr
661 SBufferNode
*InserPositionNode
;
662 SBufferNode
*InsertOpcodeNode
;
663 SBufferNode
*NewRestoreNodeBegin
;
664 SBufferNode
*NewRestoreNodeEnd
;
665 SBufferNode
*NewLastEndNode
;
666 SBufferNode
*TmpNode
;
667 UINT32 NeedRestoreCodeLen
;
669 NewRestoreNodeEnd
= NULL
;
671 InserPositionNode
= GetBinBufferNodeForAddr(InserPositionAddr
);
672 InsertOpcodeNode
= GetBinBufferNodeForAddr(InsertOpcodeAddr
);
673 assert (InserPositionNode
!= NULL
);
674 assert (InsertOpcodeNode
!= NULL
);
676 if (InserPositionNode
== InsertOpcodeNode
) {
678 // Create New Node to save the restore opcode.
680 NeedRestoreCodeLen
= InsertOpcodeAddr
- InserPositionAddr
;
681 gAdjustOpcodeLen
= NeedRestoreCodeLen
;
682 NewRestoreNodeBegin
= CreateNewNode ();
683 if (NewRestoreNodeBegin
== NULL
) {
684 return VFR_RETURN_OUT_FOR_RESOURCES
;
686 memcpy (NewRestoreNodeBegin
->mBufferFree
, InserPositionAddr
, NeedRestoreCodeLen
);
687 NewRestoreNodeBegin
->mBufferFree
+= NeedRestoreCodeLen
;
690 // Override the restore buffer data.
692 memmove (InserPositionAddr
, InsertOpcodeAddr
, InsertOpcodeNode
->mBufferFree
- InsertOpcodeAddr
);
693 InsertOpcodeNode
->mBufferFree
-= NeedRestoreCodeLen
;
694 memset (InsertOpcodeNode
->mBufferFree
, 0, NeedRestoreCodeLen
);
697 // Create New Node to save the restore opcode.
699 NeedRestoreCodeLen
= InserPositionNode
->mBufferFree
- InserPositionAddr
;
700 gAdjustOpcodeLen
= NeedRestoreCodeLen
;
701 NewRestoreNodeBegin
= CreateNewNode ();
702 if (NewRestoreNodeBegin
== NULL
) {
703 return VFR_RETURN_OUT_FOR_RESOURCES
;
705 memcpy (NewRestoreNodeBegin
->mBufferFree
, InserPositionAddr
, NeedRestoreCodeLen
);
706 NewRestoreNodeBegin
->mBufferFree
+= NeedRestoreCodeLen
;
708 // Override the restore buffer data.
710 InserPositionNode
->mBufferFree
-= NeedRestoreCodeLen
;
712 // Link the restore data to new node.
714 NewRestoreNodeBegin
->mNext
= InserPositionNode
->mNext
;
717 // Count the Adjust opcode len.
719 TmpNode
= InserPositionNode
->mNext
;
720 while (TmpNode
!= InsertOpcodeNode
) {
721 gAdjustOpcodeLen
+= TmpNode
->mBufferFree
- TmpNode
->mBufferStart
;
722 TmpNode
= TmpNode
->mNext
;
726 // Create New Node to save the last node of restore opcode.
728 NeedRestoreCodeLen
= InsertOpcodeAddr
- InsertOpcodeNode
->mBufferStart
;
729 gAdjustOpcodeLen
+= NeedRestoreCodeLen
;
730 if (NeedRestoreCodeLen
> 0) {
731 NewRestoreNodeEnd
= CreateNewNode ();
732 if (NewRestoreNodeEnd
== NULL
) {
733 return VFR_RETURN_OUT_FOR_RESOURCES
;
735 memcpy (NewRestoreNodeEnd
->mBufferFree
, InsertOpcodeNode
->mBufferStart
, NeedRestoreCodeLen
);
736 NewRestoreNodeEnd
->mBufferFree
+= NeedRestoreCodeLen
;
738 // Override the restore buffer data.
740 memmove (InsertOpcodeNode
->mBufferStart
, InsertOpcodeAddr
, InsertOpcodeNode
->mBufferFree
- InsertOpcodeAddr
);
741 InsertOpcodeNode
->mBufferFree
-= InsertOpcodeAddr
- InsertOpcodeNode
->mBufferStart
;
744 // Insert the last restore data node.
746 TmpNode
= GetNodeBefore (InsertOpcodeNode
);
747 assert (TmpNode
!= NULL
);
749 if (TmpNode
== InserPositionNode
) {
750 NewRestoreNodeBegin
->mNext
= NewRestoreNodeEnd
;
752 TmpNode
->mNext
= NewRestoreNodeEnd
;
755 // Connect the dynamic opcode node to the node after InserPositionNode.
757 InserPositionNode
->mNext
= InsertOpcodeNode
;
761 if (CreateOpcodeAfterParsingVfr
) {
763 // Th new opcodes were created after Parsing Vfr file,
764 // so the content in mBufferNodeQueueTail must be the new created opcodes.
765 // So connet the NewRestoreNodeBegin to the tail and update the tail node.
767 mBufferNodeQueueTail
->mNext
= NewRestoreNodeBegin
;
768 if (NewRestoreNodeEnd
!= NULL
) {
769 mBufferNodeQueueTail
= NewRestoreNodeEnd
;
771 mBufferNodeQueueTail
= NewRestoreNodeBegin
;
774 if (mBufferNodeQueueTail
->mBufferFree
- mBufferNodeQueueTail
->mBufferStart
> 2) {
776 // End form set opcode all in the mBufferNodeQueueTail node.
778 NewLastEndNode
= CreateNewNode ();
779 if (NewLastEndNode
== NULL
) {
780 return VFR_RETURN_OUT_FOR_RESOURCES
;
782 NewLastEndNode
->mBufferStart
[0] = 0x29;
783 NewLastEndNode
->mBufferStart
[1] = 0x02;
784 NewLastEndNode
->mBufferFree
+= 2;
786 mBufferNodeQueueTail
->mBufferFree
-= 2;
788 mBufferNodeQueueTail
->mNext
= NewRestoreNodeBegin
;
789 if (NewRestoreNodeEnd
!= NULL
) {
790 NewRestoreNodeEnd
->mNext
= NewLastEndNode
;
792 NewRestoreNodeBegin
->mNext
= NewLastEndNode
;
795 mBufferNodeQueueTail
= NewLastEndNode
;
796 } else if (mBufferNodeQueueTail
->mBufferFree
- mBufferNodeQueueTail
->mBufferStart
== 2) {
797 TmpNode
= GetNodeBefore(mBufferNodeQueueTail
);
798 assert (TmpNode
!= NULL
);
800 TmpNode
->mNext
= NewRestoreNodeBegin
;
801 if (NewRestoreNodeEnd
!= NULL
) {
802 NewRestoreNodeEnd
->mNext
= mBufferNodeQueueTail
;
804 NewRestoreNodeBegin
->mNext
= mBufferNodeQueueTail
;
808 mCurrBufferNode
= mBufferNodeQueueTail
;
809 return VFR_RETURN_SUCCESS
;
813 CFormPkg::DeclarePendingQuestion (
814 IN CVfrVarDataTypeDB
&lCVfrVarDataTypeDB
,
815 IN CVfrDataStorage
&lCVfrDataStorage
,
816 IN CVfrQuestionDB
&lCVfrQuestionDB
,
817 IN EFI_GUID
*LocalFormSetGuid
,
819 OUT CHAR8
**InsertOpcodeAddr
822 SPendingAssign
*pNode
;
825 CHAR8 FName
[MAX_NAME_LEN
];
828 UINT32 ShrinkSize
= 0;
829 EFI_VFR_RETURN_CODE ReturnCode
;
830 EFI_VFR_VARSTORE_TYPE VarStoreType
= EFI_VFR_VARSTORE_INVALID
;
831 EFI_VARSTORE_ID VarStoreId
= EFI_VARSTORE_ID_INVALID
;
834 // Declare all questions as Numeric in DisableIf True
838 DIObj
.SetLineNo (LineNo
);
839 *InsertOpcodeAddr
= DIObj
.GetObjBinAddr ();
842 CIfrTrue
TObj (LineNo
);
844 // Declare Numeric qeustion for each undefined question.
845 for (pNode
= PendingAssignList
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
846 if (pNode
->mFlag
== PENDING
) {
848 EFI_VARSTORE_INFO Info
;
849 EFI_QUESTION_ID QId
= EFI_QUESTION_ID_INVALID
;
851 CNObj
.SetLineNo (LineNo
);
852 CNObj
.SetPrompt (0x0);
856 // Register this question, assume it is normal question, not date or time question
858 VarStr
= pNode
->mKey
;
859 ReturnCode
= lCVfrQuestionDB
.RegisterQuestion (NULL
, VarStr
, QId
);
860 if (ReturnCode
!= VFR_RETURN_SUCCESS
) {
861 gCVfrErrorHandle
.HandleError (ReturnCode
, pNode
->mLineNo
, pNode
->mKey
);
866 printf ("Undefined Question name is %s and Id is 0x%x\n", VarStr
, QId
);
869 // Get Question Info, framework vfr VarName == StructName
871 ReturnCode
= lCVfrVarDataTypeDB
.ExtractFieldNameAndArrary (VarStr
, FName
, ArrayIdx
);
872 if (ReturnCode
!= VFR_RETURN_SUCCESS
) {
873 gCVfrErrorHandle
.PrintMsg (pNode
->mLineNo
, pNode
->mKey
, "Error", "Var string is not the valid C variable");
879 ReturnCode
= lCVfrDataStorage
.GetVarStoreId (FName
, &Info
.mVarStoreId
);
880 if (ReturnCode
!= VFR_RETURN_SUCCESS
) {
881 gCVfrErrorHandle
.PrintMsg (pNode
->mLineNo
, FName
, "Error", "Var Store Type is not defined");
884 VarStoreType
= lCVfrDataStorage
.GetVarStoreType (Info
.mVarStoreId
);
886 if (*VarStr
== '\0' && ArrayIdx
!= INVALID_ARRAY_INDEX
) {
887 ReturnCode
= lCVfrDataStorage
.GetNameVarStoreInfo (&Info
, ArrayIdx
);
889 if (VarStoreType
== EFI_VFR_VARSTORE_EFI
) {
890 ReturnCode
= lCVfrDataStorage
.GetEfiVarStoreInfo (&Info
);
891 } else if (VarStoreType
== EFI_VFR_VARSTORE_BUFFER
) {
892 VarStr
= pNode
->mKey
;
893 //convert VarStr with store name to VarStr with structure name
894 ReturnCode
= lCVfrDataStorage
.GetBufferVarStoreDataTypeName (Info
.mVarStoreId
, &SName
);
895 if (ReturnCode
== VFR_RETURN_SUCCESS
) {
896 NewStr
= new CHAR8
[strlen (VarStr
) + strlen (SName
) + 1];
898 strcpy (NewStr
, SName
);
899 strcat (NewStr
, VarStr
+ strlen (FName
));
900 ReturnCode
= lCVfrVarDataTypeDB
.GetDataFieldInfo (NewStr
, Info
.mInfo
.mVarOffset
, Info
.mVarType
, Info
.mVarTotalSize
);
904 ReturnCode
= VFR_RETURN_UNSUPPORTED
;
907 if (ReturnCode
!= VFR_RETURN_SUCCESS
) {
908 gCVfrErrorHandle
.HandleError (ReturnCode
, pNode
->mLineNo
, pNode
->mKey
);
912 CNObj
.SetQuestionId (QId
);
913 CNObj
.SetVarStoreInfo (&Info
);
915 // Numeric doesn't support BOOLEAN data type.
916 // BOOLEAN type has the same data size to UINT8.
918 if (Info
.mVarType
== EFI_IFR_TYPE_BOOLEAN
) {
919 Info
.mVarType
= EFI_IFR_TYPE_NUM_SIZE_8
;
921 CNObj
.SetFlags (0, Info
.mVarType
);
923 // Use maximum value not to limit the vaild value for the undefined question.
925 switch (Info
.mVarType
) {
926 case EFI_IFR_TYPE_NUM_SIZE_64
:
927 CNObj
.SetMinMaxStepData ((UINT64
) 0, (UINT64
) -1 , (UINT64
) 0);
930 case EFI_IFR_TYPE_NUM_SIZE_32
:
931 CNObj
.SetMinMaxStepData ((UINT32
) 0, (UINT32
) -1 , (UINT32
) 0);
934 case EFI_IFR_TYPE_NUM_SIZE_16
:
935 CNObj
.SetMinMaxStepData ((UINT16
) 0, (UINT16
) -1 , (UINT16
) 0);
938 case EFI_IFR_TYPE_NUM_SIZE_8
:
939 CNObj
.SetMinMaxStepData ((UINT8
) 0, (UINT8
) -1 , (UINT8
) 0);
945 CNObj
.ShrinkBinSize (ShrinkSize
);
948 // For undefined Efi VarStore type question
949 // Append the extended guided opcode to contain VarName
951 if (VarStoreType
== EFI_VFR_VARSTORE_EFI
|| VfrCompatibleMode
) {
952 CIfrVarEqName
CVNObj (QId
, Info
.mInfo
.mVarName
);
953 CVNObj
.SetLineNo (LineNo
);
960 CEObj
.SetLineNo (LineNo
);
968 SEObj
.SetLineNo (LineNo
);
970 return VFR_RETURN_SUCCESS
;
975 SIfrRecord::SIfrRecord (
981 mLineNo
= 0xFFFFFFFF;
982 mOffset
= 0xFFFFFFFF;
986 SIfrRecord::~SIfrRecord (
990 if (mIfrBinBuf
!= NULL
) {
994 mLineNo
= 0xFFFFFFFF;
995 mOffset
= 0xFFFFFFFF;
1000 CIfrRecordInfoDB::CIfrRecordInfoDB (
1005 mRecordCount
= EFI_IFR_RECORDINFO_IDX_START
;
1006 mIfrRecordListHead
= NULL
;
1007 mIfrRecordListTail
= NULL
;
1008 mAllDefaultTypeCount
= 0;
1009 for (UINT8 i
= 0; i
< EFI_HII_MAX_SUPPORT_DEFAULT_TYPE
; i
++) {
1010 mAllDefaultIdArray
[i
] = 0xffff;
1014 CIfrRecordInfoDB::~CIfrRecordInfoDB (
1020 while (mIfrRecordListHead
!= NULL
) {
1021 pNode
= mIfrRecordListHead
;
1022 mIfrRecordListHead
= mIfrRecordListHead
->mNext
;
1028 CIfrRecordInfoDB::GetRecordInfoFromIdx (
1033 SIfrRecord
*pNode
= NULL
;
1035 if (RecordIdx
== EFI_IFR_RECORDINFO_IDX_INVALUD
) {
1039 for (Idx
= (EFI_IFR_RECORDINFO_IDX_START
+ 1), pNode
= mIfrRecordListHead
;
1040 (Idx
!= RecordIdx
) && (pNode
!= NULL
);
1041 Idx
++, pNode
= pNode
->mNext
)
1048 CIfrRecordInfoDB::IfrRecordRegister (
1050 IN CHAR8
*IfrBinBuf
,
1057 if (mSwitch
== FALSE
) {
1058 return EFI_IFR_RECORDINFO_IDX_INVALUD
;
1061 if ((pNew
= new SIfrRecord
) == NULL
) {
1062 return EFI_IFR_RECORDINFO_IDX_INVALUD
;
1065 if (mIfrRecordListHead
== NULL
) {
1066 mIfrRecordListHead
= pNew
;
1067 mIfrRecordListTail
= pNew
;
1069 mIfrRecordListTail
->mNext
= pNew
;
1070 mIfrRecordListTail
= pNew
;
1074 return mRecordCount
;
1078 CIfrRecordInfoDB::IfrRecordInfoUpdate (
1079 IN UINT32 RecordIdx
,
1089 if ((pNode
= GetRecordInfoFromIdx (RecordIdx
)) == NULL
) {
1095 // Line number is not specified explicitly, try to use line number of previous opcode
1097 Prev
= GetRecordInfoFromIdx (RecordIdx
- 1);
1099 LineNo
= Prev
->mLineNo
;
1103 pNode
->mLineNo
= LineNo
;
1104 pNode
->mOffset
= Offset
;
1105 pNode
->mBinBufLen
= BinBufLen
;
1106 pNode
->mIfrBinBuf
= BinBuf
;
1111 CIfrRecordInfoDB::IfrRecordOutput (
1112 OUT PACKAGE_DATA
&TBuffer
1118 if (TBuffer
.Buffer
!= NULL
) {
1119 delete TBuffer
.Buffer
;
1123 TBuffer
.Buffer
= NULL
;
1126 if (mSwitch
== FALSE
) {
1130 for (pNode
= mIfrRecordListHead
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
1131 TBuffer
.Size
+= pNode
->mBinBufLen
;
1134 if (TBuffer
.Size
!= 0) {
1135 TBuffer
.Buffer
= new CHAR8
[TBuffer
.Size
];
1140 Temp
= TBuffer
.Buffer
;
1142 for (pNode
= mIfrRecordListHead
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
1143 if (pNode
->mIfrBinBuf
!= NULL
) {
1144 memcpy (Temp
, pNode
->mIfrBinBuf
, pNode
->mBinBufLen
);
1145 Temp
+= pNode
->mBinBufLen
;
1153 CIfrRecordInfoDB::IfrRecordOutput (
1162 if (mSwitch
== FALSE
) {
1172 for (pNode
= mIfrRecordListHead
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
1173 if (pNode
->mLineNo
== LineNo
|| LineNo
== 0) {
1174 fprintf (File
, ">%08X: ", pNode
->mOffset
);
1175 TotalSize
+= pNode
->mBinBufLen
;
1176 if (pNode
->mIfrBinBuf
!= NULL
) {
1177 for (Index
= 0; Index
< pNode
->mBinBufLen
; Index
++) {
1178 fprintf (File
, "%02X ", (UINT8
)(pNode
->mIfrBinBuf
[Index
]));
1181 fprintf (File
, "\n");
1186 fprintf (File
, "\nTotal Size of all record is 0x%08X\n", TotalSize
);
1191 // for framework vfr file
1192 // adjust opcode sequence for uefi IFR format
1193 // adjust inconsistent and varstore into the right position.
1196 CIfrRecordInfoDB::CheckQuestionOpCode (
1201 case EFI_IFR_CHECKBOX_OP
:
1202 case EFI_IFR_NUMERIC_OP
:
1203 case EFI_IFR_PASSWORD_OP
:
1204 case EFI_IFR_ONE_OF_OP
:
1205 case EFI_IFR_ACTION_OP
:
1206 case EFI_IFR_STRING_OP
:
1207 case EFI_IFR_DATE_OP
:
1208 case EFI_IFR_TIME_OP
:
1209 case EFI_IFR_ORDERED_LIST_OP
:
1210 case EFI_IFR_REF_OP
:
1218 CIfrRecordInfoDB::CheckIdOpCode (
1223 case EFI_IFR_EQ_ID_VAL_OP
:
1224 case EFI_IFR_EQ_ID_ID_OP
:
1225 case EFI_IFR_EQ_ID_VAL_LIST_OP
:
1226 case EFI_IFR_QUESTION_REF1_OP
:
1234 CIfrRecordInfoDB::GetOpcodeQuestionId (
1235 IN EFI_IFR_OP_HEADER
*OpHead
1238 EFI_IFR_QUESTION_HEADER
*QuestionHead
;
1240 QuestionHead
= (EFI_IFR_QUESTION_HEADER
*) (OpHead
+ 1);
1242 return QuestionHead
->QuestionId
;
1246 CIfrRecordInfoDB::GetRecordInfoFromOffset (
1250 SIfrRecord
*pNode
= NULL
;
1252 for (pNode
= mIfrRecordListHead
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
1253 if (pNode
->mOffset
== Offset
) {
1262 Add just the op code position.
1264 Case1 (CreateOpcodeAfterParsingVfr == FALSE): The dynamic opcodes were created before the formset opcode,
1265 so pDynamicOpcodeNodes is before mIfrRecordListTail.
1269 |mIfrRecordListHead + ...+ pAdjustNode + pDynamicOpcodeNodes + mIfrRecordListTail|
1273 |mIfrRecordListHead + ...+ pDynamicOpcodeNodes + pAdjustNode + mIfrRecordListTail|
1275 Case2 (CreateOpcodeAfterParsingVfr == TRUE): The dynamic opcodes were created after paring the vfr file,
1276 so new records are appennded to the end of OriginalIfrRecordListTail.
1280 |mIfrRecordListHead + ...+ pAdjustNode + ... + OriginalIfrRecordListTail + pDynamicOpcodeNodes|
1284 |mIfrRecordListHead + ...+ pDynamicOpcodeNodes + pAdjustNode + ... + OriginalIfrRecordListTail|
1287 @param CreateOpcodeAfterParsingVfr Whether create the dynamic opcode after parsing the VFR file.
1291 CIfrRecordInfoDB::IfrAdjustDynamicOpcodeInRecords (
1292 IN BOOLEAN CreateOpcodeAfterParsingVfr
1295 UINT32 OpcodeOffset
;
1296 SIfrRecord
*pNode
, *pPreNode
;
1297 SIfrRecord
*pAdjustNode
, *pNodeBeforeAdjust
;
1298 SIfrRecord
*pNodeBeforeDynamic
;
1302 pNodeBeforeDynamic
= NULL
;
1306 // Base on the gAdjustOpcodeOffset and gAdjustOpcodeLen to find the pAdjustNod, the node before pAdjustNode,
1307 // and the node before pDynamicOpcodeNode.
1309 for (pNode
= mIfrRecordListHead
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
1310 if (OpcodeOffset
== gAdjustOpcodeOffset
) {
1311 pAdjustNode
= pNode
;
1312 pNodeBeforeAdjust
= pPreNode
;
1313 } else if (OpcodeOffset
== gAdjustOpcodeOffset
+ gAdjustOpcodeLen
) {
1314 pNodeBeforeDynamic
= pPreNode
;
1316 if (pNode
->mNext
!= NULL
) {
1319 OpcodeOffset
+= pNode
->mBinBufLen
;
1323 // Check the nodes whether exist.
1325 if (pNodeBeforeDynamic
== NULL
|| pAdjustNode
== NULL
|| pNodeBeforeAdjust
== NULL
) {
1330 // Adjust the node. pPreNode save the Node before mIfrRecordListTail
1332 pNodeBeforeAdjust
->mNext
= pNodeBeforeDynamic
->mNext
;
1333 if (CreateOpcodeAfterParsingVfr
) {
1335 // mIfrRecordListTail is the end of pDynamicNode (Case2).
1337 mIfrRecordListTail
->mNext
= pAdjustNode
;
1338 mIfrRecordListTail
= pNodeBeforeDynamic
;
1339 mIfrRecordListTail
->mNext
= NULL
;
1342 //pPreNode is the end of pDynamicNode(Case1).
1344 pPreNode
->mNext
= pAdjustNode
;
1345 pNodeBeforeDynamic
->mNext
= mIfrRecordListTail
;
1352 Update the record info(the position in the record list, offset and mIfrBinBuf) for new created record.
1354 @param CreateOpcodeAfterParsingVfr Whether create the dynamic opcode after parsing the VFR file.
1358 CIfrRecordInfoDB::IfrUpdateRecordInfoForDynamicOpcode (
1359 IN BOOLEAN CreateOpcodeAfterParsingVfr
1362 SIfrRecord
*pRecord
;
1365 // Base on the original offset info to update the record list.
1367 if (!IfrAdjustDynamicOpcodeInRecords(CreateOpcodeAfterParsingVfr
)) {
1368 gCVfrErrorHandle
.PrintMsg (0, "Error", "Can not find the adjust offset in the record.");
1372 // Base on the opcode binary length to recalculate the offset for each opcode.
1374 IfrAdjustOffsetForRecord();
1377 // Base on the offset to find the binary address.
1379 pRecord
= GetRecordInfoFromOffset(gAdjustOpcodeOffset
);
1380 while (pRecord
!= NULL
) {
1381 pRecord
->mIfrBinBuf
= gCFormPkg
.GetBufAddrBaseOnOffset(pRecord
->mOffset
);
1382 pRecord
= pRecord
->mNext
;
1388 CIfrRecordInfoDB::IfrAdjustOffsetForRecord (
1392 UINT32 OpcodeOffset
;
1396 for (pNode
= mIfrRecordListHead
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
1397 pNode
->mOffset
= OpcodeOffset
;
1398 OpcodeOffset
+= pNode
->mBinBufLen
;
1403 CIfrRecordInfoDB::IfrRecordAdjust (
1407 SIfrRecord
*pNode
, *preNode
;
1408 SIfrRecord
*uNode
, *tNode
;
1409 EFI_IFR_OP_HEADER
*OpHead
, *tOpHead
;
1410 EFI_QUESTION_ID QuestionId
;
1412 UINT32 QuestionScope
;
1413 UINT32 OpcodeOffset
;
1414 CHAR8 ErrorMsg
[MAX_STRING_LEN
] = {0, };
1415 EFI_VFR_RETURN_CODE Status
;
1418 // Init local variable
1420 Status
= VFR_RETURN_SUCCESS
;
1421 pNode
= mIfrRecordListHead
;
1424 while (pNode
!= NULL
) {
1425 OpHead
= (EFI_IFR_OP_HEADER
*) pNode
->mIfrBinBuf
;
1428 // make sure the inconsistent opcode in question scope
1430 if (QuestionScope
> 0) {
1431 QuestionScope
+= OpHead
->Scope
;
1432 if (OpHead
->OpCode
== EFI_IFR_END_OP
) {
1437 if (CheckQuestionOpCode (OpHead
->OpCode
)) {
1441 // for the inconsistent opcode not in question scope, adjust it
1443 if (OpHead
->OpCode
== EFI_IFR_INCONSISTENT_IF_OP
&& QuestionScope
== 0) {
1445 // for inconsistent opcode not in question scope
1449 // Count inconsistent opcode Scope
1451 StackCount
= OpHead
->Scope
;
1452 QuestionId
= EFI_QUESTION_ID_INVALID
;
1454 while (tNode
!= NULL
&& StackCount
> 0) {
1455 tNode
= tNode
->mNext
;
1456 tOpHead
= (EFI_IFR_OP_HEADER
*) tNode
->mIfrBinBuf
;
1458 // Calculate Scope Number
1460 StackCount
+= tOpHead
->Scope
;
1461 if (tOpHead
->OpCode
== EFI_IFR_END_OP
) {
1465 // by IdEqual opcode to get QuestionId
1467 if (QuestionId
== EFI_QUESTION_ID_INVALID
&&
1468 CheckIdOpCode (tOpHead
->OpCode
)) {
1469 QuestionId
= *(EFI_QUESTION_ID
*) (tOpHead
+ 1);
1472 if (tNode
== NULL
|| QuestionId
== EFI_QUESTION_ID_INVALID
) {
1474 // report error; not found
1476 sprintf (ErrorMsg
, "Inconsistent OpCode Record list invalid QuestionId is 0x%X", QuestionId
);
1477 gCVfrErrorHandle
.PrintMsg (0, NULL
, "Error", ErrorMsg
);
1478 Status
= VFR_RETURN_MISMATCHED
;
1482 // extract inconsistent opcode list
1483 // pNode is Incosistent opcode, tNode is End Opcode
1487 // insert inconsistent opcode list into the right question scope by questionid
1489 for (uNode
= mIfrRecordListHead
; uNode
!= NULL
; uNode
= uNode
->mNext
) {
1490 tOpHead
= (EFI_IFR_OP_HEADER
*) uNode
->mIfrBinBuf
;
1491 if (CheckQuestionOpCode (tOpHead
->OpCode
) &&
1492 (QuestionId
== GetOpcodeQuestionId (tOpHead
))) {
1497 // insert inconsistent opcode list and check LATE_CHECK flag
1499 if (uNode
!= NULL
) {
1500 if ((((EFI_IFR_QUESTION_HEADER
*)(tOpHead
+ 1))->Flags
& 0x20) != 0) {
1502 // if LATE_CHECK flag is set, change inconsistent to nosumbit
1504 OpHead
->OpCode
= EFI_IFR_NO_SUBMIT_IF_OP
;
1508 // skip the default storage for Date and Time
1510 if ((uNode
->mNext
!= NULL
) && (*uNode
->mNext
->mIfrBinBuf
== EFI_IFR_DEFAULT_OP
)) {
1511 uNode
= uNode
->mNext
;
1514 preNode
->mNext
= tNode
->mNext
;
1515 tNode
->mNext
= uNode
->mNext
;
1516 uNode
->mNext
= pNode
;
1518 // reset pNode to head list, scan the whole list again.
1520 pNode
= mIfrRecordListHead
;
1526 // not found matched question id, report error
1528 sprintf (ErrorMsg
, "QuestionId required by Inconsistent OpCode is not found. QuestionId is 0x%X", QuestionId
);
1529 gCVfrErrorHandle
.PrintMsg (0, NULL
, "Error", ErrorMsg
);
1530 Status
= VFR_RETURN_MISMATCHED
;
1533 } else if (OpHead
->OpCode
== EFI_IFR_VARSTORE_OP
||
1534 OpHead
->OpCode
== EFI_IFR_VARSTORE_EFI_OP
) {
1536 // for new added group of varstore opcode
1539 while (tNode
->mNext
!= NULL
) {
1540 tOpHead
= (EFI_IFR_OP_HEADER
*) tNode
->mNext
->mIfrBinBuf
;
1541 if (tOpHead
->OpCode
!= EFI_IFR_VARSTORE_OP
&&
1542 tOpHead
->OpCode
!= EFI_IFR_VARSTORE_EFI_OP
) {
1545 tNode
= tNode
->mNext
;
1548 if (tNode
->mNext
== NULL
) {
1550 // invalid IfrCode, IfrCode end by EndOpCode
1552 gCVfrErrorHandle
.PrintMsg (0, NULL
, "Error", "No found End Opcode in the end");
1553 Status
= VFR_RETURN_MISMATCHED
;
1557 if (tOpHead
->OpCode
!= EFI_IFR_END_OP
) {
1559 // not new added varstore, which are not needed to be adjust.
1562 pNode
= tNode
->mNext
;
1566 // move new added varstore opcode to the position befor form opcode
1567 // varstore opcode between pNode and tNode
1571 // search form opcode from begin
1573 for (uNode
= mIfrRecordListHead
; uNode
->mNext
!= NULL
; uNode
= uNode
->mNext
) {
1574 tOpHead
= (EFI_IFR_OP_HEADER
*) uNode
->mNext
->mIfrBinBuf
;
1575 if (tOpHead
->OpCode
== EFI_IFR_FORM_OP
) {
1580 // Insert varstore opcode beform form opcode if form opcode is found
1582 if (uNode
->mNext
!= NULL
) {
1583 preNode
->mNext
= tNode
->mNext
;
1584 tNode
->mNext
= uNode
->mNext
;
1585 uNode
->mNext
= pNode
;
1587 // reset pNode to head list, scan the whole list again.
1589 pNode
= mIfrRecordListHead
;
1595 // not found form, continue scan IfrRecord list
1598 pNode
= tNode
->mNext
;
1607 pNode
= pNode
->mNext
;
1611 // Update Ifr Opcode Offset
1613 if (Status
== VFR_RETURN_SUCCESS
) {
1614 IfrAdjustOffsetForRecord ();
1620 When the Varstore of the question is EFI_VFR_VARSTORE_BUFFER and the default value is not
1621 given by expression, should save the default info for the Buffer VarStore.
1623 @param DefaultId The default id.
1624 @param pQuestionNode Point to the question opcode node.
1625 @param Value The default value.
1628 CIfrRecordInfoDB::IfrAddDefaultToBufferConfig (
1629 IN UINT16 DefaultId
,
1630 IN SIfrRecord
*pQuestionNode
,
1631 IN EFI_IFR_TYPE_VALUE Value
1634 CHAR8
*VarStoreName
= NULL
;
1635 EFI_VFR_VARSTORE_TYPE VarStoreType
= EFI_VFR_VARSTORE_INVALID
;
1636 EFI_GUID
*VarGuid
= NULL
;
1637 EFI_VARSTORE_INFO VarInfo
;
1638 EFI_IFR_QUESTION_HEADER
*QuestionHead
;
1639 EFI_IFR_OP_HEADER
*pQuestionOpHead
;
1641 pQuestionOpHead
= (EFI_IFR_OP_HEADER
*) pQuestionNode
->mIfrBinBuf
;
1642 QuestionHead
= (EFI_IFR_QUESTION_HEADER
*) (pQuestionOpHead
+ 1);
1645 // Get the Var Store name and type.
1647 gCVfrDataStorage
.GetVarStoreName (QuestionHead
->VarStoreId
, &VarStoreName
);
1648 VarGuid
= gCVfrDataStorage
.GetVarStoreGuid (QuestionHead
->VarStoreId
);
1649 VarStoreType
= gCVfrDataStorage
.GetVarStoreType (QuestionHead
->VarStoreId
);
1652 // Only for Buffer storage need to save the default info in the storage.
1653 // Other type storage, just return.
1655 if (VarStoreType
!= EFI_VFR_VARSTORE_BUFFER
) {
1658 VarInfo
.mInfo
.mVarOffset
= QuestionHead
->VarStoreInfo
.VarOffset
;
1659 VarInfo
.mVarStoreId
= QuestionHead
->VarStoreId
;
1663 // Get the buffer storage info about this question.
1665 gCVfrDataStorage
.GetBufferVarStoreFieldInfo (&VarInfo
);
1670 gCVfrDefaultStore
.BufferVarStoreAltConfigAdd (
1681 Record the number and default id of all defaultstore opcode.
1685 CIfrRecordInfoDB::IfrGetDefaultStoreInfo (
1690 EFI_IFR_OP_HEADER
*pOpHead
;
1691 EFI_IFR_DEFAULTSTORE
*DefaultStore
;
1693 pNode
= mIfrRecordListHead
;
1694 mAllDefaultTypeCount
= 0;
1696 while (pNode
!= NULL
) {
1697 pOpHead
= (EFI_IFR_OP_HEADER
*) pNode
->mIfrBinBuf
;
1699 if (pOpHead
->OpCode
== EFI_IFR_DEFAULTSTORE_OP
){
1700 DefaultStore
= (EFI_IFR_DEFAULTSTORE
*) pNode
->mIfrBinBuf
;
1701 mAllDefaultIdArray
[mAllDefaultTypeCount
++] = DefaultStore
->DefaultId
;
1703 pNode
= pNode
->mNext
;
1708 Create new default opcode record.
1710 @param Size The new default opcode size.
1711 @param DefaultId The new default id.
1712 @param Type The new default type.
1713 @param LineNo The line number of the new record.
1714 @param Value The new default value.
1718 CIfrRecordInfoDB::IfrCreateDefaultRecord(
1720 IN UINT16 DefaultId
,
1723 IN EFI_IFR_TYPE_VALUE Value
1727 CIfrDefault2
*DObj2
;
1732 if (Type
== EFI_IFR_TYPE_OTHER
) {
1733 DObj2
= new CIfrDefault2 (Size
);
1734 DObj2
->SetDefaultId(DefaultId
);
1735 DObj2
->SetType(Type
);
1736 DObj2
->SetLineNo(LineNo
);
1737 DObj2
->SetScope (1);
1740 DObj
= new CIfrDefault (Size
);
1741 DObj
->SetDefaultId(DefaultId
);
1742 DObj
->SetType(Type
);
1743 DObj
->SetLineNo(LineNo
);
1744 DObj
->SetValue (Value
);
1750 Create new default opcode for question base on the QuestionDefaultInfo.
1752 @param pQuestionNode Point to the question opcode Node.
1753 @param QuestionDefaultInfo Point to the QuestionDefaultInfo for current question.
1757 CIfrRecordInfoDB::IfrCreateDefaultForQuestion (
1758 IN SIfrRecord
*pQuestionNode
,
1759 IN QuestionDefaultRecord
*QuestionDefaultInfo
1762 EFI_IFR_OP_HEADER
*pOpHead
;
1763 EFI_IFR_DEFAULT
*Default
;
1766 SIfrRecord
*pDefaultNode
;
1773 EFI_IFR_ONE_OF_OPTION
*DefaultOptionOpcode
;
1774 EFI_IFR_TYPE_VALUE CheckBoxDefaultValue
;
1776 CheckBoxDefaultValue
.b
= 1;
1777 pOpHead
= (EFI_IFR_OP_HEADER
*) pQuestionNode
->mIfrBinBuf
;
1783 // Record the offset of node which need to be adjust, will move the new created default opcode to this offset.
1785 gAdjustOpcodeOffset
= pQuestionNode
->mNext
->mOffset
;
1788 // For oneof, the default with smallest default id is given by the option flag.
1789 // So create the missing defaults base on the oneof option value(mDefaultValueRecord).
1791 if (pOpHead
->OpCode
== EFI_IFR_ONE_OF_OP
&& !QuestionDefaultInfo
->mIsDefaultOpcode
) {
1792 DefaultOptionOpcode
= (EFI_IFR_ONE_OF_OPTION
*)QuestionDefaultInfo
->mDefaultValueRecord
->mIfrBinBuf
;
1793 DefaultSize
= QuestionDefaultInfo
->mDefaultValueRecord
->mBinBufLen
- OFFSET_OF (EFI_IFR_ONE_OF_OPTION
, Value
);
1794 DefaultSize
+= OFFSET_OF (EFI_IFR_DEFAULT
, Value
);
1795 for (UINT8 i
= 0; i
< mAllDefaultTypeCount
; i
++) {
1796 if (!QuestionDefaultInfo
->mIsDefaultIdExist
[i
]) {
1797 IfrCreateDefaultRecord (DefaultSize
, mAllDefaultIdArray
[i
], DefaultOptionOpcode
->Type
, pQuestionNode
->mLineNo
, DefaultOptionOpcode
->Value
);
1799 // Save the new created default in the buffer storage.
1801 IfrAddDefaultToBufferConfig (mAllDefaultIdArray
[i
], pQuestionNode
, DefaultOptionOpcode
->Value
);
1809 // For checkbox, the default with smallest default id is given by the question flag.
1810 // And create the missing defaults with true value.
1812 if (pOpHead
-> OpCode
== EFI_IFR_CHECKBOX_OP
&& !QuestionDefaultInfo
->mIsDefaultOpcode
) {
1813 DefaultSize
= OFFSET_OF (EFI_IFR_DEFAULT
, Value
) + sizeof (BOOLEAN
);
1814 for (UINT8 i
= 0; i
< mAllDefaultTypeCount
; i
++) {
1815 if (!QuestionDefaultInfo
->mIsDefaultIdExist
[i
]) {
1816 IfrCreateDefaultRecord (DefaultSize
, mAllDefaultIdArray
[i
], EFI_IFR_TYPE_BOOLEAN
, pQuestionNode
->mLineNo
, CheckBoxDefaultValue
);
1818 // Save the new created default.
1820 IfrAddDefaultToBufferConfig (mAllDefaultIdArray
[i
], pQuestionNode
, CheckBoxDefaultValue
);
1828 // The default with smallest default id is given by the default opcode.
1829 // So create the missing defaults base on the value in the default opcode.
1833 // pDefaultNode point to the mDefaultValueRecord in QuestionDefaultInfo.
1835 pDefaultNode
= QuestionDefaultInfo
->mDefaultValueRecord
;
1836 Default
= (EFI_IFR_DEFAULT
*)pDefaultNode
->mIfrBinBuf
;
1838 // Record the offset of node which need to be adjust, will move the new created default opcode to this offset.
1840 gAdjustOpcodeOffset
= pDefaultNode
->mNext
->mOffset
;
1842 if (Default
->Type
== EFI_IFR_TYPE_OTHER
) {
1844 // EFI_IFR_DEFAULT_2 opcode.
1846 // Point to the first expression opcode.
1848 pSNode
= pDefaultNode
->mNext
;
1852 // Get opcode number behind the EFI_IFR_DEFAULT_2 until reach its END opcode (including the END opcode of EFI_IFR_DEFAULT_2)
1854 while (pSNode
!= NULL
&& pSNode
->mNext
!= NULL
&& ScopeCount
!= 0) {
1855 pOpHead
= (EFI_IFR_OP_HEADER
*) pSNode
->mIfrBinBuf
;
1856 if (pOpHead
->Scope
== 1) {
1859 if (pOpHead
->OpCode
== EFI_IFR_END_OP
) {
1863 pSNode
= pSNode
->mNext
;
1871 // Record the offset of node which need to be adjust, will move the new created default opcode to this offset.
1873 gAdjustOpcodeOffset
= pSNode
->mOffset
;
1875 // Create new default opcode node for missing default.
1877 for (UINT8 i
= 0; i
< mAllDefaultTypeCount
; i
++) {
1878 OpcodeNumber
= OpcodeCount
;
1879 if (!QuestionDefaultInfo
->mIsDefaultIdExist
[i
]) {
1880 IfrCreateDefaultRecord (Default
->Header
.Length
, mAllDefaultIdArray
[i
], Default
->Type
, pENode
->mLineNo
, Default
->Value
);
1882 // Point to the first expression opcode node.
1884 pSNode
= pDefaultNode
->mNext
;
1886 // Create the expression opcode and end opcode for the new created EFI_IFR_DEFAULT_2 opcode.
1888 while (pSNode
!= NULL
&& pSNode
->mNext
!= NULL
&& OpcodeNumber
-- != 0) {
1889 pOpHead
= (EFI_IFR_OP_HEADER
*) pSNode
->mIfrBinBuf
;
1890 Obj
= new CIfrObj (pOpHead
->OpCode
, NULL
, pSNode
->mBinBufLen
, FALSE
);
1891 assert (Obj
!= NULL
);
1892 Obj
->SetLineNo (pSNode
->mLineNo
);
1893 ObjBinBuf
= Obj
->GetObjBinAddr();
1894 memcpy (ObjBinBuf
, pSNode
->mIfrBinBuf
, (UINTN
)pSNode
->mBinBufLen
);
1896 pSNode
= pSNode
->mNext
;
1902 // EFI_IFR_DEFAULT opcode.
1904 // Create new default opcode node for missing default.
1906 for (UINT8 i
= 0; i
< mAllDefaultTypeCount
; i
++) {
1907 if (!QuestionDefaultInfo
->mIsDefaultIdExist
[i
]) {
1908 IfrCreateDefaultRecord (Default
->Header
.Length
, mAllDefaultIdArray
[i
], Default
->Type
, pDefaultNode
->mLineNo
, Default
->Value
);
1910 // Save the new created default in the buffer storage..
1912 IfrAddDefaultToBufferConfig (mAllDefaultIdArray
[i
], pQuestionNode
, Default
->Value
);
1919 Parse the default information in a question, get the QuestionDefaultInfo.
1921 @param pQuestionNode Point to the question record Node.
1922 @param QuestionDefaultInfo On return, point to the QuestionDefaultInfo.
1925 CIfrRecordInfoDB::IfrParseDefaulInfoInQuestion(
1926 IN SIfrRecord
*pQuestionNode
,
1927 OUT QuestionDefaultRecord
*QuestionDefaultInfo
1931 EFI_IFR_ONE_OF_OPTION
*OneofOptionOpcode
;
1932 EFI_IFR_OP_HEADER
*pSOpHead
;
1933 EFI_IFR_CHECKBOX
*CheckBoxOpcode
;
1934 EFI_IFR_DEFAULT
*DefaultOpcode
;
1935 BOOLEAN IsOneOfOpcode
;
1936 UINT16 SmallestDefaultId
;
1939 SmallestDefaultId
= 0xffff;
1940 IsOneOfOpcode
= FALSE
;
1942 pSNode
= pQuestionNode
;
1945 // Parse all the opcodes in the Question.
1947 while (pSNode
!= NULL
) {
1948 pSOpHead
= (EFI_IFR_OP_HEADER
*) pSNode
->mIfrBinBuf
;
1950 // For a question, its scope bit must be set, the scope exists until it reaches a corresponding EFI_IFR_END_OP.
1951 // Scopes may be nested within other scopes.
1952 // When finishing parsing a question, the scope count must be zero.
1954 if (pSOpHead
->Scope
== 1) {
1957 if (pSOpHead
->OpCode
== EFI_IFR_END_OP
) {
1961 // Check whether finishing parsing a question.
1963 if (ScopeCount
== 0) {
1968 // Record the default information in the question.
1970 switch (pSOpHead
->OpCode
) {
1971 case EFI_IFR_ONE_OF_OP
:
1972 IsOneOfOpcode
= TRUE
;
1974 case EFI_IFR_CHECKBOX_OP
:
1976 // The default info of check box may be given by flag.
1977 // So need to check the flag of check box.
1979 CheckBoxOpcode
= (EFI_IFR_CHECKBOX
*)pSNode
->mIfrBinBuf
;
1980 if ((CheckBoxOpcode
->Flags
& EFI_IFR_CHECKBOX_DEFAULT
) != 0) {
1982 // Check whether need to update the smallest default id.
1984 if (SmallestDefaultId
> EFI_HII_DEFAULT_CLASS_STANDARD
) {
1985 SmallestDefaultId
= EFI_HII_DEFAULT_CLASS_STANDARD
;
1988 // Update the QuestionDefaultInfo.
1990 for (UINT8 i
= 0; i
< mAllDefaultTypeCount
; i
++) {
1991 if (mAllDefaultIdArray
[i
] == EFI_HII_DEFAULT_CLASS_STANDARD
) {
1992 if (!QuestionDefaultInfo
->mIsDefaultIdExist
[i
]) {
1993 QuestionDefaultInfo
->mDefaultNumber
++;
1994 QuestionDefaultInfo
->mIsDefaultIdExist
[i
] = TRUE
;
2000 if ((CheckBoxOpcode
->Flags
& EFI_IFR_CHECKBOX_DEFAULT_MFG
) != 0) {
2002 // Check whether need to update the smallest default id.
2004 if (SmallestDefaultId
> EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
2005 SmallestDefaultId
= EFI_HII_DEFAULT_CLASS_MANUFACTURING
;
2008 // Update the QuestionDefaultInfo.
2010 for (UINT8 i
= 0; i
< mAllDefaultTypeCount
; i
++) {
2011 if (mAllDefaultIdArray
[i
] == EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
2012 if (!QuestionDefaultInfo
->mIsDefaultIdExist
[i
]) {
2013 QuestionDefaultInfo
->mDefaultNumber
++;
2014 QuestionDefaultInfo
->mIsDefaultIdExist
[i
] = TRUE
;
2021 case EFI_IFR_ONE_OF_OPTION_OP
:
2022 if (!IsOneOfOpcode
) {
2024 // Only check the option in oneof.
2028 OneofOptionOpcode
= (EFI_IFR_ONE_OF_OPTION
*)pSNode
->mIfrBinBuf
;
2029 if ((OneofOptionOpcode
->Flags
& EFI_IFR_OPTION_DEFAULT
) != 0) {
2031 // The option is used as the standard default.
2032 // Check whether need to update the smallest default id and QuestionDefaultInfo.
2034 if (SmallestDefaultId
> EFI_HII_DEFAULT_CLASS_STANDARD
) {
2035 SmallestDefaultId
= EFI_HII_DEFAULT_CLASS_STANDARD
;
2036 QuestionDefaultInfo
->mDefaultValueRecord
= pSNode
;
2039 // Update the IsDefaultIdExist array in QuestionDefaultInfo.
2041 for (UINT8 i
= 0; i
< mAllDefaultTypeCount
; i
++) {
2042 if (mAllDefaultIdArray
[i
] == EFI_HII_DEFAULT_CLASS_STANDARD
) {
2043 if (!QuestionDefaultInfo
->mIsDefaultIdExist
[i
]) {
2044 QuestionDefaultInfo
->mDefaultNumber
++;
2045 QuestionDefaultInfo
->mIsDefaultIdExist
[i
] = TRUE
;
2051 if ((OneofOptionOpcode
->Flags
& EFI_IFR_OPTION_DEFAULT_MFG
) != 0) {
2053 // This option is used as the manufacture default.
2054 // Check whether need to update the smallest default id and QuestionDefaultInfo.
2056 if (SmallestDefaultId
> EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
2057 SmallestDefaultId
= EFI_HII_DEFAULT_CLASS_MANUFACTURING
;
2058 QuestionDefaultInfo
->mDefaultValueRecord
= pSNode
;
2061 // Update the QuestionDefaultInfo.
2063 for (UINT8 i
= 0; i
< mAllDefaultTypeCount
; i
++) {
2064 if (mAllDefaultIdArray
[i
] == EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
2065 if (!QuestionDefaultInfo
->mIsDefaultIdExist
[i
]) {
2066 QuestionDefaultInfo
->mDefaultNumber
++;
2067 QuestionDefaultInfo
->mIsDefaultIdExist
[i
] = TRUE
;
2074 case EFI_IFR_DEFAULT_OP
:
2075 DefaultOpcode
= (EFI_IFR_DEFAULT
*) pSNode
->mIfrBinBuf
;
2077 // Check whether need to update the smallest default id and QuestionDefaultInfo.
2079 if (SmallestDefaultId
>= DefaultOpcode
->DefaultId
) {
2080 SmallestDefaultId
= DefaultOpcode
->DefaultId
;
2081 QuestionDefaultInfo
->mDefaultValueRecord
= pSNode
;
2082 QuestionDefaultInfo
->mIsDefaultOpcode
= TRUE
;
2085 // Update the QuestionDefaultInfo.
2087 for (UINT8 i
= 0; i
< mAllDefaultTypeCount
; i
++){
2088 if (mAllDefaultIdArray
[i
] == ((EFI_IFR_DEFAULT
*)pSNode
->mIfrBinBuf
)->DefaultId
) {
2089 if (!QuestionDefaultInfo
->mIsDefaultIdExist
[i
]) {
2090 QuestionDefaultInfo
->mDefaultNumber
++;
2091 QuestionDefaultInfo
->mIsDefaultIdExist
[i
] = TRUE
;
2101 // Parse next opcode in this question.
2103 pSNode
= pSNode
->mNext
;
2108 Check or add default for question if need.
2110 This function will check the default info for question.
2111 If the question has default, but the default number < defaultstore opcode number.
2112 will do following two action :
2114 1. if (AutoDefault) will add default for question to support all kinds of defaults.
2115 2. if (CheckDefault) will generate an error to tell user the question misses some default value.
2117 We assume that the two options can not be TRUE at same time.
2118 If they are TRUE at same time, only do the action corresponding to AutoDefault option.
2120 @param AutoDefault Add default for question if needed
2121 @param CheckDefault Check the default info, if missing default, generates an error.
2125 CIfrRecordInfoDB::IfrCheckAddDefaultRecord (
2126 BOOLEAN AutoDefault
,
2127 BOOLEAN CheckDefault
2131 SIfrRecord
*pTailNode
;
2132 SIfrRecord
*pStartAdjustNode
;
2133 EFI_IFR_OP_HEADER
*pOpHead
;
2134 QuestionDefaultRecord QuestionDefaultInfo
;
2135 UINT8 MissingDefaultCount
;
2136 CHAR8 Msg
[MAX_STRING_LEN
] = {0, };
2138 pNode
= mIfrRecordListHead
;
2141 // Record the number and default id of all defaultstore opcode.
2143 IfrGetDefaultStoreInfo ();
2145 while (pNode
!= NULL
) {
2146 pOpHead
= (EFI_IFR_OP_HEADER
*) pNode
->mIfrBinBuf
;
2148 // Check whether is question opcode.
2150 if (CheckQuestionOpCode (pOpHead
->OpCode
)) {
2152 // Initialize some local variables here, because they vary with question.
2153 // Record the mIfrRecordListTail for each question, because may create default node for question after mIfrRecordListTail.
2155 memset (&QuestionDefaultInfo
, 0, sizeof (QuestionDefaultRecord
));
2156 pTailNode
= mIfrRecordListTail
;
2158 // Get the QuestionDefaultInfo for current question.
2160 IfrParseDefaulInfoInQuestion (pNode
, &QuestionDefaultInfo
);
2162 if (QuestionDefaultInfo
.mDefaultNumber
!= mAllDefaultTypeCount
&& QuestionDefaultInfo
.mDefaultNumber
!= 0) {
2165 // Create default for question which misses default.
2167 IfrCreateDefaultForQuestion (pNode
, &QuestionDefaultInfo
);
2170 // Adjust the buffer content.
2171 // pStartAdjustNode->mIfrBinBuf points to the insert position.
2172 // pTailNode->mNext->mIfrBinBuf points to the inset opcodes.
2174 pStartAdjustNode
=GetRecordInfoFromOffset (gAdjustOpcodeOffset
);
2175 gCFormPkg
.AdjustDynamicInsertOpcode (pStartAdjustNode
->mIfrBinBuf
, pTailNode
->mNext
->mIfrBinBuf
, TRUE
);
2178 // Update the record info.
2180 IfrUpdateRecordInfoForDynamicOpcode (TRUE
);
2181 } else if (CheckDefault
) {
2183 // Generate an error for question which misses default.
2185 MissingDefaultCount
= mAllDefaultTypeCount
- QuestionDefaultInfo
.mDefaultNumber
;
2186 sprintf (Msg
, "The question misses %d default, the question's opcode is %d", MissingDefaultCount
, pOpHead
->OpCode
);
2187 gCVfrErrorHandle
.PrintMsg (pNode
->mLineNo
, NULL
, "Error", Msg
);
2192 // parse next opcode.
2194 pNode
= pNode
->mNext
;
2198 CIfrRecordInfoDB gCIfrRecordInfoDB
;
2201 CIfrObj::_EMIT_PENDING_OBJ (
2205 CHAR8
*ObjBinBuf
= NULL
;
2210 if (!mDelayEmit
|| !gCreateOp
) {
2214 mPkgOffset
= gCFormPkg
.GetPkgLength ();
2216 // update data buffer to package data
2218 ObjBinBuf
= gCFormPkg
.IfrBinBufferGet (mObjBinLen
);
2219 if (ObjBinBuf
!= NULL
) {
2220 memmove (ObjBinBuf
, mObjBinBuf
, mObjBinLen
);
2224 // update bin buffer to package data buffer
2226 if (mObjBinBuf
!= NULL
) {
2228 mObjBinBuf
= ObjBinBuf
;
2235 * The definition of CIfrObj's member function
2240 } gOpcodeSizesScopeTable
[] = {
2241 { 0, 0 }, // EFI_IFR_INVALID - 0x00
2242 { sizeof (EFI_IFR_FORM
), 1 }, // EFI_IFR_FORM_OP
2243 { sizeof (EFI_IFR_SUBTITLE
), 1 }, // EFI_IFR_SUBTITLE_OP
2244 { sizeof (EFI_IFR_TEXT
), 0 }, // EFI_IFR_TEXT_OP
2245 { sizeof (EFI_IFR_IMAGE
), 0 }, // EFI_IFR_IMAGE_OP
2246 { sizeof (EFI_IFR_ONE_OF
), 1 }, // EFI_IFR_ONE_OF_OP - 0x05
2247 { sizeof (EFI_IFR_CHECKBOX
), 1}, // EFI_IFR_CHECKBOX_OP
2248 { sizeof (EFI_IFR_NUMERIC
), 1 }, // EFI_IFR_NUMERIC_OP
2249 { sizeof (EFI_IFR_PASSWORD
), 1 }, // EFI_IFR_PASSWORD_OP
2250 { sizeof (EFI_IFR_ONE_OF_OPTION
), 0 }, // EFI_IFR_ONE_OF_OPTION_OP
2251 { sizeof (EFI_IFR_SUPPRESS_IF
), 1 }, // EFI_IFR_SUPPRESS_IF - 0x0A
2252 { sizeof (EFI_IFR_LOCKED
), 0 }, // EFI_IFR_LOCKED_OP
2253 { sizeof (EFI_IFR_ACTION
), 1 }, // EFI_IFR_ACTION_OP
2254 { sizeof (EFI_IFR_RESET_BUTTON
), 1 }, // EFI_IFR_RESET_BUTTON_OP
2255 { sizeof (EFI_IFR_FORM_SET
), 1 }, // EFI_IFR_FORM_SET_OP -0xE
2256 { sizeof (EFI_IFR_REF
), 0 }, // EFI_IFR_REF_OP
2257 { sizeof (EFI_IFR_NO_SUBMIT_IF
), 1}, // EFI_IFR_NO_SUBMIT_IF_OP -0x10
2258 { sizeof (EFI_IFR_INCONSISTENT_IF
), 1 }, // EFI_IFR_INCONSISTENT_IF_OP
2259 { sizeof (EFI_IFR_EQ_ID_VAL
), 0 }, // EFI_IFR_EQ_ID_VAL_OP
2260 { sizeof (EFI_IFR_EQ_ID_ID
), 0 }, // EFI_IFR_EQ_ID_ID_OP
2261 { sizeof (EFI_IFR_EQ_ID_VAL_LIST
), 0 }, // EFI_IFR_EQ_ID_LIST_OP - 0x14
2262 { sizeof (EFI_IFR_AND
), 0 }, // EFI_IFR_AND_OP
2263 { sizeof (EFI_IFR_OR
), 0 }, // EFI_IFR_OR_OP
2264 { sizeof (EFI_IFR_NOT
), 0 }, // EFI_IFR_NOT_OP
2265 { sizeof (EFI_IFR_RULE
), 1 }, // EFI_IFR_RULE_OP
2266 { sizeof (EFI_IFR_GRAY_OUT_IF
), 1 }, // EFI_IFR_GRAYOUT_IF_OP - 0x19
2267 { sizeof (EFI_IFR_DATE
), 1 }, // EFI_IFR_DATE_OP
2268 { sizeof (EFI_IFR_TIME
), 1 }, // EFI_IFR_TIME_OP
2269 { sizeof (EFI_IFR_STRING
), 1 }, // EFI_IFR_STRING_OP
2270 { sizeof (EFI_IFR_REFRESH
), 0 }, // EFI_IFR_REFRESH_OP
2271 { sizeof (EFI_IFR_DISABLE_IF
), 1 }, // EFI_IFR_DISABLE_IF_OP - 0x1E
2273 { sizeof (EFI_IFR_TO_LOWER
), 0 }, // EFI_IFR_TO_LOWER_OP - 0x20
2274 { sizeof (EFI_IFR_TO_UPPER
), 0 }, // EFI_IFR_TO_UPPER_OP - 0x21
2275 { sizeof (EFI_IFR_MAP
), 1 }, // EFI_IFR_MAP - 0x22
2276 { sizeof (EFI_IFR_ORDERED_LIST
), 1 }, // EFI_IFR_ORDERED_LIST_OP - 0x23
2277 { sizeof (EFI_IFR_VARSTORE
), 0 }, // EFI_IFR_VARSTORE_OP
2278 { sizeof (EFI_IFR_VARSTORE_NAME_VALUE
), 0 }, // EFI_IFR_VARSTORE_NAME_VALUE_OP
2279 { sizeof (EFI_IFR_VARSTORE_EFI
), 0 }, // EFI_IFR_VARSTORE_EFI_OP
2280 { sizeof (EFI_IFR_VARSTORE_DEVICE
), 1 }, // EFI_IFR_VARSTORE_DEVICE_OP
2281 { sizeof (EFI_IFR_VERSION
), 0 }, // EFI_IFR_VERSION_OP - 0x28
2282 { sizeof (EFI_IFR_END
), 0 }, // EFI_IFR_END_OP
2283 { sizeof (EFI_IFR_MATCH
), 0 }, // EFI_IFR_MATCH_OP - 0x2A
2284 { sizeof (EFI_IFR_GET
), 0 }, // EFI_IFR_GET - 0x2B
2285 { sizeof (EFI_IFR_SET
), 0 }, // EFI_IFR_SET - 0x2C
2286 { sizeof (EFI_IFR_READ
), 0 }, // EFI_IFR_READ - 0x2D
2287 { sizeof (EFI_IFR_WRITE
), 0 }, // EFI_IFR_WRITE - 0x2E
2288 { sizeof (EFI_IFR_EQUAL
), 0 }, // EFI_IFR_EQUAL_OP - 0x2F
2289 { sizeof (EFI_IFR_NOT_EQUAL
), 0 }, // EFI_IFR_NOT_EQUAL_OP
2290 { sizeof (EFI_IFR_GREATER_THAN
), 0 }, // EFI_IFR_GREATER_THAN_OP
2291 { sizeof (EFI_IFR_GREATER_EQUAL
), 0 }, // EFI_IFR_GREATER_EQUAL_OP
2292 { sizeof (EFI_IFR_LESS_THAN
), 0 }, // EFI_IFR_LESS_THAN_OP
2293 { sizeof (EFI_IFR_LESS_EQUAL
), 0 }, // EFI_IFR_LESS_EQUAL_OP - 0x34
2294 { sizeof (EFI_IFR_BITWISE_AND
), 0 }, // EFI_IFR_BITWISE_AND_OP
2295 { sizeof (EFI_IFR_BITWISE_OR
), 0 }, // EFI_IFR_BITWISE_OR_OP
2296 { sizeof (EFI_IFR_BITWISE_NOT
), 0 }, // EFI_IFR_BITWISE_NOT_OP
2297 { sizeof (EFI_IFR_SHIFT_LEFT
), 0 }, // EFI_IFR_SHIFT_LEFT_OP
2298 { sizeof (EFI_IFR_SHIFT_RIGHT
), 0 }, // EFI_IFR_SHIFT_RIGHT_OP
2299 { sizeof (EFI_IFR_ADD
), 0 }, // EFI_IFR_ADD_OP - 0x3A
2300 { sizeof (EFI_IFR_SUBTRACT
), 0 }, // EFI_IFR_SUBTRACT_OP
2301 { sizeof (EFI_IFR_MULTIPLY
), 0 }, // EFI_IFR_MULTIPLY_OP
2302 { sizeof (EFI_IFR_DIVIDE
), 0 }, // EFI_IFR_DIVIDE_OP
2303 { sizeof (EFI_IFR_MODULO
), 0 }, // EFI_IFR_MODULO_OP - 0x3E
2304 { sizeof (EFI_IFR_RULE_REF
), 0 }, // EFI_IFR_RULE_REF_OP
2305 { sizeof (EFI_IFR_QUESTION_REF1
), 0 }, // EFI_IFR_QUESTION_REF1_OP
2306 { sizeof (EFI_IFR_QUESTION_REF2
), 0 }, // EFI_IFR_QUESTION_REF2_OP - 0x41
2307 { sizeof (EFI_IFR_UINT8
), 0}, // EFI_IFR_UINT8
2308 { sizeof (EFI_IFR_UINT16
), 0}, // EFI_IFR_UINT16
2309 { sizeof (EFI_IFR_UINT32
), 0}, // EFI_IFR_UINT32
2310 { sizeof (EFI_IFR_UINT64
), 0}, // EFI_IFR_UTNT64
2311 { sizeof (EFI_IFR_TRUE
), 0 }, // EFI_IFR_TRUE_OP - 0x46
2312 { sizeof (EFI_IFR_FALSE
), 0 }, // EFI_IFR_FALSE_OP
2313 { sizeof (EFI_IFR_TO_UINT
), 0 }, // EFI_IFR_TO_UINT_OP
2314 { sizeof (EFI_IFR_TO_STRING
), 0 }, // EFI_IFR_TO_STRING_OP
2315 { sizeof (EFI_IFR_TO_BOOLEAN
), 0 }, // EFI_IFR_TO_BOOLEAN_OP
2316 { sizeof (EFI_IFR_MID
), 0 }, // EFI_IFR_MID_OP
2317 { sizeof (EFI_IFR_FIND
), 0 }, // EFI_IFR_FIND_OP
2318 { sizeof (EFI_IFR_TOKEN
), 0 }, // EFI_IFR_TOKEN_OP
2319 { sizeof (EFI_IFR_STRING_REF1
), 0 }, // EFI_IFR_STRING_REF1_OP - 0x4E
2320 { sizeof (EFI_IFR_STRING_REF2
), 0 }, // EFI_IFR_STRING_REF2_OP
2321 { sizeof (EFI_IFR_CONDITIONAL
), 0 }, // EFI_IFR_CONDITIONAL_OP
2322 { sizeof (EFI_IFR_QUESTION_REF3
), 0 }, // EFI_IFR_QUESTION_REF3_OP
2323 { sizeof (EFI_IFR_ZERO
), 0 }, // EFI_IFR_ZERO_OP
2324 { sizeof (EFI_IFR_ONE
), 0 }, // EFI_IFR_ONE_OP
2325 { sizeof (EFI_IFR_ONES
), 0 }, // EFI_IFR_ONES_OP
2326 { sizeof (EFI_IFR_UNDEFINED
), 0 }, // EFI_IFR_UNDEFINED_OP
2327 { sizeof (EFI_IFR_LENGTH
), 0 }, // EFI_IFR_LENGTH_OP
2328 { sizeof (EFI_IFR_DUP
), 0 }, // EFI_IFR_DUP_OP - 0x57
2329 { sizeof (EFI_IFR_THIS
), 0 }, // EFI_IFR_THIS_OP
2330 { sizeof (EFI_IFR_SPAN
), 0 }, // EFI_IFR_SPAN_OP
2331 { sizeof (EFI_IFR_VALUE
), 1 }, // EFI_IFR_VALUE_OP
2332 { sizeof (EFI_IFR_DEFAULT
), 0 }, // EFI_IFR_DEFAULT_OP
2333 { sizeof (EFI_IFR_DEFAULTSTORE
), 0 }, // EFI_IFR_DEFAULTSTORE_OP - 0x5C
2334 { sizeof (EFI_IFR_FORM_MAP
), 1}, // EFI_IFR_FORM_MAP_OP - 0x5D
2335 { sizeof (EFI_IFR_CATENATE
), 0 }, // EFI_IFR_CATENATE_OP
2336 { sizeof (EFI_IFR_GUID
), 0 }, // EFI_IFR_GUID_OP
2337 { sizeof (EFI_IFR_SECURITY
), 0 }, // EFI_IFR_SECURITY_OP - 0x60
2338 { sizeof (EFI_IFR_MODAL_TAG
), 0}, // EFI_IFR_MODAL_TAG_OP - 0x61
2339 { sizeof (EFI_IFR_REFRESH_ID
), 0}, // EFI_IFR_REFRESH_ID_OP - 0x62
2340 { sizeof (EFI_IFR_WARNING_IF
), 1}, // EFI_IFR_WARNING_IF_OP - 0x63
2341 { sizeof (EFI_IFR_MATCH2
), 0 }, // EFI_IFR_MATCH2_OP - 0x64
2344 #ifdef CIFROBJ_DEUBG
2347 } gIfrObjPrintDebugTable
[] = {
2348 "EFI_IFR_INVALID", "EFI_IFR_FORM", "EFI_IFR_SUBTITLE", "EFI_IFR_TEXT", "EFI_IFR_IMAGE", "EFI_IFR_ONE_OF",
2349 "EFI_IFR_CHECKBOX", "EFI_IFR_NUMERIC", "EFI_IFR_PASSWORD", "EFI_IFR_ONE_OF_OPTION", "EFI_IFR_SUPPRESS_IF", "EFI_IFR_LOCKED",
2350 "EFI_IFR_ACTION", "EFI_IFR_RESET_BUTTON", "EFI_IFR_FORM_SET", "EFI_IFR_REF", "EFI_IFR_NO_SUBMIT_IF", "EFI_IFR_INCONSISTENT_IF",
2351 "EFI_IFR_EQ_ID_VAL", "EFI_IFR_EQ_ID_ID", "EFI_IFR_EQ_ID_LIST", "EFI_IFR_AND", "EFI_IFR_OR", "EFI_IFR_NOT",
2352 "EFI_IFR_RULE", "EFI_IFR_GRAY_OUT_IF", "EFI_IFR_DATE", "EFI_IFR_TIME", "EFI_IFR_STRING", "EFI_IFR_REFRESH",
2353 "EFI_IFR_DISABLE_IF", "EFI_IFR_INVALID", "EFI_IFR_TO_LOWER", "EFI_IFR_TO_UPPER", "EFI_IFR_MAP", "EFI_IFR_ORDERED_LIST",
2354 "EFI_IFR_VARSTORE", "EFI_IFR_VARSTORE_NAME_VALUE", "EFI_IFR_VARSTORE_EFI", "EFI_IFR_VARSTORE_DEVICE", "EFI_IFR_VERSION", "EFI_IFR_END",
2355 "EFI_IFR_MATCH", "EFI_IFR_GET", "EFI_IFR_SET", "EFI_IFR_READ", "EFI_IFR_WRITE", "EFI_IFR_EQUAL",
2356 "EFI_IFR_NOT_EQUAL", "EFI_IFR_GREATER_THAN", "EFI_IFR_GREATER_EQUAL", "EFI_IFR_LESS_THAN", "EFI_IFR_LESS_EQUAL", "EFI_IFR_BITWISE_AND",
2357 "EFI_IFR_BITWISE_OR", "EFI_IFR_BITWISE_NOT", "EFI_IFR_SHIFT_LEFT", "EFI_IFR_SHIFT_RIGHT", "EFI_IFR_ADD", "EFI_IFR_SUBTRACT",
2358 "EFI_IFR_MULTIPLY", "EFI_IFR_DIVIDE", "EFI_IFR_MODULO", "EFI_IFR_RULE_REF", "EFI_IFR_QUESTION_REF1", "EFI_IFR_QUESTION_REF2",
2359 "EFI_IFR_UINT8", "EFI_IFR_UINT16", "EFI_IFR_UINT32", "EFI_IFR_UINT64", "EFI_IFR_TRUE", "EFI_IFR_FALSE",
2360 "EFI_IFR_TO_UINT", "EFI_IFR_TO_STRING", "EFI_IFR_TO_BOOLEAN", "EFI_IFR_MID", "EFI_IFR_FIND", "EFI_IFR_TOKEN",
2361 "EFI_IFR_STRING_REF1","EFI_IFR_STRING_REF2", "EFI_IFR_CONDITIONAL", "EFI_IFR_QUESTION_REF3", "EFI_IFR_ZERO", "EFI_IFR_ONE",
2362 "EFI_IFR_ONES", "EFI_IFR_UNDEFINED", "EFI_IFR_LENGTH", "EFI_IFR_DUP", "EFI_IFR_THIS", "EFI_IFR_SPAN",
2363 "EFI_IFR_VALUE", "EFI_IFR_DEFAULT", "EFI_IFR_DEFAULTSTORE", "EFI_IFR_FORM_MAP", "EFI_IFR_CATENATE", "EFI_IFR_GUID",
2364 "EFI_IFR_SECURITY", "EFI_IFR_MODAL_TAG", "EFI_IFR_REFRESH_ID", "EFI_IFR_WARNING_IF", "EFI_IFR_MATCH2",
2368 CIFROBJ_DEBUG_PRINT (
2372 printf ("======Create IFR [%s]\n", gIfrObjPrintDebugTable
[OpCode
].mIfrName
);
2376 #define CIFROBJ_DEBUG_PRINT(OpCode)
2380 BOOLEAN gCreateOp
= TRUE
;
2386 IN BOOLEAN DelayEmit
2389 mDelayEmit
= DelayEmit
;
2390 mPkgOffset
= gCFormPkg
.GetPkgLength ();
2391 mObjBinLen
= (ObjBinLen
== 0) ? gOpcodeSizesScopeTable
[OpCode
].mSize
: ObjBinLen
;
2392 mObjBinBuf
= ((DelayEmit
== FALSE
) && (gCreateOp
== TRUE
)) ? gCFormPkg
.IfrBinBufferGet (mObjBinLen
) : new CHAR8
[EFI_IFR_MAX_LENGTH
];
2393 mRecordIdx
= (gCreateOp
== TRUE
) ? gCIfrRecordInfoDB
.IfrRecordRegister (0xFFFFFFFF, mObjBinBuf
, mObjBinLen
, mPkgOffset
) : EFI_IFR_RECORDINFO_IDX_INVALUD
;
2395 assert (mObjBinBuf
!= NULL
);
2397 if (IfrObj
!= NULL
) {
2398 *IfrObj
= mObjBinBuf
;
2401 CIFROBJ_DEBUG_PRINT (OpCode
);
2408 if ((mDelayEmit
== TRUE
) && ((gCreateOp
== TRUE
))) {
2409 _EMIT_PENDING_OBJ ();
2412 gCIfrRecordInfoDB
.IfrRecordInfoUpdate (mRecordIdx
, mLineNo
, mObjBinBuf
, mObjBinLen
, mPkgOffset
);
2416 * The definition of CIfrObj's member function
2418 UINT8 gScopeCount
= 0;
2420 CIfrOpHeader::CIfrOpHeader (
2424 ) : mHeader ((EFI_IFR_OP_HEADER
*)StartAddr
)
2426 mHeader
->OpCode
= OpCode
;
2427 mHeader
->Length
= (Length
== 0) ? gOpcodeSizesScopeTable
[OpCode
].mSize
: Length
;
2428 mHeader
->Scope
= (gOpcodeSizesScopeTable
[OpCode
].mScope
+ gScopeCount
> 0) ? 1 : 0;
2431 CIfrOpHeader::CIfrOpHeader (
2432 IN CIfrOpHeader
&OpHdr
2435 mHeader
= OpHdr
.mHeader
;
2438 UINT32
CIfrFormId::FormIdBitMap
[EFI_FREE_FORM_ID_BITMAP_SIZE
] = {0, };