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
;
833 // Declare all questions as Numeric in DisableIf True
837 DIObj
.SetLineNo (LineNo
);
838 *InsertOpcodeAddr
= DIObj
.GetObjBinAddr ();
841 CIfrTrue
TObj (LineNo
);
843 // Declare Numeric qeustion for each undefined question.
844 for (pNode
= PendingAssignList
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
845 if (pNode
->mFlag
== PENDING
) {
847 EFI_VARSTORE_INFO Info
;
848 EFI_QUESTION_ID QId
= EFI_QUESTION_ID_INVALID
;
850 CNObj
.SetLineNo (LineNo
);
851 CNObj
.SetPrompt (0x0);
855 // Register this question, assume it is normal question, not date or time question
857 VarStr
= pNode
->mKey
;
858 ReturnCode
= lCVfrQuestionDB
.RegisterQuestion (NULL
, VarStr
, QId
);
859 if (ReturnCode
!= VFR_RETURN_SUCCESS
) {
860 gCVfrErrorHandle
.HandleError (ReturnCode
, pNode
->mLineNo
, pNode
->mKey
);
865 printf ("Undefined Question name is %s and Id is 0x%x\n", VarStr
, QId
);
868 // Get Question Info, framework vfr VarName == StructName
870 ReturnCode
= lCVfrVarDataTypeDB
.ExtractFieldNameAndArrary (VarStr
, FName
, ArrayIdx
);
871 if (ReturnCode
!= VFR_RETURN_SUCCESS
) {
872 gCVfrErrorHandle
.PrintMsg (pNode
->mLineNo
, pNode
->mKey
, "Error", "Var string is not the valid C variable");
878 ReturnCode
= lCVfrDataStorage
.GetVarStoreId (FName
, &Info
.mVarStoreId
);
879 if (ReturnCode
!= VFR_RETURN_SUCCESS
) {
880 gCVfrErrorHandle
.PrintMsg (pNode
->mLineNo
, FName
, "Error", "Var Store Type is not defined");
883 VarStoreType
= lCVfrDataStorage
.GetVarStoreType (Info
.mVarStoreId
);
885 if (*VarStr
== '\0' && ArrayIdx
!= INVALID_ARRAY_INDEX
) {
886 ReturnCode
= lCVfrDataStorage
.GetNameVarStoreInfo (&Info
, ArrayIdx
);
888 if (VarStoreType
== EFI_VFR_VARSTORE_EFI
) {
889 ReturnCode
= lCVfrDataStorage
.GetEfiVarStoreInfo (&Info
);
890 } else if (VarStoreType
== EFI_VFR_VARSTORE_BUFFER
) {
891 VarStr
= pNode
->mKey
;
892 //convert VarStr with store name to VarStr with structure name
893 ReturnCode
= lCVfrDataStorage
.GetBufferVarStoreDataTypeName (Info
.mVarStoreId
, &SName
);
894 if (ReturnCode
== VFR_RETURN_SUCCESS
) {
895 NewStr
= new CHAR8
[strlen (VarStr
) + strlen (SName
) + 1];
897 strcpy (NewStr
, SName
);
898 strcat (NewStr
, VarStr
+ strlen (FName
));
899 ReturnCode
= lCVfrVarDataTypeDB
.GetDataFieldInfo (NewStr
, Info
.mInfo
.mVarOffset
, Info
.mVarType
, Info
.mVarTotalSize
);
903 ReturnCode
= VFR_RETURN_UNSUPPORTED
;
906 if (ReturnCode
!= VFR_RETURN_SUCCESS
) {
907 gCVfrErrorHandle
.HandleError (ReturnCode
, pNode
->mLineNo
, pNode
->mKey
);
911 CNObj
.SetQuestionId (QId
);
912 CNObj
.SetVarStoreInfo (&Info
);
914 // Numeric doesn't support BOOLEAN data type.
915 // BOOLEAN type has the same data size to UINT8.
917 if (Info
.mVarType
== EFI_IFR_TYPE_BOOLEAN
) {
918 Info
.mVarType
= EFI_IFR_TYPE_NUM_SIZE_8
;
920 CNObj
.SetFlags (0, Info
.mVarType
);
922 // Use maximum value not to limit the vaild value for the undefined question.
924 switch (Info
.mVarType
) {
925 case EFI_IFR_TYPE_NUM_SIZE_64
:
926 CNObj
.SetMinMaxStepData ((UINT64
) 0, (UINT64
) -1 , (UINT64
) 0);
929 case EFI_IFR_TYPE_NUM_SIZE_32
:
930 CNObj
.SetMinMaxStepData ((UINT32
) 0, (UINT32
) -1 , (UINT32
) 0);
933 case EFI_IFR_TYPE_NUM_SIZE_16
:
934 CNObj
.SetMinMaxStepData ((UINT16
) 0, (UINT16
) -1 , (UINT16
) 0);
937 case EFI_IFR_TYPE_NUM_SIZE_8
:
938 CNObj
.SetMinMaxStepData ((UINT8
) 0, (UINT8
) -1 , (UINT8
) 0);
944 CNObj
.ShrinkBinSize (ShrinkSize
);
947 // For undefined Efi VarStore type question
948 // Append the extended guided opcode to contain VarName
950 if (VarStoreType
== EFI_VFR_VARSTORE_EFI
|| VfrCompatibleMode
) {
951 CIfrVarEqName
CVNObj (QId
, Info
.mInfo
.mVarName
);
952 CVNObj
.SetLineNo (LineNo
);
959 CEObj
.SetLineNo (LineNo
);
967 SEObj
.SetLineNo (LineNo
);
969 return VFR_RETURN_SUCCESS
;
974 SIfrRecord::SIfrRecord (
980 mLineNo
= 0xFFFFFFFF;
981 mOffset
= 0xFFFFFFFF;
985 SIfrRecord::~SIfrRecord (
989 if (mIfrBinBuf
!= NULL
) {
993 mLineNo
= 0xFFFFFFFF;
994 mOffset
= 0xFFFFFFFF;
999 CIfrRecordInfoDB::CIfrRecordInfoDB (
1004 mRecordCount
= EFI_IFR_RECORDINFO_IDX_START
;
1005 mIfrRecordListHead
= NULL
;
1006 mIfrRecordListTail
= NULL
;
1007 mAllDefaultTypeCount
= 0;
1008 for (UINT8 i
= 0; i
< EFI_HII_MAX_SUPPORT_DEFAULT_TYPE
; i
++) {
1009 mAllDefaultIdArray
[i
] = 0xffff;
1013 CIfrRecordInfoDB::~CIfrRecordInfoDB (
1019 while (mIfrRecordListHead
!= NULL
) {
1020 pNode
= mIfrRecordListHead
;
1021 mIfrRecordListHead
= mIfrRecordListHead
->mNext
;
1027 CIfrRecordInfoDB::GetRecordInfoFromIdx (
1032 SIfrRecord
*pNode
= NULL
;
1034 if (RecordIdx
== EFI_IFR_RECORDINFO_IDX_INVALUD
) {
1038 for (Idx
= (EFI_IFR_RECORDINFO_IDX_START
+ 1), pNode
= mIfrRecordListHead
;
1039 (Idx
!= RecordIdx
) && (pNode
!= NULL
);
1040 Idx
++, pNode
= pNode
->mNext
)
1047 CIfrRecordInfoDB::IfrRecordRegister (
1049 IN CHAR8
*IfrBinBuf
,
1056 if (mSwitch
== FALSE
) {
1057 return EFI_IFR_RECORDINFO_IDX_INVALUD
;
1060 if ((pNew
= new SIfrRecord
) == NULL
) {
1061 return EFI_IFR_RECORDINFO_IDX_INVALUD
;
1064 if (mIfrRecordListHead
== NULL
) {
1065 mIfrRecordListHead
= pNew
;
1066 mIfrRecordListTail
= pNew
;
1068 mIfrRecordListTail
->mNext
= pNew
;
1069 mIfrRecordListTail
= pNew
;
1073 return mRecordCount
;
1077 CIfrRecordInfoDB::IfrRecordInfoUpdate (
1078 IN UINT32 RecordIdx
,
1088 if ((pNode
= GetRecordInfoFromIdx (RecordIdx
)) == NULL
) {
1094 // Line number is not specified explicitly, try to use line number of previous opcode
1096 Prev
= GetRecordInfoFromIdx (RecordIdx
- 1);
1098 LineNo
= Prev
->mLineNo
;
1102 pNode
->mLineNo
= LineNo
;
1103 pNode
->mOffset
= Offset
;
1104 pNode
->mBinBufLen
= BinBufLen
;
1105 pNode
->mIfrBinBuf
= BinBuf
;
1110 CIfrRecordInfoDB::IfrRecordOutput (
1111 OUT PACKAGE_DATA
&TBuffer
1117 if (TBuffer
.Buffer
!= NULL
) {
1118 delete TBuffer
.Buffer
;
1122 TBuffer
.Buffer
= NULL
;
1125 if (mSwitch
== FALSE
) {
1129 for (pNode
= mIfrRecordListHead
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
1130 TBuffer
.Size
+= pNode
->mBinBufLen
;
1133 if (TBuffer
.Size
!= 0) {
1134 TBuffer
.Buffer
= new CHAR8
[TBuffer
.Size
];
1139 Temp
= TBuffer
.Buffer
;
1141 for (pNode
= mIfrRecordListHead
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
1142 if (pNode
->mIfrBinBuf
!= NULL
) {
1143 memcpy (Temp
, pNode
->mIfrBinBuf
, pNode
->mBinBufLen
);
1144 Temp
+= pNode
->mBinBufLen
;
1152 CIfrRecordInfoDB::IfrRecordOutput (
1161 if (mSwitch
== FALSE
) {
1171 for (pNode
= mIfrRecordListHead
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
1172 if (pNode
->mLineNo
== LineNo
|| LineNo
== 0) {
1173 fprintf (File
, ">%08X: ", pNode
->mOffset
);
1174 TotalSize
+= pNode
->mBinBufLen
;
1175 if (pNode
->mIfrBinBuf
!= NULL
) {
1176 for (Index
= 0; Index
< pNode
->mBinBufLen
; Index
++) {
1177 fprintf (File
, "%02X ", (UINT8
)(pNode
->mIfrBinBuf
[Index
]));
1180 fprintf (File
, "\n");
1185 fprintf (File
, "\nTotal Size of all record is 0x%08X\n", TotalSize
);
1190 // for framework vfr file
1191 // adjust opcode sequence for uefi IFR format
1192 // adjust inconsistent and varstore into the right position.
1195 CIfrRecordInfoDB::CheckQuestionOpCode (
1200 case EFI_IFR_CHECKBOX_OP
:
1201 case EFI_IFR_NUMERIC_OP
:
1202 case EFI_IFR_PASSWORD_OP
:
1203 case EFI_IFR_ONE_OF_OP
:
1204 case EFI_IFR_ACTION_OP
:
1205 case EFI_IFR_STRING_OP
:
1206 case EFI_IFR_DATE_OP
:
1207 case EFI_IFR_TIME_OP
:
1208 case EFI_IFR_ORDERED_LIST_OP
:
1209 case EFI_IFR_REF_OP
:
1217 CIfrRecordInfoDB::CheckIdOpCode (
1222 case EFI_IFR_EQ_ID_VAL_OP
:
1223 case EFI_IFR_EQ_ID_ID_OP
:
1224 case EFI_IFR_EQ_ID_VAL_LIST_OP
:
1225 case EFI_IFR_QUESTION_REF1_OP
:
1233 CIfrRecordInfoDB::GetOpcodeQuestionId (
1234 IN EFI_IFR_OP_HEADER
*OpHead
1237 EFI_IFR_QUESTION_HEADER
*QuestionHead
;
1239 QuestionHead
= (EFI_IFR_QUESTION_HEADER
*) (OpHead
+ 1);
1241 return QuestionHead
->QuestionId
;
1245 CIfrRecordInfoDB::GetRecordInfoFromOffset (
1249 SIfrRecord
*pNode
= NULL
;
1251 for (pNode
= mIfrRecordListHead
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
1252 if (pNode
->mOffset
== Offset
) {
1261 Add just the op code position.
1263 Case1 (CreateOpcodeAfterParsingVfr == FALSE): The dynamic opcodes were created before the formset opcode,
1264 so pDynamicOpcodeNodes is before mIfrRecordListTail.
1268 |mIfrRecordListHead + ...+ pAdjustNode + pDynamicOpcodeNodes + mIfrRecordListTail|
1272 |mIfrRecordListHead + ...+ pDynamicOpcodeNodes + pAdjustNode + mIfrRecordListTail|
1274 Case2 (CreateOpcodeAfterParsingVfr == TRUE): The dynamic opcodes were created after paring the vfr file,
1275 so new records are appennded to the end of OriginalIfrRecordListTail.
1279 |mIfrRecordListHead + ...+ pAdjustNode + ... + OriginalIfrRecordListTail + pDynamicOpcodeNodes|
1283 |mIfrRecordListHead + ...+ pDynamicOpcodeNodes + pAdjustNode + ... + OriginalIfrRecordListTail|
1286 @param CreateOpcodeAfterParsingVfr Whether create the dynamic opcode after parsing the VFR file.
1290 CIfrRecordInfoDB::IfrAdjustDynamicOpcodeInRecords (
1291 IN BOOLEAN CreateOpcodeAfterParsingVfr
1294 UINT32 OpcodeOffset
;
1295 SIfrRecord
*pNode
, *pPreNode
;
1296 SIfrRecord
*pAdjustNode
, *pNodeBeforeAdjust
;
1297 SIfrRecord
*pNodeBeforeDynamic
;
1301 pNodeBeforeDynamic
= NULL
;
1305 // Base on the gAdjustOpcodeOffset and gAdjustOpcodeLen to find the pAdjustNod, the node before pAdjustNode,
1306 // and the node before pDynamicOpcodeNode.
1308 for (pNode
= mIfrRecordListHead
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
1309 if (OpcodeOffset
== gAdjustOpcodeOffset
) {
1310 pAdjustNode
= pNode
;
1311 pNodeBeforeAdjust
= pPreNode
;
1312 } else if (OpcodeOffset
== gAdjustOpcodeOffset
+ gAdjustOpcodeLen
) {
1313 pNodeBeforeDynamic
= pPreNode
;
1315 if (pNode
->mNext
!= NULL
) {
1318 OpcodeOffset
+= pNode
->mBinBufLen
;
1322 // Check the nodes whether exist.
1324 if (pNodeBeforeDynamic
== NULL
|| pAdjustNode
== NULL
|| pNodeBeforeAdjust
== NULL
) {
1329 // Adjust the node. pPreNode save the Node before mIfrRecordListTail
1331 pNodeBeforeAdjust
->mNext
= pNodeBeforeDynamic
->mNext
;
1332 if (CreateOpcodeAfterParsingVfr
) {
1334 // mIfrRecordListTail is the end of pDynamicNode (Case2).
1336 mIfrRecordListTail
->mNext
= pAdjustNode
;
1337 mIfrRecordListTail
= pNodeBeforeDynamic
;
1338 mIfrRecordListTail
->mNext
= NULL
;
1341 //pPreNode is the end of pDynamicNode(Case1).
1343 pPreNode
->mNext
= pAdjustNode
;
1344 pNodeBeforeDynamic
->mNext
= mIfrRecordListTail
;
1351 Update the record info(the position in the record list, offset and mIfrBinBuf) for new created record.
1353 @param CreateOpcodeAfterParsingVfr Whether create the dynamic opcode after parsing the VFR file.
1357 CIfrRecordInfoDB::IfrUpdateRecordInfoForDynamicOpcode (
1358 IN BOOLEAN CreateOpcodeAfterParsingVfr
1361 SIfrRecord
*pRecord
;
1364 // Base on the original offset info to update the record list.
1366 if (!IfrAdjustDynamicOpcodeInRecords(CreateOpcodeAfterParsingVfr
)) {
1367 gCVfrErrorHandle
.PrintMsg (0, "Error", "Can not find the adjust offset in the record.");
1371 // Base on the opcode binary length to recalculate the offset for each opcode.
1373 IfrAdjustOffsetForRecord();
1376 // Base on the offset to find the binary address.
1378 pRecord
= GetRecordInfoFromOffset(gAdjustOpcodeOffset
);
1379 while (pRecord
!= NULL
) {
1380 pRecord
->mIfrBinBuf
= gCFormPkg
.GetBufAddrBaseOnOffset(pRecord
->mOffset
);
1381 pRecord
= pRecord
->mNext
;
1387 CIfrRecordInfoDB::IfrAdjustOffsetForRecord (
1391 UINT32 OpcodeOffset
;
1395 for (pNode
= mIfrRecordListHead
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
1396 pNode
->mOffset
= OpcodeOffset
;
1397 OpcodeOffset
+= pNode
->mBinBufLen
;
1402 CIfrRecordInfoDB::IfrRecordAdjust (
1406 SIfrRecord
*pNode
, *preNode
;
1407 SIfrRecord
*uNode
, *tNode
;
1408 EFI_IFR_OP_HEADER
*OpHead
, *tOpHead
;
1409 EFI_QUESTION_ID QuestionId
;
1411 UINT32 QuestionScope
;
1412 CHAR8 ErrorMsg
[MAX_STRING_LEN
] = {0, };
1413 EFI_VFR_RETURN_CODE Status
;
1416 // Init local variable
1418 Status
= VFR_RETURN_SUCCESS
;
1419 pNode
= mIfrRecordListHead
;
1422 while (pNode
!= NULL
) {
1423 OpHead
= (EFI_IFR_OP_HEADER
*) pNode
->mIfrBinBuf
;
1426 // make sure the inconsistent opcode in question scope
1428 if (QuestionScope
> 0) {
1429 QuestionScope
+= OpHead
->Scope
;
1430 if (OpHead
->OpCode
== EFI_IFR_END_OP
) {
1435 if (CheckQuestionOpCode (OpHead
->OpCode
)) {
1439 // for the inconsistent opcode not in question scope, adjust it
1441 if (OpHead
->OpCode
== EFI_IFR_INCONSISTENT_IF_OP
&& QuestionScope
== 0) {
1443 // for inconsistent opcode not in question scope
1447 // Count inconsistent opcode Scope
1449 StackCount
= OpHead
->Scope
;
1450 QuestionId
= EFI_QUESTION_ID_INVALID
;
1452 while (tNode
!= NULL
&& StackCount
> 0) {
1453 tNode
= tNode
->mNext
;
1454 tOpHead
= (EFI_IFR_OP_HEADER
*) tNode
->mIfrBinBuf
;
1456 // Calculate Scope Number
1458 StackCount
+= tOpHead
->Scope
;
1459 if (tOpHead
->OpCode
== EFI_IFR_END_OP
) {
1463 // by IdEqual opcode to get QuestionId
1465 if (QuestionId
== EFI_QUESTION_ID_INVALID
&&
1466 CheckIdOpCode (tOpHead
->OpCode
)) {
1467 QuestionId
= *(EFI_QUESTION_ID
*) (tOpHead
+ 1);
1470 if (tNode
== NULL
|| QuestionId
== EFI_QUESTION_ID_INVALID
) {
1472 // report error; not found
1474 sprintf (ErrorMsg
, "Inconsistent OpCode Record list invalid QuestionId is 0x%X", QuestionId
);
1475 gCVfrErrorHandle
.PrintMsg (0, NULL
, "Error", ErrorMsg
);
1476 Status
= VFR_RETURN_MISMATCHED
;
1480 // extract inconsistent opcode list
1481 // pNode is Incosistent opcode, tNode is End Opcode
1485 // insert inconsistent opcode list into the right question scope by questionid
1487 for (uNode
= mIfrRecordListHead
; uNode
!= NULL
; uNode
= uNode
->mNext
) {
1488 tOpHead
= (EFI_IFR_OP_HEADER
*) uNode
->mIfrBinBuf
;
1489 if (CheckQuestionOpCode (tOpHead
->OpCode
) &&
1490 (QuestionId
== GetOpcodeQuestionId (tOpHead
))) {
1495 // insert inconsistent opcode list and check LATE_CHECK flag
1497 if (uNode
!= NULL
) {
1498 if ((((EFI_IFR_QUESTION_HEADER
*)(tOpHead
+ 1))->Flags
& 0x20) != 0) {
1500 // if LATE_CHECK flag is set, change inconsistent to nosumbit
1502 OpHead
->OpCode
= EFI_IFR_NO_SUBMIT_IF_OP
;
1506 // skip the default storage for Date and Time
1508 if ((uNode
->mNext
!= NULL
) && (*uNode
->mNext
->mIfrBinBuf
== EFI_IFR_DEFAULT_OP
)) {
1509 uNode
= uNode
->mNext
;
1512 preNode
->mNext
= tNode
->mNext
;
1513 tNode
->mNext
= uNode
->mNext
;
1514 uNode
->mNext
= pNode
;
1516 // reset pNode to head list, scan the whole list again.
1518 pNode
= mIfrRecordListHead
;
1524 // not found matched question id, report error
1526 sprintf (ErrorMsg
, "QuestionId required by Inconsistent OpCode is not found. QuestionId is 0x%X", QuestionId
);
1527 gCVfrErrorHandle
.PrintMsg (0, NULL
, "Error", ErrorMsg
);
1528 Status
= VFR_RETURN_MISMATCHED
;
1531 } else if (OpHead
->OpCode
== EFI_IFR_VARSTORE_OP
||
1532 OpHead
->OpCode
== EFI_IFR_VARSTORE_EFI_OP
) {
1534 // for new added group of varstore opcode
1537 while (tNode
->mNext
!= NULL
) {
1538 tOpHead
= (EFI_IFR_OP_HEADER
*) tNode
->mNext
->mIfrBinBuf
;
1539 if (tOpHead
->OpCode
!= EFI_IFR_VARSTORE_OP
&&
1540 tOpHead
->OpCode
!= EFI_IFR_VARSTORE_EFI_OP
) {
1543 tNode
= tNode
->mNext
;
1546 if (tNode
->mNext
== NULL
) {
1548 // invalid IfrCode, IfrCode end by EndOpCode
1550 gCVfrErrorHandle
.PrintMsg (0, NULL
, "Error", "No found End Opcode in the end");
1551 Status
= VFR_RETURN_MISMATCHED
;
1555 if (tOpHead
->OpCode
!= EFI_IFR_END_OP
) {
1557 // not new added varstore, which are not needed to be adjust.
1560 pNode
= tNode
->mNext
;
1564 // move new added varstore opcode to the position befor form opcode
1565 // varstore opcode between pNode and tNode
1569 // search form opcode from begin
1571 for (uNode
= mIfrRecordListHead
; uNode
->mNext
!= NULL
; uNode
= uNode
->mNext
) {
1572 tOpHead
= (EFI_IFR_OP_HEADER
*) uNode
->mNext
->mIfrBinBuf
;
1573 if (tOpHead
->OpCode
== EFI_IFR_FORM_OP
) {
1578 // Insert varstore opcode beform form opcode if form opcode is found
1580 if (uNode
->mNext
!= NULL
) {
1581 preNode
->mNext
= tNode
->mNext
;
1582 tNode
->mNext
= uNode
->mNext
;
1583 uNode
->mNext
= pNode
;
1585 // reset pNode to head list, scan the whole list again.
1587 pNode
= mIfrRecordListHead
;
1593 // not found form, continue scan IfrRecord list
1596 pNode
= tNode
->mNext
;
1605 pNode
= pNode
->mNext
;
1609 // Update Ifr Opcode Offset
1611 if (Status
== VFR_RETURN_SUCCESS
) {
1612 IfrAdjustOffsetForRecord ();
1618 When the Varstore of the question is EFI_VFR_VARSTORE_BUFFER and the default value is not
1619 given by expression, should save the default info for the Buffer VarStore.
1621 @param DefaultId The default id.
1622 @param pQuestionNode Point to the question opcode node.
1623 @param Value The default value.
1626 CIfrRecordInfoDB::IfrAddDefaultToBufferConfig (
1627 IN UINT16 DefaultId
,
1628 IN SIfrRecord
*pQuestionNode
,
1629 IN EFI_IFR_TYPE_VALUE Value
1632 CHAR8
*VarStoreName
= NULL
;
1633 EFI_VFR_VARSTORE_TYPE VarStoreType
= EFI_VFR_VARSTORE_INVALID
;
1634 EFI_GUID
*VarGuid
= NULL
;
1635 EFI_VARSTORE_INFO VarInfo
;
1636 EFI_IFR_QUESTION_HEADER
*QuestionHead
;
1637 EFI_IFR_OP_HEADER
*pQuestionOpHead
;
1639 pQuestionOpHead
= (EFI_IFR_OP_HEADER
*) pQuestionNode
->mIfrBinBuf
;
1640 QuestionHead
= (EFI_IFR_QUESTION_HEADER
*) (pQuestionOpHead
+ 1);
1643 // Get the Var Store name and type.
1645 gCVfrDataStorage
.GetVarStoreName (QuestionHead
->VarStoreId
, &VarStoreName
);
1646 VarGuid
= gCVfrDataStorage
.GetVarStoreGuid (QuestionHead
->VarStoreId
);
1647 VarStoreType
= gCVfrDataStorage
.GetVarStoreType (QuestionHead
->VarStoreId
);
1650 // Only for Buffer storage need to save the default info in the storage.
1651 // Other type storage, just return.
1653 if (VarStoreType
!= EFI_VFR_VARSTORE_BUFFER
) {
1656 VarInfo
.mInfo
.mVarOffset
= QuestionHead
->VarStoreInfo
.VarOffset
;
1657 VarInfo
.mVarStoreId
= QuestionHead
->VarStoreId
;
1661 // Get the buffer storage info about this question.
1663 gCVfrDataStorage
.GetBufferVarStoreFieldInfo (&VarInfo
);
1668 gCVfrDefaultStore
.BufferVarStoreAltConfigAdd (
1679 Record the number and default id of all defaultstore opcode.
1683 CIfrRecordInfoDB::IfrGetDefaultStoreInfo (
1688 EFI_IFR_OP_HEADER
*pOpHead
;
1689 EFI_IFR_DEFAULTSTORE
*DefaultStore
;
1691 pNode
= mIfrRecordListHead
;
1692 mAllDefaultTypeCount
= 0;
1694 while (pNode
!= NULL
) {
1695 pOpHead
= (EFI_IFR_OP_HEADER
*) pNode
->mIfrBinBuf
;
1697 if (pOpHead
->OpCode
== EFI_IFR_DEFAULTSTORE_OP
){
1698 DefaultStore
= (EFI_IFR_DEFAULTSTORE
*) pNode
->mIfrBinBuf
;
1699 mAllDefaultIdArray
[mAllDefaultTypeCount
++] = DefaultStore
->DefaultId
;
1701 pNode
= pNode
->mNext
;
1706 Create new default opcode record.
1708 @param Size The new default opcode size.
1709 @param DefaultId The new default id.
1710 @param Type The new default type.
1711 @param LineNo The line number of the new record.
1712 @param Value The new default value.
1716 CIfrRecordInfoDB::IfrCreateDefaultRecord(
1718 IN UINT16 DefaultId
,
1721 IN EFI_IFR_TYPE_VALUE Value
1725 CIfrDefault2
*DObj2
;
1730 if (Type
== EFI_IFR_TYPE_OTHER
) {
1731 DObj2
= new CIfrDefault2 (Size
);
1732 DObj2
->SetDefaultId(DefaultId
);
1733 DObj2
->SetType(Type
);
1734 DObj2
->SetLineNo(LineNo
);
1735 DObj2
->SetScope (1);
1738 DObj
= new CIfrDefault (Size
);
1739 DObj
->SetDefaultId(DefaultId
);
1740 DObj
->SetType(Type
);
1741 DObj
->SetLineNo(LineNo
);
1742 DObj
->SetValue (Value
);
1748 Create new default opcode for question base on the QuestionDefaultInfo.
1750 @param pQuestionNode Point to the question opcode Node.
1751 @param QuestionDefaultInfo Point to the QuestionDefaultInfo for current question.
1755 CIfrRecordInfoDB::IfrCreateDefaultForQuestion (
1756 IN SIfrRecord
*pQuestionNode
,
1757 IN QuestionDefaultRecord
*QuestionDefaultInfo
1760 EFI_IFR_OP_HEADER
*pOpHead
;
1761 EFI_IFR_DEFAULT
*Default
;
1764 SIfrRecord
*pDefaultNode
;
1771 EFI_IFR_ONE_OF_OPTION
*DefaultOptionOpcode
;
1772 EFI_IFR_TYPE_VALUE CheckBoxDefaultValue
;
1774 CheckBoxDefaultValue
.b
= 1;
1775 pOpHead
= (EFI_IFR_OP_HEADER
*) pQuestionNode
->mIfrBinBuf
;
1781 // Record the offset of node which need to be adjust, will move the new created default opcode to this offset.
1783 gAdjustOpcodeOffset
= pQuestionNode
->mNext
->mOffset
;
1786 // For oneof, the default with smallest default id is given by the option flag.
1787 // So create the missing defaults base on the oneof option value(mDefaultValueRecord).
1789 if (pOpHead
->OpCode
== EFI_IFR_ONE_OF_OP
&& !QuestionDefaultInfo
->mIsDefaultOpcode
) {
1790 DefaultOptionOpcode
= (EFI_IFR_ONE_OF_OPTION
*)QuestionDefaultInfo
->mDefaultValueRecord
->mIfrBinBuf
;
1791 DefaultSize
= QuestionDefaultInfo
->mDefaultValueRecord
->mBinBufLen
- OFFSET_OF (EFI_IFR_ONE_OF_OPTION
, Value
);
1792 DefaultSize
+= OFFSET_OF (EFI_IFR_DEFAULT
, Value
);
1793 for (UINT8 i
= 0; i
< mAllDefaultTypeCount
; i
++) {
1794 if (!QuestionDefaultInfo
->mIsDefaultIdExist
[i
]) {
1795 IfrCreateDefaultRecord (DefaultSize
, mAllDefaultIdArray
[i
], DefaultOptionOpcode
->Type
, pQuestionNode
->mLineNo
, DefaultOptionOpcode
->Value
);
1797 // Save the new created default in the buffer storage.
1799 IfrAddDefaultToBufferConfig (mAllDefaultIdArray
[i
], pQuestionNode
, DefaultOptionOpcode
->Value
);
1807 // For checkbox, the default with smallest default id is given by the question flag.
1808 // And create the missing defaults with true value.
1810 if (pOpHead
-> OpCode
== EFI_IFR_CHECKBOX_OP
&& !QuestionDefaultInfo
->mIsDefaultOpcode
) {
1811 DefaultSize
= OFFSET_OF (EFI_IFR_DEFAULT
, Value
) + sizeof (BOOLEAN
);
1812 for (UINT8 i
= 0; i
< mAllDefaultTypeCount
; i
++) {
1813 if (!QuestionDefaultInfo
->mIsDefaultIdExist
[i
]) {
1814 IfrCreateDefaultRecord (DefaultSize
, mAllDefaultIdArray
[i
], EFI_IFR_TYPE_BOOLEAN
, pQuestionNode
->mLineNo
, CheckBoxDefaultValue
);
1816 // Save the new created default.
1818 IfrAddDefaultToBufferConfig (mAllDefaultIdArray
[i
], pQuestionNode
, CheckBoxDefaultValue
);
1826 // The default with smallest default id is given by the default opcode.
1827 // So create the missing defaults base on the value in the default opcode.
1831 // pDefaultNode point to the mDefaultValueRecord in QuestionDefaultInfo.
1833 pDefaultNode
= QuestionDefaultInfo
->mDefaultValueRecord
;
1834 Default
= (EFI_IFR_DEFAULT
*)pDefaultNode
->mIfrBinBuf
;
1836 // Record the offset of node which need to be adjust, will move the new created default opcode to this offset.
1838 gAdjustOpcodeOffset
= pDefaultNode
->mNext
->mOffset
;
1840 if (Default
->Type
== EFI_IFR_TYPE_OTHER
) {
1842 // EFI_IFR_DEFAULT_2 opcode.
1844 // Point to the first expression opcode.
1846 pSNode
= pDefaultNode
->mNext
;
1850 // Get opcode number behind the EFI_IFR_DEFAULT_2 until reach its END opcode (including the END opcode of EFI_IFR_DEFAULT_2)
1852 while (pSNode
!= NULL
&& pSNode
->mNext
!= NULL
&& ScopeCount
!= 0) {
1853 pOpHead
= (EFI_IFR_OP_HEADER
*) pSNode
->mIfrBinBuf
;
1854 if (pOpHead
->Scope
== 1) {
1857 if (pOpHead
->OpCode
== EFI_IFR_END_OP
) {
1861 pSNode
= pSNode
->mNext
;
1869 // Record the offset of node which need to be adjust, will move the new created default opcode to this offset.
1871 gAdjustOpcodeOffset
= pSNode
->mOffset
;
1873 // Create new default opcode node for missing default.
1875 for (UINT8 i
= 0; i
< mAllDefaultTypeCount
; i
++) {
1876 OpcodeNumber
= OpcodeCount
;
1877 if (!QuestionDefaultInfo
->mIsDefaultIdExist
[i
]) {
1878 IfrCreateDefaultRecord (Default
->Header
.Length
, mAllDefaultIdArray
[i
], Default
->Type
, pENode
->mLineNo
, Default
->Value
);
1880 // Point to the first expression opcode node.
1882 pSNode
= pDefaultNode
->mNext
;
1884 // Create the expression opcode and end opcode for the new created EFI_IFR_DEFAULT_2 opcode.
1886 while (pSNode
!= NULL
&& pSNode
->mNext
!= NULL
&& OpcodeNumber
-- != 0) {
1887 pOpHead
= (EFI_IFR_OP_HEADER
*) pSNode
->mIfrBinBuf
;
1888 Obj
= new CIfrObj (pOpHead
->OpCode
, NULL
, pSNode
->mBinBufLen
, FALSE
);
1889 assert (Obj
!= NULL
);
1890 Obj
->SetLineNo (pSNode
->mLineNo
);
1891 ObjBinBuf
= Obj
->GetObjBinAddr();
1892 memcpy (ObjBinBuf
, pSNode
->mIfrBinBuf
, (UINTN
)pSNode
->mBinBufLen
);
1894 pSNode
= pSNode
->mNext
;
1900 // EFI_IFR_DEFAULT opcode.
1902 // Create new default opcode node for missing default.
1904 for (UINT8 i
= 0; i
< mAllDefaultTypeCount
; i
++) {
1905 if (!QuestionDefaultInfo
->mIsDefaultIdExist
[i
]) {
1906 IfrCreateDefaultRecord (Default
->Header
.Length
, mAllDefaultIdArray
[i
], Default
->Type
, pDefaultNode
->mLineNo
, Default
->Value
);
1908 // Save the new created default in the buffer storage..
1910 IfrAddDefaultToBufferConfig (mAllDefaultIdArray
[i
], pQuestionNode
, Default
->Value
);
1917 Parse the default information in a question, get the QuestionDefaultInfo.
1919 @param pQuestionNode Point to the question record Node.
1920 @param QuestionDefaultInfo On return, point to the QuestionDefaultInfo.
1923 CIfrRecordInfoDB::IfrParseDefaulInfoInQuestion(
1924 IN SIfrRecord
*pQuestionNode
,
1925 OUT QuestionDefaultRecord
*QuestionDefaultInfo
1929 EFI_IFR_ONE_OF_OPTION
*OneofOptionOpcode
;
1930 EFI_IFR_OP_HEADER
*pSOpHead
;
1931 EFI_IFR_CHECKBOX
*CheckBoxOpcode
;
1932 EFI_IFR_DEFAULT
*DefaultOpcode
;
1933 BOOLEAN IsOneOfOpcode
;
1934 UINT16 SmallestDefaultId
;
1937 SmallestDefaultId
= 0xffff;
1938 IsOneOfOpcode
= FALSE
;
1940 pSNode
= pQuestionNode
;
1943 // Parse all the opcodes in the Question.
1945 while (pSNode
!= NULL
) {
1946 pSOpHead
= (EFI_IFR_OP_HEADER
*) pSNode
->mIfrBinBuf
;
1948 // For a question, its scope bit must be set, the scope exists until it reaches a corresponding EFI_IFR_END_OP.
1949 // Scopes may be nested within other scopes.
1950 // When finishing parsing a question, the scope count must be zero.
1952 if (pSOpHead
->Scope
== 1) {
1955 if (pSOpHead
->OpCode
== EFI_IFR_END_OP
) {
1959 // Check whether finishing parsing a question.
1961 if (ScopeCount
== 0) {
1966 // Record the default information in the question.
1968 switch (pSOpHead
->OpCode
) {
1969 case EFI_IFR_ONE_OF_OP
:
1970 IsOneOfOpcode
= TRUE
;
1972 case EFI_IFR_CHECKBOX_OP
:
1974 // The default info of check box may be given by flag.
1975 // So need to check the flag of check box.
1977 CheckBoxOpcode
= (EFI_IFR_CHECKBOX
*)pSNode
->mIfrBinBuf
;
1978 if ((CheckBoxOpcode
->Flags
& EFI_IFR_CHECKBOX_DEFAULT
) != 0) {
1980 // Check whether need to update the smallest default id.
1982 if (SmallestDefaultId
> EFI_HII_DEFAULT_CLASS_STANDARD
) {
1983 SmallestDefaultId
= EFI_HII_DEFAULT_CLASS_STANDARD
;
1986 // Update the QuestionDefaultInfo.
1988 for (UINT8 i
= 0; i
< mAllDefaultTypeCount
; i
++) {
1989 if (mAllDefaultIdArray
[i
] == EFI_HII_DEFAULT_CLASS_STANDARD
) {
1990 if (!QuestionDefaultInfo
->mIsDefaultIdExist
[i
]) {
1991 QuestionDefaultInfo
->mDefaultNumber
++;
1992 QuestionDefaultInfo
->mIsDefaultIdExist
[i
] = TRUE
;
1998 if ((CheckBoxOpcode
->Flags
& EFI_IFR_CHECKBOX_DEFAULT_MFG
) != 0) {
2000 // Check whether need to update the smallest default id.
2002 if (SmallestDefaultId
> EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
2003 SmallestDefaultId
= EFI_HII_DEFAULT_CLASS_MANUFACTURING
;
2006 // Update the QuestionDefaultInfo.
2008 for (UINT8 i
= 0; i
< mAllDefaultTypeCount
; i
++) {
2009 if (mAllDefaultIdArray
[i
] == EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
2010 if (!QuestionDefaultInfo
->mIsDefaultIdExist
[i
]) {
2011 QuestionDefaultInfo
->mDefaultNumber
++;
2012 QuestionDefaultInfo
->mIsDefaultIdExist
[i
] = TRUE
;
2019 case EFI_IFR_ONE_OF_OPTION_OP
:
2020 if (!IsOneOfOpcode
) {
2022 // Only check the option in oneof.
2026 OneofOptionOpcode
= (EFI_IFR_ONE_OF_OPTION
*)pSNode
->mIfrBinBuf
;
2027 if ((OneofOptionOpcode
->Flags
& EFI_IFR_OPTION_DEFAULT
) != 0) {
2029 // The option is used as the standard default.
2030 // Check whether need to update the smallest default id and QuestionDefaultInfo.
2032 if (SmallestDefaultId
> EFI_HII_DEFAULT_CLASS_STANDARD
) {
2033 SmallestDefaultId
= EFI_HII_DEFAULT_CLASS_STANDARD
;
2034 QuestionDefaultInfo
->mDefaultValueRecord
= pSNode
;
2037 // Update the IsDefaultIdExist array in QuestionDefaultInfo.
2039 for (UINT8 i
= 0; i
< mAllDefaultTypeCount
; i
++) {
2040 if (mAllDefaultIdArray
[i
] == EFI_HII_DEFAULT_CLASS_STANDARD
) {
2041 if (!QuestionDefaultInfo
->mIsDefaultIdExist
[i
]) {
2042 QuestionDefaultInfo
->mDefaultNumber
++;
2043 QuestionDefaultInfo
->mIsDefaultIdExist
[i
] = TRUE
;
2049 if ((OneofOptionOpcode
->Flags
& EFI_IFR_OPTION_DEFAULT_MFG
) != 0) {
2051 // This option is used as the manufacture default.
2052 // Check whether need to update the smallest default id and QuestionDefaultInfo.
2054 if (SmallestDefaultId
> EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
2055 SmallestDefaultId
= EFI_HII_DEFAULT_CLASS_MANUFACTURING
;
2056 QuestionDefaultInfo
->mDefaultValueRecord
= pSNode
;
2059 // Update the QuestionDefaultInfo.
2061 for (UINT8 i
= 0; i
< mAllDefaultTypeCount
; i
++) {
2062 if (mAllDefaultIdArray
[i
] == EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
2063 if (!QuestionDefaultInfo
->mIsDefaultIdExist
[i
]) {
2064 QuestionDefaultInfo
->mDefaultNumber
++;
2065 QuestionDefaultInfo
->mIsDefaultIdExist
[i
] = TRUE
;
2072 case EFI_IFR_DEFAULT_OP
:
2073 DefaultOpcode
= (EFI_IFR_DEFAULT
*) pSNode
->mIfrBinBuf
;
2075 // Check whether need to update the smallest default id and QuestionDefaultInfo.
2077 if (SmallestDefaultId
>= DefaultOpcode
->DefaultId
) {
2078 SmallestDefaultId
= DefaultOpcode
->DefaultId
;
2079 QuestionDefaultInfo
->mDefaultValueRecord
= pSNode
;
2080 QuestionDefaultInfo
->mIsDefaultOpcode
= TRUE
;
2083 // Update the QuestionDefaultInfo.
2085 for (UINT8 i
= 0; i
< mAllDefaultTypeCount
; i
++){
2086 if (mAllDefaultIdArray
[i
] == ((EFI_IFR_DEFAULT
*)pSNode
->mIfrBinBuf
)->DefaultId
) {
2087 if (!QuestionDefaultInfo
->mIsDefaultIdExist
[i
]) {
2088 QuestionDefaultInfo
->mDefaultNumber
++;
2089 QuestionDefaultInfo
->mIsDefaultIdExist
[i
] = TRUE
;
2099 // Parse next opcode in this question.
2101 pSNode
= pSNode
->mNext
;
2106 Check or add default for question if need.
2108 This function will check the default info for question.
2109 If the question has default, but the default number < defaultstore opcode number.
2110 will do following two action :
2112 1. if (AutoDefault) will add default for question to support all kinds of defaults.
2113 2. if (CheckDefault) will generate an error to tell user the question misses some default value.
2115 We assume that the two options can not be TRUE at same time.
2116 If they are TRUE at same time, only do the action corresponding to AutoDefault option.
2118 @param AutoDefault Add default for question if needed
2119 @param CheckDefault Check the default info, if missing default, generates an error.
2123 CIfrRecordInfoDB::IfrCheckAddDefaultRecord (
2124 BOOLEAN AutoDefault
,
2125 BOOLEAN CheckDefault
2129 SIfrRecord
*pTailNode
;
2130 SIfrRecord
*pStartAdjustNode
;
2131 EFI_IFR_OP_HEADER
*pOpHead
;
2132 QuestionDefaultRecord QuestionDefaultInfo
;
2133 UINT8 MissingDefaultCount
;
2134 CHAR8 Msg
[MAX_STRING_LEN
] = {0, };
2136 pNode
= mIfrRecordListHead
;
2139 // Record the number and default id of all defaultstore opcode.
2141 IfrGetDefaultStoreInfo ();
2143 while (pNode
!= NULL
) {
2144 pOpHead
= (EFI_IFR_OP_HEADER
*) pNode
->mIfrBinBuf
;
2146 // Check whether is question opcode.
2148 if (CheckQuestionOpCode (pOpHead
->OpCode
)) {
2150 // Initialize some local variables here, because they vary with question.
2151 // Record the mIfrRecordListTail for each question, because may create default node for question after mIfrRecordListTail.
2153 memset (&QuestionDefaultInfo
, 0, sizeof (QuestionDefaultRecord
));
2154 pTailNode
= mIfrRecordListTail
;
2156 // Get the QuestionDefaultInfo for current question.
2158 IfrParseDefaulInfoInQuestion (pNode
, &QuestionDefaultInfo
);
2160 if (QuestionDefaultInfo
.mDefaultNumber
!= mAllDefaultTypeCount
&& QuestionDefaultInfo
.mDefaultNumber
!= 0) {
2163 // Create default for question which misses default.
2165 IfrCreateDefaultForQuestion (pNode
, &QuestionDefaultInfo
);
2168 // Adjust the buffer content.
2169 // pStartAdjustNode->mIfrBinBuf points to the insert position.
2170 // pTailNode->mNext->mIfrBinBuf points to the inset opcodes.
2172 pStartAdjustNode
=GetRecordInfoFromOffset (gAdjustOpcodeOffset
);
2173 gCFormPkg
.AdjustDynamicInsertOpcode (pStartAdjustNode
->mIfrBinBuf
, pTailNode
->mNext
->mIfrBinBuf
, TRUE
);
2176 // Update the record info.
2178 IfrUpdateRecordInfoForDynamicOpcode (TRUE
);
2179 } else if (CheckDefault
) {
2181 // Generate an error for question which misses default.
2183 MissingDefaultCount
= mAllDefaultTypeCount
- QuestionDefaultInfo
.mDefaultNumber
;
2184 sprintf (Msg
, "The question misses %d default, the question's opcode is %d", MissingDefaultCount
, pOpHead
->OpCode
);
2185 gCVfrErrorHandle
.PrintMsg (pNode
->mLineNo
, NULL
, "Error", Msg
);
2190 // parse next opcode.
2192 pNode
= pNode
->mNext
;
2196 CIfrRecordInfoDB gCIfrRecordInfoDB
;
2199 CIfrObj::_EMIT_PENDING_OBJ (
2203 CHAR8
*ObjBinBuf
= NULL
;
2208 if (!mDelayEmit
|| !gCreateOp
) {
2212 mPkgOffset
= gCFormPkg
.GetPkgLength ();
2214 // update data buffer to package data
2216 ObjBinBuf
= gCFormPkg
.IfrBinBufferGet (mObjBinLen
);
2217 if (ObjBinBuf
!= NULL
) {
2218 memmove (ObjBinBuf
, mObjBinBuf
, mObjBinLen
);
2222 // update bin buffer to package data buffer
2224 if (mObjBinBuf
!= NULL
) {
2226 mObjBinBuf
= ObjBinBuf
;
2233 * The definition of CIfrObj's member function
2238 } gOpcodeSizesScopeTable
[] = {
2239 { 0, 0 }, // EFI_IFR_INVALID - 0x00
2240 { sizeof (EFI_IFR_FORM
), 1 }, // EFI_IFR_FORM_OP
2241 { sizeof (EFI_IFR_SUBTITLE
), 1 }, // EFI_IFR_SUBTITLE_OP
2242 { sizeof (EFI_IFR_TEXT
), 0 }, // EFI_IFR_TEXT_OP
2243 { sizeof (EFI_IFR_IMAGE
), 0 }, // EFI_IFR_IMAGE_OP
2244 { sizeof (EFI_IFR_ONE_OF
), 1 }, // EFI_IFR_ONE_OF_OP - 0x05
2245 { sizeof (EFI_IFR_CHECKBOX
), 1}, // EFI_IFR_CHECKBOX_OP
2246 { sizeof (EFI_IFR_NUMERIC
), 1 }, // EFI_IFR_NUMERIC_OP
2247 { sizeof (EFI_IFR_PASSWORD
), 1 }, // EFI_IFR_PASSWORD_OP
2248 { sizeof (EFI_IFR_ONE_OF_OPTION
), 0 }, // EFI_IFR_ONE_OF_OPTION_OP
2249 { sizeof (EFI_IFR_SUPPRESS_IF
), 1 }, // EFI_IFR_SUPPRESS_IF - 0x0A
2250 { sizeof (EFI_IFR_LOCKED
), 0 }, // EFI_IFR_LOCKED_OP
2251 { sizeof (EFI_IFR_ACTION
), 1 }, // EFI_IFR_ACTION_OP
2252 { sizeof (EFI_IFR_RESET_BUTTON
), 1 }, // EFI_IFR_RESET_BUTTON_OP
2253 { sizeof (EFI_IFR_FORM_SET
), 1 }, // EFI_IFR_FORM_SET_OP -0xE
2254 { sizeof (EFI_IFR_REF
), 0 }, // EFI_IFR_REF_OP
2255 { sizeof (EFI_IFR_NO_SUBMIT_IF
), 1}, // EFI_IFR_NO_SUBMIT_IF_OP -0x10
2256 { sizeof (EFI_IFR_INCONSISTENT_IF
), 1 }, // EFI_IFR_INCONSISTENT_IF_OP
2257 { sizeof (EFI_IFR_EQ_ID_VAL
), 0 }, // EFI_IFR_EQ_ID_VAL_OP
2258 { sizeof (EFI_IFR_EQ_ID_ID
), 0 }, // EFI_IFR_EQ_ID_ID_OP
2259 { sizeof (EFI_IFR_EQ_ID_VAL_LIST
), 0 }, // EFI_IFR_EQ_ID_LIST_OP - 0x14
2260 { sizeof (EFI_IFR_AND
), 0 }, // EFI_IFR_AND_OP
2261 { sizeof (EFI_IFR_OR
), 0 }, // EFI_IFR_OR_OP
2262 { sizeof (EFI_IFR_NOT
), 0 }, // EFI_IFR_NOT_OP
2263 { sizeof (EFI_IFR_RULE
), 1 }, // EFI_IFR_RULE_OP
2264 { sizeof (EFI_IFR_GRAY_OUT_IF
), 1 }, // EFI_IFR_GRAYOUT_IF_OP - 0x19
2265 { sizeof (EFI_IFR_DATE
), 1 }, // EFI_IFR_DATE_OP
2266 { sizeof (EFI_IFR_TIME
), 1 }, // EFI_IFR_TIME_OP
2267 { sizeof (EFI_IFR_STRING
), 1 }, // EFI_IFR_STRING_OP
2268 { sizeof (EFI_IFR_REFRESH
), 0 }, // EFI_IFR_REFRESH_OP
2269 { sizeof (EFI_IFR_DISABLE_IF
), 1 }, // EFI_IFR_DISABLE_IF_OP - 0x1E
2271 { sizeof (EFI_IFR_TO_LOWER
), 0 }, // EFI_IFR_TO_LOWER_OP - 0x20
2272 { sizeof (EFI_IFR_TO_UPPER
), 0 }, // EFI_IFR_TO_UPPER_OP - 0x21
2273 { sizeof (EFI_IFR_MAP
), 1 }, // EFI_IFR_MAP - 0x22
2274 { sizeof (EFI_IFR_ORDERED_LIST
), 1 }, // EFI_IFR_ORDERED_LIST_OP - 0x23
2275 { sizeof (EFI_IFR_VARSTORE
), 0 }, // EFI_IFR_VARSTORE_OP
2276 { sizeof (EFI_IFR_VARSTORE_NAME_VALUE
), 0 }, // EFI_IFR_VARSTORE_NAME_VALUE_OP
2277 { sizeof (EFI_IFR_VARSTORE_EFI
), 0 }, // EFI_IFR_VARSTORE_EFI_OP
2278 { sizeof (EFI_IFR_VARSTORE_DEVICE
), 1 }, // EFI_IFR_VARSTORE_DEVICE_OP
2279 { sizeof (EFI_IFR_VERSION
), 0 }, // EFI_IFR_VERSION_OP - 0x28
2280 { sizeof (EFI_IFR_END
), 0 }, // EFI_IFR_END_OP
2281 { sizeof (EFI_IFR_MATCH
), 0 }, // EFI_IFR_MATCH_OP - 0x2A
2282 { sizeof (EFI_IFR_GET
), 0 }, // EFI_IFR_GET - 0x2B
2283 { sizeof (EFI_IFR_SET
), 0 }, // EFI_IFR_SET - 0x2C
2284 { sizeof (EFI_IFR_READ
), 0 }, // EFI_IFR_READ - 0x2D
2285 { sizeof (EFI_IFR_WRITE
), 0 }, // EFI_IFR_WRITE - 0x2E
2286 { sizeof (EFI_IFR_EQUAL
), 0 }, // EFI_IFR_EQUAL_OP - 0x2F
2287 { sizeof (EFI_IFR_NOT_EQUAL
), 0 }, // EFI_IFR_NOT_EQUAL_OP
2288 { sizeof (EFI_IFR_GREATER_THAN
), 0 }, // EFI_IFR_GREATER_THAN_OP
2289 { sizeof (EFI_IFR_GREATER_EQUAL
), 0 }, // EFI_IFR_GREATER_EQUAL_OP
2290 { sizeof (EFI_IFR_LESS_THAN
), 0 }, // EFI_IFR_LESS_THAN_OP
2291 { sizeof (EFI_IFR_LESS_EQUAL
), 0 }, // EFI_IFR_LESS_EQUAL_OP - 0x34
2292 { sizeof (EFI_IFR_BITWISE_AND
), 0 }, // EFI_IFR_BITWISE_AND_OP
2293 { sizeof (EFI_IFR_BITWISE_OR
), 0 }, // EFI_IFR_BITWISE_OR_OP
2294 { sizeof (EFI_IFR_BITWISE_NOT
), 0 }, // EFI_IFR_BITWISE_NOT_OP
2295 { sizeof (EFI_IFR_SHIFT_LEFT
), 0 }, // EFI_IFR_SHIFT_LEFT_OP
2296 { sizeof (EFI_IFR_SHIFT_RIGHT
), 0 }, // EFI_IFR_SHIFT_RIGHT_OP
2297 { sizeof (EFI_IFR_ADD
), 0 }, // EFI_IFR_ADD_OP - 0x3A
2298 { sizeof (EFI_IFR_SUBTRACT
), 0 }, // EFI_IFR_SUBTRACT_OP
2299 { sizeof (EFI_IFR_MULTIPLY
), 0 }, // EFI_IFR_MULTIPLY_OP
2300 { sizeof (EFI_IFR_DIVIDE
), 0 }, // EFI_IFR_DIVIDE_OP
2301 { sizeof (EFI_IFR_MODULO
), 0 }, // EFI_IFR_MODULO_OP - 0x3E
2302 { sizeof (EFI_IFR_RULE_REF
), 0 }, // EFI_IFR_RULE_REF_OP
2303 { sizeof (EFI_IFR_QUESTION_REF1
), 0 }, // EFI_IFR_QUESTION_REF1_OP
2304 { sizeof (EFI_IFR_QUESTION_REF2
), 0 }, // EFI_IFR_QUESTION_REF2_OP - 0x41
2305 { sizeof (EFI_IFR_UINT8
), 0}, // EFI_IFR_UINT8
2306 { sizeof (EFI_IFR_UINT16
), 0}, // EFI_IFR_UINT16
2307 { sizeof (EFI_IFR_UINT32
), 0}, // EFI_IFR_UINT32
2308 { sizeof (EFI_IFR_UINT64
), 0}, // EFI_IFR_UTNT64
2309 { sizeof (EFI_IFR_TRUE
), 0 }, // EFI_IFR_TRUE_OP - 0x46
2310 { sizeof (EFI_IFR_FALSE
), 0 }, // EFI_IFR_FALSE_OP
2311 { sizeof (EFI_IFR_TO_UINT
), 0 }, // EFI_IFR_TO_UINT_OP
2312 { sizeof (EFI_IFR_TO_STRING
), 0 }, // EFI_IFR_TO_STRING_OP
2313 { sizeof (EFI_IFR_TO_BOOLEAN
), 0 }, // EFI_IFR_TO_BOOLEAN_OP
2314 { sizeof (EFI_IFR_MID
), 0 }, // EFI_IFR_MID_OP
2315 { sizeof (EFI_IFR_FIND
), 0 }, // EFI_IFR_FIND_OP
2316 { sizeof (EFI_IFR_TOKEN
), 0 }, // EFI_IFR_TOKEN_OP
2317 { sizeof (EFI_IFR_STRING_REF1
), 0 }, // EFI_IFR_STRING_REF1_OP - 0x4E
2318 { sizeof (EFI_IFR_STRING_REF2
), 0 }, // EFI_IFR_STRING_REF2_OP
2319 { sizeof (EFI_IFR_CONDITIONAL
), 0 }, // EFI_IFR_CONDITIONAL_OP
2320 { sizeof (EFI_IFR_QUESTION_REF3
), 0 }, // EFI_IFR_QUESTION_REF3_OP
2321 { sizeof (EFI_IFR_ZERO
), 0 }, // EFI_IFR_ZERO_OP
2322 { sizeof (EFI_IFR_ONE
), 0 }, // EFI_IFR_ONE_OP
2323 { sizeof (EFI_IFR_ONES
), 0 }, // EFI_IFR_ONES_OP
2324 { sizeof (EFI_IFR_UNDEFINED
), 0 }, // EFI_IFR_UNDEFINED_OP
2325 { sizeof (EFI_IFR_LENGTH
), 0 }, // EFI_IFR_LENGTH_OP
2326 { sizeof (EFI_IFR_DUP
), 0 }, // EFI_IFR_DUP_OP - 0x57
2327 { sizeof (EFI_IFR_THIS
), 0 }, // EFI_IFR_THIS_OP
2328 { sizeof (EFI_IFR_SPAN
), 0 }, // EFI_IFR_SPAN_OP
2329 { sizeof (EFI_IFR_VALUE
), 1 }, // EFI_IFR_VALUE_OP
2330 { sizeof (EFI_IFR_DEFAULT
), 0 }, // EFI_IFR_DEFAULT_OP
2331 { sizeof (EFI_IFR_DEFAULTSTORE
), 0 }, // EFI_IFR_DEFAULTSTORE_OP - 0x5C
2332 { sizeof (EFI_IFR_FORM_MAP
), 1}, // EFI_IFR_FORM_MAP_OP - 0x5D
2333 { sizeof (EFI_IFR_CATENATE
), 0 }, // EFI_IFR_CATENATE_OP
2334 { sizeof (EFI_IFR_GUID
), 0 }, // EFI_IFR_GUID_OP
2335 { sizeof (EFI_IFR_SECURITY
), 0 }, // EFI_IFR_SECURITY_OP - 0x60
2336 { sizeof (EFI_IFR_MODAL_TAG
), 0}, // EFI_IFR_MODAL_TAG_OP - 0x61
2337 { sizeof (EFI_IFR_REFRESH_ID
), 0}, // EFI_IFR_REFRESH_ID_OP - 0x62
2338 { sizeof (EFI_IFR_WARNING_IF
), 1}, // EFI_IFR_WARNING_IF_OP - 0x63
2339 { sizeof (EFI_IFR_MATCH2
), 0 }, // EFI_IFR_MATCH2_OP - 0x64
2342 #ifdef CIFROBJ_DEUBG
2345 } gIfrObjPrintDebugTable
[] = {
2346 "EFI_IFR_INVALID", "EFI_IFR_FORM", "EFI_IFR_SUBTITLE", "EFI_IFR_TEXT", "EFI_IFR_IMAGE", "EFI_IFR_ONE_OF",
2347 "EFI_IFR_CHECKBOX", "EFI_IFR_NUMERIC", "EFI_IFR_PASSWORD", "EFI_IFR_ONE_OF_OPTION", "EFI_IFR_SUPPRESS_IF", "EFI_IFR_LOCKED",
2348 "EFI_IFR_ACTION", "EFI_IFR_RESET_BUTTON", "EFI_IFR_FORM_SET", "EFI_IFR_REF", "EFI_IFR_NO_SUBMIT_IF", "EFI_IFR_INCONSISTENT_IF",
2349 "EFI_IFR_EQ_ID_VAL", "EFI_IFR_EQ_ID_ID", "EFI_IFR_EQ_ID_LIST", "EFI_IFR_AND", "EFI_IFR_OR", "EFI_IFR_NOT",
2350 "EFI_IFR_RULE", "EFI_IFR_GRAY_OUT_IF", "EFI_IFR_DATE", "EFI_IFR_TIME", "EFI_IFR_STRING", "EFI_IFR_REFRESH",
2351 "EFI_IFR_DISABLE_IF", "EFI_IFR_INVALID", "EFI_IFR_TO_LOWER", "EFI_IFR_TO_UPPER", "EFI_IFR_MAP", "EFI_IFR_ORDERED_LIST",
2352 "EFI_IFR_VARSTORE", "EFI_IFR_VARSTORE_NAME_VALUE", "EFI_IFR_VARSTORE_EFI", "EFI_IFR_VARSTORE_DEVICE", "EFI_IFR_VERSION", "EFI_IFR_END",
2353 "EFI_IFR_MATCH", "EFI_IFR_GET", "EFI_IFR_SET", "EFI_IFR_READ", "EFI_IFR_WRITE", "EFI_IFR_EQUAL",
2354 "EFI_IFR_NOT_EQUAL", "EFI_IFR_GREATER_THAN", "EFI_IFR_GREATER_EQUAL", "EFI_IFR_LESS_THAN", "EFI_IFR_LESS_EQUAL", "EFI_IFR_BITWISE_AND",
2355 "EFI_IFR_BITWISE_OR", "EFI_IFR_BITWISE_NOT", "EFI_IFR_SHIFT_LEFT", "EFI_IFR_SHIFT_RIGHT", "EFI_IFR_ADD", "EFI_IFR_SUBTRACT",
2356 "EFI_IFR_MULTIPLY", "EFI_IFR_DIVIDE", "EFI_IFR_MODULO", "EFI_IFR_RULE_REF", "EFI_IFR_QUESTION_REF1", "EFI_IFR_QUESTION_REF2",
2357 "EFI_IFR_UINT8", "EFI_IFR_UINT16", "EFI_IFR_UINT32", "EFI_IFR_UINT64", "EFI_IFR_TRUE", "EFI_IFR_FALSE",
2358 "EFI_IFR_TO_UINT", "EFI_IFR_TO_STRING", "EFI_IFR_TO_BOOLEAN", "EFI_IFR_MID", "EFI_IFR_FIND", "EFI_IFR_TOKEN",
2359 "EFI_IFR_STRING_REF1","EFI_IFR_STRING_REF2", "EFI_IFR_CONDITIONAL", "EFI_IFR_QUESTION_REF3", "EFI_IFR_ZERO", "EFI_IFR_ONE",
2360 "EFI_IFR_ONES", "EFI_IFR_UNDEFINED", "EFI_IFR_LENGTH", "EFI_IFR_DUP", "EFI_IFR_THIS", "EFI_IFR_SPAN",
2361 "EFI_IFR_VALUE", "EFI_IFR_DEFAULT", "EFI_IFR_DEFAULTSTORE", "EFI_IFR_FORM_MAP", "EFI_IFR_CATENATE", "EFI_IFR_GUID",
2362 "EFI_IFR_SECURITY", "EFI_IFR_MODAL_TAG", "EFI_IFR_REFRESH_ID", "EFI_IFR_WARNING_IF", "EFI_IFR_MATCH2",
2366 CIFROBJ_DEBUG_PRINT (
2370 printf ("======Create IFR [%s]\n", gIfrObjPrintDebugTable
[OpCode
].mIfrName
);
2374 #define CIFROBJ_DEBUG_PRINT(OpCode)
2378 BOOLEAN gCreateOp
= TRUE
;
2384 IN BOOLEAN DelayEmit
2387 mDelayEmit
= DelayEmit
;
2388 mPkgOffset
= gCFormPkg
.GetPkgLength ();
2389 mObjBinLen
= (ObjBinLen
== 0) ? gOpcodeSizesScopeTable
[OpCode
].mSize
: ObjBinLen
;
2390 mObjBinBuf
= ((DelayEmit
== FALSE
) && (gCreateOp
== TRUE
)) ? gCFormPkg
.IfrBinBufferGet (mObjBinLen
) : new CHAR8
[EFI_IFR_MAX_LENGTH
];
2391 mRecordIdx
= (gCreateOp
== TRUE
) ? gCIfrRecordInfoDB
.IfrRecordRegister (0xFFFFFFFF, mObjBinBuf
, mObjBinLen
, mPkgOffset
) : EFI_IFR_RECORDINFO_IDX_INVALUD
;
2393 assert (mObjBinBuf
!= NULL
);
2395 if (IfrObj
!= NULL
) {
2396 *IfrObj
= mObjBinBuf
;
2399 CIFROBJ_DEBUG_PRINT (OpCode
);
2406 if ((mDelayEmit
== TRUE
) && ((gCreateOp
== TRUE
))) {
2407 _EMIT_PENDING_OBJ ();
2410 gCIfrRecordInfoDB
.IfrRecordInfoUpdate (mRecordIdx
, mLineNo
, mObjBinBuf
, mObjBinLen
, mPkgOffset
);
2414 * The definition of CIfrObj's member function
2416 UINT8 gScopeCount
= 0;
2418 CIfrOpHeader::CIfrOpHeader (
2422 ) : mHeader ((EFI_IFR_OP_HEADER
*)StartAddr
)
2424 mHeader
->OpCode
= OpCode
;
2425 mHeader
->Length
= (Length
== 0) ? gOpcodeSizesScopeTable
[OpCode
].mSize
: Length
;
2426 mHeader
->Scope
= (gOpcodeSizesScopeTable
[OpCode
].mScope
+ gScopeCount
> 0) ? 1 : 0;
2429 CIfrOpHeader::CIfrOpHeader (
2430 IN CIfrOpHeader
&OpHdr
2433 mHeader
= OpHdr
.mHeader
;
2436 UINT32
CIfrFormId::FormIdBitMap
[EFI_FREE_FORM_ID_BITMAP_SIZE
] = {0, };