3 The definition of CFormPkg's member function
5 Copyright (c) 2004 - 2017, 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
) {
119 BufferEnd
= BufferStart
+ BufferSize
;
121 memset (BufferStart
, 0, BufferSize
);
122 Node
->mBufferStart
= BufferStart
;
123 Node
->mBufferEnd
= BufferEnd
;
124 Node
->mBufferFree
= BufferStart
;
127 mBufferSize
= BufferSize
;
128 mBufferNodeQueueHead
= Node
;
129 mBufferNodeQueueTail
= Node
;
130 mCurrBufferNode
= Node
;
133 CFormPkg::~CFormPkg ()
136 SPendingAssign
*pPNode
;
138 while (mBufferNodeQueueHead
!= NULL
) {
139 pBNode
= mBufferNodeQueueHead
;
140 mBufferNodeQueueHead
= mBufferNodeQueueHead
->mNext
;
141 if (pBNode
->mBufferStart
!= NULL
) {
142 delete pBNode
->mBufferStart
;
146 mBufferNodeQueueTail
= NULL
;
147 mCurrBufferNode
= NULL
;
149 while (PendingAssignList
!= NULL
) {
150 pPNode
= PendingAssignList
;
151 PendingAssignList
= PendingAssignList
->mNext
;
154 PendingAssignList
= NULL
;
158 CFormPkg::CreateNewNode (
164 Node
= new SBufferNode
;
169 Node
->mBufferStart
= new CHAR8
[mBufferSize
];
170 if (Node
->mBufferStart
== NULL
) {
174 memset (Node
->mBufferStart
, 0, mBufferSize
);
175 Node
->mBufferEnd
= Node
->mBufferStart
+ mBufferSize
;
176 Node
->mBufferFree
= Node
->mBufferStart
;
184 CFormPkg::IfrBinBufferGet (
188 CHAR8
*BinBuffer
= NULL
;
189 SBufferNode
*Node
= NULL
;
191 if ((Len
== 0) || (Len
> mBufferSize
)) {
195 if ((mCurrBufferNode
->mBufferFree
+ Len
) <= mCurrBufferNode
->mBufferEnd
) {
196 BinBuffer
= mCurrBufferNode
->mBufferFree
;
197 mCurrBufferNode
->mBufferFree
+= Len
;
199 Node
= CreateNewNode ();
204 if (mBufferNodeQueueTail
== NULL
) {
205 mBufferNodeQueueHead
= mBufferNodeQueueTail
= Node
;
207 mBufferNodeQueueTail
->mNext
= Node
;
208 mBufferNodeQueueTail
= Node
;
210 mCurrBufferNode
= Node
;
215 BinBuffer
= mCurrBufferNode
->mBufferFree
;
216 mCurrBufferNode
->mBufferFree
+= Len
;
226 CFormPkg::GetPkgLength (
238 mReadBufferNode
= mBufferNodeQueueHead
;
239 mReadBufferOffset
= 0;
247 mReadBufferNode
= NULL
;
248 mReadBufferOffset
= 0;
259 if ((Size
== 0) || (Buffer
== NULL
)) {
263 if (mReadBufferNode
== NULL
) {
267 for (Index
= 0; Index
< Size
; Index
++) {
268 if ((mReadBufferNode
->mBufferStart
+ mReadBufferOffset
) < mReadBufferNode
->mBufferFree
) {
269 Buffer
[Index
] = mReadBufferNode
->mBufferStart
[mReadBufferOffset
++];
271 if ((mReadBufferNode
= mReadBufferNode
->mNext
) == NULL
) {
274 mReadBufferOffset
= 0;
284 CFormPkg::BuildPkgHdr (
285 OUT EFI_HII_PACKAGE_HEADER
**PkgHdr
288 if (PkgHdr
== NULL
) {
289 return VFR_RETURN_FATAL_ERROR
;
292 if (((*PkgHdr
) = new EFI_HII_PACKAGE_HEADER
) == NULL
) {
293 return VFR_RETURN_OUT_FOR_RESOURCES
;
296 (*PkgHdr
)->Type
= EFI_HII_PACKAGE_FORM
;
297 (*PkgHdr
)->Length
= mPkgLength
+ sizeof (EFI_HII_PACKAGE_HEADER
);
299 return VFR_RETURN_SUCCESS
;
304 OUT PACKAGE_DATA
&TBuffer
312 if (TBuffer
.Buffer
!= NULL
) {
313 delete TBuffer
.Buffer
;
316 TBuffer
.Size
= mPkgLength
;
317 TBuffer
.Buffer
= NULL
;
318 if (TBuffer
.Size
!= 0) {
319 TBuffer
.Buffer
= new CHAR8
[TBuffer
.Size
];
321 return VFR_RETURN_SUCCESS
;
324 Temp
= TBuffer
.Buffer
;
326 while ((Size
= Read (Buffer
, 1024)) != 0) {
327 memcpy (Temp
, Buffer
, Size
);
331 return VFR_RETURN_SUCCESS
;
338 IN PACKAGE_DATA
*PkgData
341 EFI_VFR_RETURN_CODE Ret
;
344 EFI_HII_PACKAGE_HEADER
*PkgHdr
;
346 if (Output
== NULL
) {
347 return VFR_RETURN_FATAL_ERROR
;
350 if ((Ret
= BuildPkgHdr(&PkgHdr
)) != VFR_RETURN_SUCCESS
) {
353 fwrite (PkgHdr
, sizeof (EFI_HII_PACKAGE_HEADER
), 1, Output
);
356 if (PkgData
== NULL
) {
358 while ((Size
= Read (Buffer
, 1024)) != 0) {
359 fwrite (Buffer
, Size
, 1, Output
);
363 fwrite (PkgData
->Buffer
, PkgData
->Size
, 1, Output
);
366 return VFR_RETURN_SUCCESS
;
370 CFormPkg::_WRITE_PKG_LINE (
373 IN CONST CHAR8
*LineHeader
,
380 if ((pFile
== NULL
) || (LineHeader
== NULL
) || (BlkBuf
== NULL
)) {
384 for (Index
= 0; Index
< BlkSize
; Index
++) {
385 if ((Index
% LineBytes
) == 0) {
386 fprintf (pFile
, "\n%s", LineHeader
);
388 fprintf (pFile
, "0x%02X, ", (UINT8
)BlkBuf
[Index
]);
393 CFormPkg::_WRITE_PKG_END (
396 IN CONST CHAR8
*LineHeader
,
403 if ((BlkSize
== 0) || (pFile
== NULL
) || (LineHeader
== NULL
) || (BlkBuf
== NULL
)) {
407 for (Index
= 0; Index
< BlkSize
- 1; Index
++) {
408 if ((Index
% LineBytes
) == 0) {
409 fprintf (pFile
, "\n%s", LineHeader
);
411 fprintf (pFile
, "0x%02X, ", (UINT8
)BlkBuf
[Index
]);
414 if ((Index
% LineBytes
) == 0) {
415 fprintf (pFile
, "\n%s", LineHeader
);
417 fprintf (pFile
, "0x%02X\n", (UINT8
)BlkBuf
[Index
]);
420 #define BYTES_PRE_LINE 0x10
421 UINT32 gAdjustOpcodeOffset
= 0;
422 BOOLEAN gNeedAdjustOpcode
= FALSE
;
423 UINT32 gAdjustOpcodeLen
= 0;
429 IN PACKAGE_DATA
*PkgData
432 EFI_VFR_RETURN_CODE Ret
;
433 CHAR8 Buffer
[BYTES_PRE_LINE
* 8];
434 EFI_HII_PACKAGE_HEADER
*PkgHdr
;
435 UINT32 PkgLength
= 0;
438 if ((BaseName
== NULL
) || (pFile
== NULL
)) {
439 return VFR_RETURN_FATAL_ERROR
;
442 fprintf (pFile
, "\nunsigned char %sBin[] = {\n", BaseName
);
444 if ((Ret
= BuildPkgHdr(&PkgHdr
)) != VFR_RETURN_SUCCESS
) {
449 // For framework vfr file, the extension framework header will be added.
451 if (VfrCompatibleMode
) {
452 fprintf (pFile
, " // FRAMEWORK PACKAGE HEADER Length\n");
453 PkgLength
= PkgHdr
->Length
+ sizeof (UINT32
) + 2;
454 _WRITE_PKG_LINE(pFile
, BYTES_PRE_LINE
, " ", (CHAR8
*)&PkgLength
, sizeof (UINT32
));
455 fprintf (pFile
, "\n\n // FRAMEWORK PACKAGE HEADER Type\n");
457 _WRITE_PKG_LINE(pFile
, BYTES_PRE_LINE
, " ", (CHAR8
*)&PkgLength
, sizeof (UINT16
));
459 fprintf (pFile
, " // ARRAY LENGTH\n");
460 PkgLength
= PkgHdr
->Length
+ sizeof (UINT32
);
461 _WRITE_PKG_LINE(pFile
, BYTES_PRE_LINE
, " ", (CHAR8
*)&PkgLength
, sizeof (UINT32
));
464 fprintf (pFile
, "\n\n // PACKAGE HEADER\n");
465 _WRITE_PKG_LINE(pFile
, BYTES_PRE_LINE
, " ", (CHAR8
*)PkgHdr
, sizeof (EFI_HII_PACKAGE_HEADER
));
466 PkgLength
= sizeof (EFI_HII_PACKAGE_HEADER
);
468 fprintf (pFile
, "\n\n // PACKAGE DATA\n");
470 if (PkgData
== NULL
) {
472 while ((ReadSize
= Read ((CHAR8
*)Buffer
, BYTES_PRE_LINE
* 8)) != 0) {
473 PkgLength
+= ReadSize
;
474 if (PkgLength
< PkgHdr
->Length
) {
475 _WRITE_PKG_LINE (pFile
, BYTES_PRE_LINE
, " ", Buffer
, ReadSize
);
477 _WRITE_PKG_END (pFile
, BYTES_PRE_LINE
, " ", Buffer
, ReadSize
);
482 if (PkgData
->Size
% BYTES_PRE_LINE
!= 0) {
483 PkgLength
= PkgData
->Size
- (PkgData
->Size
% BYTES_PRE_LINE
);
484 _WRITE_PKG_LINE (pFile
, BYTES_PRE_LINE
, " ", PkgData
->Buffer
, PkgLength
);
485 _WRITE_PKG_END (pFile
, BYTES_PRE_LINE
, " ", PkgData
->Buffer
+ PkgLength
, PkgData
->Size
% BYTES_PRE_LINE
);
487 PkgLength
= PkgData
->Size
- BYTES_PRE_LINE
;
488 _WRITE_PKG_LINE (pFile
, BYTES_PRE_LINE
, " ", PkgData
->Buffer
, PkgLength
);
489 _WRITE_PKG_END (pFile
, BYTES_PRE_LINE
, " ", PkgData
->Buffer
+ PkgLength
, BYTES_PRE_LINE
);
494 fprintf (pFile
, "\n};\n");
496 return VFR_RETURN_SUCCESS
;
500 CFormPkg::AssignPending (
508 SPendingAssign
*pNew
;
510 pNew
= new SPendingAssign (Key
, ValAddr
, ValLen
, LineNo
, Msg
);
512 return VFR_RETURN_OUT_FOR_RESOURCES
;
515 pNew
->mNext
= PendingAssignList
;
516 PendingAssignList
= pNew
;
517 return VFR_RETURN_SUCCESS
;
521 CFormPkg::DoPendingAssign (
527 SPendingAssign
*pNode
;
529 if ((Key
== NULL
) || (ValAddr
== NULL
)) {
533 for (pNode
= PendingAssignList
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
534 if (strcmp (pNode
->mKey
, Key
) == 0) {
535 pNode
->AssignValue (ValAddr
, ValLen
);
541 CFormPkg::HavePendingUnassigned (
545 SPendingAssign
*pNode
;
547 for (pNode
= PendingAssignList
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
548 if (pNode
->mFlag
== PENDING
) {
557 CFormPkg::PendingAssignPrintAll (
561 SPendingAssign
*pNode
;
563 for (pNode
= PendingAssignList
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
564 if (pNode
->mFlag
== PENDING
) {
565 gCVfrErrorHandle
.PrintMsg (pNode
->mLineNo
, pNode
->mKey
, "Error", pNode
->mMsg
);
571 CFormPkg::GetBinBufferNodeForAddr (
572 IN CHAR8
*BinBuffAddr
575 SBufferNode
*TmpNode
;
577 TmpNode
= mBufferNodeQueueHead
;
579 while (TmpNode
!= NULL
) {
580 if (TmpNode
->mBufferStart
<= BinBuffAddr
&& TmpNode
->mBufferFree
>= BinBuffAddr
) {
584 TmpNode
= TmpNode
->mNext
;
591 CFormPkg::GetNodeBefore(
592 IN SBufferNode
*CurrentNode
595 SBufferNode
*FirstNode
= mBufferNodeQueueHead
;
596 SBufferNode
*LastNode
= mBufferNodeQueueHead
;
598 while (FirstNode
!= NULL
) {
599 if (FirstNode
== CurrentNode
) {
603 LastNode
= FirstNode
;
604 FirstNode
= FirstNode
->mNext
;
607 if (FirstNode
== NULL
) {
615 CFormPkg::InsertNodeBefore(
616 IN SBufferNode
*CurrentNode
,
617 IN SBufferNode
*NewNode
620 SBufferNode
*LastNode
= GetNodeBefore (CurrentNode
);
622 if (LastNode
== NULL
) {
623 return VFR_RETURN_MISMATCHED
;
626 NewNode
->mNext
= LastNode
->mNext
;
627 LastNode
->mNext
= NewNode
;
629 return VFR_RETURN_SUCCESS
;
633 CFormPkg::GetBufAddrBaseOnOffset (
637 SBufferNode
*TmpNode
;
639 UINT32 CurrentBufLen
;
643 for (TmpNode
= mBufferNodeQueueHead
; TmpNode
!= NULL
; TmpNode
= TmpNode
->mNext
) {
644 CurrentBufLen
= TmpNode
->mBufferFree
- TmpNode
->mBufferStart
;
645 if (Offset
>= TotalBufLen
&& Offset
< TotalBufLen
+ CurrentBufLen
) {
646 return TmpNode
->mBufferStart
+ (Offset
- TotalBufLen
);
649 TotalBufLen
+= CurrentBufLen
;
656 CFormPkg::AdjustDynamicInsertOpcode (
657 IN CHAR8
*InserPositionAddr
,
658 IN CHAR8
*InsertOpcodeAddr
,
659 IN BOOLEAN CreateOpcodeAfterParsingVfr
662 SBufferNode
*InserPositionNode
;
663 SBufferNode
*InsertOpcodeNode
;
664 SBufferNode
*NewRestoreNodeBegin
;
665 SBufferNode
*NewRestoreNodeEnd
;
666 SBufferNode
*NewLastEndNode
;
667 SBufferNode
*TmpNode
;
668 UINT32 NeedRestoreCodeLen
;
670 NewRestoreNodeEnd
= NULL
;
672 InserPositionNode
= GetBinBufferNodeForAddr(InserPositionAddr
);
673 InsertOpcodeNode
= GetBinBufferNodeForAddr(InsertOpcodeAddr
);
674 assert (InserPositionNode
!= NULL
);
675 assert (InsertOpcodeNode
!= NULL
);
677 if (InserPositionNode
== InsertOpcodeNode
) {
679 // Create New Node to save the restore opcode.
681 NeedRestoreCodeLen
= InsertOpcodeAddr
- InserPositionAddr
;
682 gAdjustOpcodeLen
= NeedRestoreCodeLen
;
683 NewRestoreNodeBegin
= CreateNewNode ();
684 if (NewRestoreNodeBegin
== NULL
) {
685 return VFR_RETURN_OUT_FOR_RESOURCES
;
687 memcpy (NewRestoreNodeBegin
->mBufferFree
, InserPositionAddr
, NeedRestoreCodeLen
);
688 NewRestoreNodeBegin
->mBufferFree
+= NeedRestoreCodeLen
;
691 // Override the restore buffer data.
693 memmove (InserPositionAddr
, InsertOpcodeAddr
, InsertOpcodeNode
->mBufferFree
- InsertOpcodeAddr
);
694 InsertOpcodeNode
->mBufferFree
-= NeedRestoreCodeLen
;
695 memset (InsertOpcodeNode
->mBufferFree
, 0, NeedRestoreCodeLen
);
698 // Create New Node to save the restore opcode.
700 NeedRestoreCodeLen
= InserPositionNode
->mBufferFree
- InserPositionAddr
;
701 gAdjustOpcodeLen
= NeedRestoreCodeLen
;
702 NewRestoreNodeBegin
= CreateNewNode ();
703 if (NewRestoreNodeBegin
== NULL
) {
704 return VFR_RETURN_OUT_FOR_RESOURCES
;
706 memcpy (NewRestoreNodeBegin
->mBufferFree
, InserPositionAddr
, NeedRestoreCodeLen
);
707 NewRestoreNodeBegin
->mBufferFree
+= NeedRestoreCodeLen
;
709 // Override the restore buffer data.
711 InserPositionNode
->mBufferFree
-= NeedRestoreCodeLen
;
713 // Link the restore data to new node.
715 NewRestoreNodeBegin
->mNext
= InserPositionNode
->mNext
;
718 // Count the Adjust opcode len.
720 TmpNode
= InserPositionNode
->mNext
;
721 while (TmpNode
!= InsertOpcodeNode
) {
722 gAdjustOpcodeLen
+= TmpNode
->mBufferFree
- TmpNode
->mBufferStart
;
723 TmpNode
= TmpNode
->mNext
;
727 // Create New Node to save the last node of restore opcode.
729 NeedRestoreCodeLen
= InsertOpcodeAddr
- InsertOpcodeNode
->mBufferStart
;
730 gAdjustOpcodeLen
+= NeedRestoreCodeLen
;
731 if (NeedRestoreCodeLen
> 0) {
732 NewRestoreNodeEnd
= CreateNewNode ();
733 if (NewRestoreNodeEnd
== NULL
) {
734 return VFR_RETURN_OUT_FOR_RESOURCES
;
736 memcpy (NewRestoreNodeEnd
->mBufferFree
, InsertOpcodeNode
->mBufferStart
, NeedRestoreCodeLen
);
737 NewRestoreNodeEnd
->mBufferFree
+= NeedRestoreCodeLen
;
739 // Override the restore buffer data.
741 memmove (InsertOpcodeNode
->mBufferStart
, InsertOpcodeAddr
, InsertOpcodeNode
->mBufferFree
- InsertOpcodeAddr
);
742 InsertOpcodeNode
->mBufferFree
-= InsertOpcodeAddr
- InsertOpcodeNode
->mBufferStart
;
745 // Insert the last restore data node.
747 TmpNode
= GetNodeBefore (InsertOpcodeNode
);
748 assert (TmpNode
!= NULL
);
750 if (TmpNode
== InserPositionNode
) {
751 NewRestoreNodeBegin
->mNext
= NewRestoreNodeEnd
;
753 TmpNode
->mNext
= NewRestoreNodeEnd
;
756 // Connect the dynamic opcode node to the node after InserPositionNode.
758 InserPositionNode
->mNext
= InsertOpcodeNode
;
762 if (CreateOpcodeAfterParsingVfr
) {
764 // Th new opcodes were created after Parsing Vfr file,
765 // so the content in mBufferNodeQueueTail must be the new created opcodes.
766 // So connet the NewRestoreNodeBegin to the tail and update the tail node.
768 mBufferNodeQueueTail
->mNext
= NewRestoreNodeBegin
;
769 if (NewRestoreNodeEnd
!= NULL
) {
770 mBufferNodeQueueTail
= NewRestoreNodeEnd
;
772 mBufferNodeQueueTail
= NewRestoreNodeBegin
;
775 if (mBufferNodeQueueTail
->mBufferFree
- mBufferNodeQueueTail
->mBufferStart
> 2) {
777 // End form set opcode all in the mBufferNodeQueueTail node.
779 NewLastEndNode
= CreateNewNode ();
780 if (NewLastEndNode
== NULL
) {
781 return VFR_RETURN_OUT_FOR_RESOURCES
;
783 NewLastEndNode
->mBufferStart
[0] = 0x29;
784 NewLastEndNode
->mBufferStart
[1] = 0x02;
785 NewLastEndNode
->mBufferFree
+= 2;
787 mBufferNodeQueueTail
->mBufferFree
-= 2;
789 mBufferNodeQueueTail
->mNext
= NewRestoreNodeBegin
;
790 if (NewRestoreNodeEnd
!= NULL
) {
791 NewRestoreNodeEnd
->mNext
= NewLastEndNode
;
793 NewRestoreNodeBegin
->mNext
= NewLastEndNode
;
796 mBufferNodeQueueTail
= NewLastEndNode
;
797 } else if (mBufferNodeQueueTail
->mBufferFree
- mBufferNodeQueueTail
->mBufferStart
== 2) {
798 TmpNode
= GetNodeBefore(mBufferNodeQueueTail
);
799 assert (TmpNode
!= NULL
);
801 TmpNode
->mNext
= NewRestoreNodeBegin
;
802 if (NewRestoreNodeEnd
!= NULL
) {
803 NewRestoreNodeEnd
->mNext
= mBufferNodeQueueTail
;
805 NewRestoreNodeBegin
->mNext
= mBufferNodeQueueTail
;
809 mCurrBufferNode
= mBufferNodeQueueTail
;
810 return VFR_RETURN_SUCCESS
;
814 CFormPkg::DeclarePendingQuestion (
815 IN CVfrVarDataTypeDB
&lCVfrVarDataTypeDB
,
816 IN CVfrDataStorage
&lCVfrDataStorage
,
817 IN CVfrQuestionDB
&lCVfrQuestionDB
,
818 IN EFI_GUID
*LocalFormSetGuid
,
820 OUT CHAR8
**InsertOpcodeAddr
823 SPendingAssign
*pNode
;
826 CHAR8 FName
[MAX_NAME_LEN
];
829 UINT32 ShrinkSize
= 0;
830 EFI_VFR_RETURN_CODE ReturnCode
;
831 EFI_VFR_VARSTORE_TYPE VarStoreType
= EFI_VFR_VARSTORE_INVALID
;
834 CIfrGuid
*GuidObj
= NULL
;
837 // Declare all questions as Numeric in DisableIf True
841 DIObj
.SetLineNo (LineNo
);
842 *InsertOpcodeAddr
= DIObj
.GetObjBinAddr ();
845 CIfrTrue
TObj (LineNo
);
847 // Declare Numeric qeustion for each undefined question.
848 for (pNode
= PendingAssignList
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
849 if (pNode
->mFlag
== PENDING
) {
850 EFI_VARSTORE_INFO Info
;
851 EFI_QUESTION_ID QId
= EFI_QUESTION_ID_INVALID
;
853 // Register this question, assume it is normal question, not date or time question
855 VarStr
= pNode
->mKey
;
856 ReturnCode
= lCVfrQuestionDB
.RegisterQuestion (NULL
, VarStr
, QId
);
857 if (ReturnCode
!= VFR_RETURN_SUCCESS
) {
858 gCVfrErrorHandle
.HandleError (ReturnCode
, pNode
->mLineNo
, pNode
->mKey
);
863 printf ("Undefined Question name is %s and Id is 0x%x\n", VarStr
, QId
);
866 // Get Question Info, framework vfr VarName == StructName
868 ReturnCode
= lCVfrVarDataTypeDB
.ExtractFieldNameAndArrary (VarStr
, FName
, ArrayIdx
);
869 if (ReturnCode
!= VFR_RETURN_SUCCESS
) {
870 gCVfrErrorHandle
.PrintMsg (pNode
->mLineNo
, pNode
->mKey
, "Error", "Var string is not the valid C variable");
876 ReturnCode
= lCVfrDataStorage
.GetVarStoreId (FName
, &Info
.mVarStoreId
);
877 if (ReturnCode
!= VFR_RETURN_SUCCESS
) {
878 gCVfrErrorHandle
.PrintMsg (pNode
->mLineNo
, FName
, "Error", "Var Store Type is not defined");
881 VarStoreType
= lCVfrDataStorage
.GetVarStoreType (Info
.mVarStoreId
);
883 if (*VarStr
== '\0' && ArrayIdx
!= INVALID_ARRAY_INDEX
) {
884 ReturnCode
= lCVfrDataStorage
.GetNameVarStoreInfo (&Info
, ArrayIdx
);
886 if (VarStoreType
== EFI_VFR_VARSTORE_EFI
) {
887 ReturnCode
= lCVfrDataStorage
.GetEfiVarStoreInfo (&Info
);
888 } else if (VarStoreType
== EFI_VFR_VARSTORE_BUFFER
|| VarStoreType
== EFI_VFR_VARSTORE_BUFFER_BITS
) {
889 VarStr
= pNode
->mKey
;
890 //convert VarStr with store name to VarStr with structure name
891 ReturnCode
= lCVfrDataStorage
.GetBufferVarStoreDataTypeName (Info
.mVarStoreId
, &SName
);
892 if (ReturnCode
== VFR_RETURN_SUCCESS
) {
893 NewStr
= new CHAR8
[strlen (VarStr
) + strlen (SName
) + 1];
895 strcpy (NewStr
, SName
);
896 strcat (NewStr
, VarStr
+ strlen (FName
));
897 ReturnCode
= lCVfrVarDataTypeDB
.GetDataFieldInfo (NewStr
, Info
.mInfo
.mVarOffset
, Info
.mVarType
, Info
.mVarTotalSize
, Info
.mIsBitVar
);
901 ReturnCode
= VFR_RETURN_UNSUPPORTED
;
904 if (ReturnCode
!= VFR_RETURN_SUCCESS
) {
905 gCVfrErrorHandle
.HandleError (ReturnCode
, pNode
->mLineNo
, pNode
->mKey
);
909 // If the storage is bit fields, create Guid opcode to wrap the numeric opcode.
911 if (Info
.mIsBitVar
) {
912 GuidObj
= new CIfrGuid(0);
913 GuidObj
->SetGuid (&gEdkiiIfrBitVarGuid
);
914 GuidObj
->SetLineNo(LineNo
);
918 CNObj
.SetLineNo (LineNo
);
919 CNObj
.SetPrompt (0x0);
921 CNObj
.SetQuestionId (QId
);
922 CNObj
.SetVarStoreInfo (&Info
);
925 // Set Min/Max/Step Data and flags for the question with bit fields.Min/Max/Step Data are saved as UINT32 type for bit question.
927 if (Info
.mIsBitVar
) {
928 MaxValue
= (1 << Info
.mVarTotalSize
) -1;
929 CNObj
.SetMinMaxStepData ((UINT32
) 0, MaxValue
, (UINT32
) 0);
931 LFlags
= (EDKII_IFR_NUMERIC_SIZE_BIT
& Info
.mVarTotalSize
);
932 CNObj
.SetFlagsForBitField (0, LFlags
);
935 // Numeric doesn't support BOOLEAN data type.
936 // BOOLEAN type has the same data size to UINT8.
938 if (Info
.mVarType
== EFI_IFR_TYPE_BOOLEAN
) {
939 Info
.mVarType
= EFI_IFR_TYPE_NUM_SIZE_8
;
941 CNObj
.SetFlags (0, Info
.mVarType
);
943 // Use maximum value not to limit the vaild value for the undefined question.
945 switch (Info
.mVarType
) {
946 case EFI_IFR_TYPE_NUM_SIZE_64
:
947 CNObj
.SetMinMaxStepData ((UINT64
) 0, (UINT64
) -1 , (UINT64
) 0);
950 case EFI_IFR_TYPE_NUM_SIZE_32
:
951 CNObj
.SetMinMaxStepData ((UINT32
) 0, (UINT32
) -1 , (UINT32
) 0);
954 case EFI_IFR_TYPE_NUM_SIZE_16
:
955 CNObj
.SetMinMaxStepData ((UINT16
) 0, (UINT16
) -1 , (UINT16
) 0);
958 case EFI_IFR_TYPE_NUM_SIZE_8
:
959 CNObj
.SetMinMaxStepData ((UINT8
) 0, (UINT8
) -1 , (UINT8
) 0);
966 CNObj
.ShrinkBinSize (ShrinkSize
);
969 // For undefined Efi VarStore type question
970 // Append the extended guided opcode to contain VarName
972 if (VarStoreType
== EFI_VFR_VARSTORE_EFI
|| VfrCompatibleMode
) {
973 CIfrVarEqName
CVNObj (QId
, Info
.mInfo
.mVarName
);
974 CVNObj
.SetLineNo (LineNo
);
981 CEObj
.SetLineNo (LineNo
);
983 // End for Guided opcode
985 if (GuidObj
!= NULL
) {
987 CEObjGuid
.SetLineNo (LineNo
);
988 GuidObj
->SetScope(1);
999 SEObj
.SetLineNo (LineNo
);
1001 return VFR_RETURN_SUCCESS
;
1006 SIfrRecord::SIfrRecord (
1012 mLineNo
= 0xFFFFFFFF;
1013 mOffset
= 0xFFFFFFFF;
1017 SIfrRecord::~SIfrRecord (
1021 if (mIfrBinBuf
!= NULL
) {
1022 //delete mIfrBinBuf;
1025 mLineNo
= 0xFFFFFFFF;
1026 mOffset
= 0xFFFFFFFF;
1031 CIfrRecordInfoDB::CIfrRecordInfoDB (
1036 mRecordCount
= EFI_IFR_RECORDINFO_IDX_START
;
1037 mIfrRecordListHead
= NULL
;
1038 mIfrRecordListTail
= NULL
;
1039 mAllDefaultTypeCount
= 0;
1040 for (UINT8 i
= 0; i
< EFI_HII_MAX_SUPPORT_DEFAULT_TYPE
; i
++) {
1041 mAllDefaultIdArray
[i
] = 0xffff;
1045 CIfrRecordInfoDB::~CIfrRecordInfoDB (
1051 while (mIfrRecordListHead
!= NULL
) {
1052 pNode
= mIfrRecordListHead
;
1053 mIfrRecordListHead
= mIfrRecordListHead
->mNext
;
1059 CIfrRecordInfoDB::GetRecordInfoFromIdx (
1064 SIfrRecord
*pNode
= NULL
;
1066 if (RecordIdx
== EFI_IFR_RECORDINFO_IDX_INVALUD
) {
1070 for (Idx
= (EFI_IFR_RECORDINFO_IDX_START
+ 1), pNode
= mIfrRecordListHead
;
1071 (Idx
!= RecordIdx
) && (pNode
!= NULL
);
1072 Idx
++, pNode
= pNode
->mNext
)
1079 CIfrRecordInfoDB::IfrRecordRegister (
1081 IN CHAR8
*IfrBinBuf
,
1088 if (mSwitch
== FALSE
) {
1089 return EFI_IFR_RECORDINFO_IDX_INVALUD
;
1092 if ((pNew
= new SIfrRecord
) == NULL
) {
1093 return EFI_IFR_RECORDINFO_IDX_INVALUD
;
1096 if (mIfrRecordListHead
== NULL
) {
1097 mIfrRecordListHead
= pNew
;
1098 mIfrRecordListTail
= pNew
;
1100 mIfrRecordListTail
->mNext
= pNew
;
1101 mIfrRecordListTail
= pNew
;
1105 return mRecordCount
;
1109 CIfrRecordInfoDB::IfrRecordInfoUpdate (
1110 IN UINT32 RecordIdx
,
1120 if ((pNode
= GetRecordInfoFromIdx (RecordIdx
)) == NULL
) {
1126 // Line number is not specified explicitly, try to use line number of previous opcode
1128 Prev
= GetRecordInfoFromIdx (RecordIdx
- 1);
1130 LineNo
= Prev
->mLineNo
;
1134 pNode
->mLineNo
= LineNo
;
1135 pNode
->mOffset
= Offset
;
1136 pNode
->mBinBufLen
= BinBufLen
;
1137 pNode
->mIfrBinBuf
= BinBuf
;
1142 CIfrRecordInfoDB::IfrRecordOutput (
1143 OUT PACKAGE_DATA
&TBuffer
1149 if (TBuffer
.Buffer
!= NULL
) {
1150 delete TBuffer
.Buffer
;
1154 TBuffer
.Buffer
= NULL
;
1157 if (mSwitch
== FALSE
) {
1161 for (pNode
= mIfrRecordListHead
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
1162 TBuffer
.Size
+= pNode
->mBinBufLen
;
1165 if (TBuffer
.Size
!= 0) {
1166 TBuffer
.Buffer
= new CHAR8
[TBuffer
.Size
];
1171 Temp
= TBuffer
.Buffer
;
1173 for (pNode
= mIfrRecordListHead
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
1174 if (pNode
->mIfrBinBuf
!= NULL
) {
1175 memcpy (Temp
, pNode
->mIfrBinBuf
, pNode
->mBinBufLen
);
1176 Temp
+= pNode
->mBinBufLen
;
1184 CIfrRecordInfoDB::IfrRecordOutput (
1193 if (mSwitch
== FALSE
) {
1203 for (pNode
= mIfrRecordListHead
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
1204 if (pNode
->mLineNo
== LineNo
|| LineNo
== 0) {
1205 fprintf (File
, ">%08X: ", pNode
->mOffset
);
1206 TotalSize
+= pNode
->mBinBufLen
;
1207 if (pNode
->mIfrBinBuf
!= NULL
) {
1208 for (Index
= 0; Index
< pNode
->mBinBufLen
; Index
++) {
1209 fprintf (File
, "%02X ", (UINT8
)(pNode
->mIfrBinBuf
[Index
]));
1212 fprintf (File
, "\n");
1217 fprintf (File
, "\nTotal Size of all record is 0x%08X\n", TotalSize
);
1222 // for framework vfr file
1223 // adjust opcode sequence for uefi IFR format
1224 // adjust inconsistent and varstore into the right position.
1227 CIfrRecordInfoDB::CheckQuestionOpCode (
1232 case EFI_IFR_CHECKBOX_OP
:
1233 case EFI_IFR_NUMERIC_OP
:
1234 case EFI_IFR_PASSWORD_OP
:
1235 case EFI_IFR_ONE_OF_OP
:
1236 case EFI_IFR_ACTION_OP
:
1237 case EFI_IFR_STRING_OP
:
1238 case EFI_IFR_DATE_OP
:
1239 case EFI_IFR_TIME_OP
:
1240 case EFI_IFR_ORDERED_LIST_OP
:
1241 case EFI_IFR_REF_OP
:
1249 CIfrRecordInfoDB::CheckIdOpCode (
1254 case EFI_IFR_EQ_ID_VAL_OP
:
1255 case EFI_IFR_EQ_ID_ID_OP
:
1256 case EFI_IFR_EQ_ID_VAL_LIST_OP
:
1257 case EFI_IFR_QUESTION_REF1_OP
:
1265 CIfrRecordInfoDB::GetOpcodeQuestionId (
1266 IN EFI_IFR_OP_HEADER
*OpHead
1269 EFI_IFR_QUESTION_HEADER
*QuestionHead
;
1271 QuestionHead
= (EFI_IFR_QUESTION_HEADER
*) (OpHead
+ 1);
1273 return QuestionHead
->QuestionId
;
1277 CIfrRecordInfoDB::GetRecordInfoFromOffset (
1281 SIfrRecord
*pNode
= NULL
;
1283 for (pNode
= mIfrRecordListHead
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
1284 if (pNode
->mOffset
== Offset
) {
1293 Add just the op code position.
1295 Case1 (CreateOpcodeAfterParsingVfr == FALSE): The dynamic opcodes were created before the formset opcode,
1296 so pDynamicOpcodeNodes is before mIfrRecordListTail.
1300 |mIfrRecordListHead + ...+ pAdjustNode + pDynamicOpcodeNodes + mIfrRecordListTail|
1304 |mIfrRecordListHead + ...+ pDynamicOpcodeNodes + pAdjustNode + mIfrRecordListTail|
1306 Case2 (CreateOpcodeAfterParsingVfr == TRUE): The dynamic opcodes were created after paring the vfr file,
1307 so new records are appennded to the end of OriginalIfrRecordListTail.
1311 |mIfrRecordListHead + ...+ pAdjustNode + ... + OriginalIfrRecordListTail + pDynamicOpcodeNodes|
1315 |mIfrRecordListHead + ...+ pDynamicOpcodeNodes + pAdjustNode + ... + OriginalIfrRecordListTail|
1318 @param CreateOpcodeAfterParsingVfr Whether create the dynamic opcode after parsing the VFR file.
1322 CIfrRecordInfoDB::IfrAdjustDynamicOpcodeInRecords (
1323 IN BOOLEAN CreateOpcodeAfterParsingVfr
1326 UINT32 OpcodeOffset
;
1327 SIfrRecord
*pNode
, *pPreNode
;
1328 SIfrRecord
*pAdjustNode
, *pNodeBeforeAdjust
;
1329 SIfrRecord
*pNodeBeforeDynamic
;
1333 pNodeBeforeDynamic
= NULL
;
1337 // Base on the gAdjustOpcodeOffset and gAdjustOpcodeLen to find the pAdjustNod, the node before pAdjustNode,
1338 // and the node before pDynamicOpcodeNode.
1340 for (pNode
= mIfrRecordListHead
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
1341 if (OpcodeOffset
== gAdjustOpcodeOffset
) {
1342 pAdjustNode
= pNode
;
1343 pNodeBeforeAdjust
= pPreNode
;
1344 } else if (OpcodeOffset
== gAdjustOpcodeOffset
+ gAdjustOpcodeLen
) {
1345 pNodeBeforeDynamic
= pPreNode
;
1347 if (pNode
->mNext
!= NULL
) {
1350 OpcodeOffset
+= pNode
->mBinBufLen
;
1354 // Check the nodes whether exist.
1356 if (pNodeBeforeDynamic
== NULL
|| pAdjustNode
== NULL
|| pNodeBeforeAdjust
== NULL
) {
1361 // Adjust the node. pPreNode save the Node before mIfrRecordListTail
1363 pNodeBeforeAdjust
->mNext
= pNodeBeforeDynamic
->mNext
;
1364 if (CreateOpcodeAfterParsingVfr
) {
1366 // mIfrRecordListTail is the end of pDynamicNode (Case2).
1368 mIfrRecordListTail
->mNext
= pAdjustNode
;
1369 mIfrRecordListTail
= pNodeBeforeDynamic
;
1370 mIfrRecordListTail
->mNext
= NULL
;
1373 //pPreNode is the end of pDynamicNode(Case1).
1375 pPreNode
->mNext
= pAdjustNode
;
1376 pNodeBeforeDynamic
->mNext
= mIfrRecordListTail
;
1383 Update the record info(the position in the record list, offset and mIfrBinBuf) for new created record.
1385 @param CreateOpcodeAfterParsingVfr Whether create the dynamic opcode after parsing the VFR file.
1389 CIfrRecordInfoDB::IfrUpdateRecordInfoForDynamicOpcode (
1390 IN BOOLEAN CreateOpcodeAfterParsingVfr
1393 SIfrRecord
*pRecord
;
1396 // Base on the original offset info to update the record list.
1398 if (!IfrAdjustDynamicOpcodeInRecords(CreateOpcodeAfterParsingVfr
)) {
1399 gCVfrErrorHandle
.PrintMsg (0, (CHAR8
*)"Error", (CHAR8
*)"Can not find the adjust offset in the record.");
1403 // Base on the opcode binary length to recalculate the offset for each opcode.
1405 IfrAdjustOffsetForRecord();
1408 // Base on the offset to find the binary address.
1410 pRecord
= GetRecordInfoFromOffset(gAdjustOpcodeOffset
);
1411 while (pRecord
!= NULL
) {
1412 pRecord
->mIfrBinBuf
= gCFormPkg
.GetBufAddrBaseOnOffset(pRecord
->mOffset
);
1413 pRecord
= pRecord
->mNext
;
1419 CIfrRecordInfoDB::IfrAdjustOffsetForRecord (
1423 UINT32 OpcodeOffset
;
1427 for (pNode
= mIfrRecordListHead
; pNode
!= NULL
; pNode
= pNode
->mNext
) {
1428 pNode
->mOffset
= OpcodeOffset
;
1429 OpcodeOffset
+= pNode
->mBinBufLen
;
1434 CIfrRecordInfoDB::IfrRecordAdjust (
1438 SIfrRecord
*pNode
, *preNode
;
1439 SIfrRecord
*uNode
, *tNode
;
1440 EFI_IFR_OP_HEADER
*OpHead
, *tOpHead
;
1441 EFI_QUESTION_ID QuestionId
;
1443 UINT32 QuestionScope
;
1444 CHAR8 ErrorMsg
[MAX_STRING_LEN
] = {0, };
1445 EFI_VFR_RETURN_CODE Status
;
1448 // Init local variable
1450 Status
= VFR_RETURN_SUCCESS
;
1451 pNode
= mIfrRecordListHead
;
1454 while (pNode
!= NULL
) {
1455 OpHead
= (EFI_IFR_OP_HEADER
*) pNode
->mIfrBinBuf
;
1458 // make sure the inconsistent opcode in question scope
1460 if (QuestionScope
> 0) {
1461 QuestionScope
+= OpHead
->Scope
;
1462 if (OpHead
->OpCode
== EFI_IFR_END_OP
) {
1467 if (CheckQuestionOpCode (OpHead
->OpCode
)) {
1471 // for the inconsistent opcode not in question scope, adjust it
1473 if (OpHead
->OpCode
== EFI_IFR_INCONSISTENT_IF_OP
&& QuestionScope
== 0) {
1475 // for inconsistent opcode not in question scope
1479 // Count inconsistent opcode Scope
1481 StackCount
= OpHead
->Scope
;
1482 QuestionId
= EFI_QUESTION_ID_INVALID
;
1484 while (tNode
!= NULL
&& StackCount
> 0) {
1485 tNode
= tNode
->mNext
;
1486 tOpHead
= (EFI_IFR_OP_HEADER
*) tNode
->mIfrBinBuf
;
1488 // Calculate Scope Number
1490 StackCount
+= tOpHead
->Scope
;
1491 if (tOpHead
->OpCode
== EFI_IFR_END_OP
) {
1495 // by IdEqual opcode to get QuestionId
1497 if (QuestionId
== EFI_QUESTION_ID_INVALID
&&
1498 CheckIdOpCode (tOpHead
->OpCode
)) {
1499 QuestionId
= *(EFI_QUESTION_ID
*) (tOpHead
+ 1);
1502 if (tNode
== NULL
|| QuestionId
== EFI_QUESTION_ID_INVALID
) {
1504 // report error; not found
1506 sprintf (ErrorMsg
, "Inconsistent OpCode Record list invalid QuestionId is 0x%X", QuestionId
);
1507 gCVfrErrorHandle
.PrintMsg (0, NULL
, "Error", ErrorMsg
);
1508 Status
= VFR_RETURN_MISMATCHED
;
1512 // extract inconsistent opcode list
1513 // pNode is Incosistent opcode, tNode is End Opcode
1517 // insert inconsistent opcode list into the right question scope by questionid
1519 for (uNode
= mIfrRecordListHead
; uNode
!= NULL
; uNode
= uNode
->mNext
) {
1520 tOpHead
= (EFI_IFR_OP_HEADER
*) uNode
->mIfrBinBuf
;
1521 if (CheckQuestionOpCode (tOpHead
->OpCode
) &&
1522 (QuestionId
== GetOpcodeQuestionId (tOpHead
))) {
1527 // insert inconsistent opcode list and check LATE_CHECK flag
1529 if (uNode
!= NULL
) {
1530 if ((((EFI_IFR_QUESTION_HEADER
*)(tOpHead
+ 1))->Flags
& 0x20) != 0) {
1532 // if LATE_CHECK flag is set, change inconsistent to nosumbit
1534 OpHead
->OpCode
= EFI_IFR_NO_SUBMIT_IF_OP
;
1538 // skip the default storage for Date and Time
1540 if ((uNode
->mNext
!= NULL
) && (*uNode
->mNext
->mIfrBinBuf
== EFI_IFR_DEFAULT_OP
)) {
1541 uNode
= uNode
->mNext
;
1544 preNode
->mNext
= tNode
->mNext
;
1545 tNode
->mNext
= uNode
->mNext
;
1546 uNode
->mNext
= pNode
;
1548 // reset pNode to head list, scan the whole list again.
1550 pNode
= mIfrRecordListHead
;
1556 // not found matched question id, report error
1558 sprintf (ErrorMsg
, "QuestionId required by Inconsistent OpCode is not found. QuestionId is 0x%X", QuestionId
);
1559 gCVfrErrorHandle
.PrintMsg (0, NULL
, "Error", ErrorMsg
);
1560 Status
= VFR_RETURN_MISMATCHED
;
1563 } else if (OpHead
->OpCode
== EFI_IFR_VARSTORE_OP
||
1564 OpHead
->OpCode
== EFI_IFR_VARSTORE_EFI_OP
) {
1566 // for new added group of varstore opcode
1569 while (tNode
->mNext
!= NULL
) {
1570 tOpHead
= (EFI_IFR_OP_HEADER
*) tNode
->mNext
->mIfrBinBuf
;
1571 if (tOpHead
->OpCode
!= EFI_IFR_VARSTORE_OP
&&
1572 tOpHead
->OpCode
!= EFI_IFR_VARSTORE_EFI_OP
) {
1575 tNode
= tNode
->mNext
;
1578 if (tNode
->mNext
== NULL
) {
1580 // invalid IfrCode, IfrCode end by EndOpCode
1582 gCVfrErrorHandle
.PrintMsg (0, NULL
, "Error", "No found End Opcode in the end");
1583 Status
= VFR_RETURN_MISMATCHED
;
1587 if (tOpHead
->OpCode
!= EFI_IFR_END_OP
) {
1589 // not new added varstore, which are not needed to be adjust.
1592 pNode
= tNode
->mNext
;
1596 // move new added varstore opcode to the position befor form opcode
1597 // varstore opcode between pNode and tNode
1601 // search form opcode from begin
1603 for (uNode
= mIfrRecordListHead
; uNode
->mNext
!= NULL
; uNode
= uNode
->mNext
) {
1604 tOpHead
= (EFI_IFR_OP_HEADER
*) uNode
->mNext
->mIfrBinBuf
;
1605 if (tOpHead
->OpCode
== EFI_IFR_FORM_OP
) {
1610 // Insert varstore opcode beform form opcode if form opcode is found
1612 if (uNode
->mNext
!= NULL
) {
1613 preNode
->mNext
= tNode
->mNext
;
1614 tNode
->mNext
= uNode
->mNext
;
1615 uNode
->mNext
= pNode
;
1617 // reset pNode to head list, scan the whole list again.
1619 pNode
= mIfrRecordListHead
;
1625 // not found form, continue scan IfrRecord list
1628 pNode
= tNode
->mNext
;
1637 pNode
= pNode
->mNext
;
1641 // Update Ifr Opcode Offset
1643 if (Status
== VFR_RETURN_SUCCESS
) {
1644 IfrAdjustOffsetForRecord ();
1650 When the Varstore of the question is EFI_VFR_VARSTORE_BUFFER and the default value is not
1651 given by expression, should save the default info for the Buffer VarStore.
1653 @param DefaultId The default id.
1654 @param pQuestionNode Point to the question opcode node.
1655 @param Value The default value.
1658 CIfrRecordInfoDB::IfrAddDefaultToBufferConfig (
1659 IN UINT16 DefaultId
,
1660 IN SIfrRecord
*pQuestionNode
,
1661 IN EFI_IFR_TYPE_VALUE Value
1664 CHAR8
*VarStoreName
= NULL
;
1665 EFI_VFR_VARSTORE_TYPE VarStoreType
= EFI_VFR_VARSTORE_INVALID
;
1666 EFI_GUID
*VarGuid
= NULL
;
1667 EFI_VARSTORE_INFO VarInfo
;
1668 EFI_IFR_QUESTION_HEADER
*QuestionHead
;
1669 EFI_IFR_OP_HEADER
*pQuestionOpHead
;
1671 pQuestionOpHead
= (EFI_IFR_OP_HEADER
*) pQuestionNode
->mIfrBinBuf
;
1672 QuestionHead
= (EFI_IFR_QUESTION_HEADER
*) (pQuestionOpHead
+ 1);
1675 // Get the Var Store name and type.
1677 gCVfrDataStorage
.GetVarStoreName (QuestionHead
->VarStoreId
, &VarStoreName
);
1678 VarGuid
= gCVfrDataStorage
.GetVarStoreGuid (QuestionHead
->VarStoreId
);
1679 VarStoreType
= gCVfrDataStorage
.GetVarStoreType (QuestionHead
->VarStoreId
);
1682 // Only for Buffer storage need to save the default info in the storage.
1683 // Other type storage, just return.
1685 if (VarStoreType
!= EFI_VFR_VARSTORE_BUFFER
) {
1688 VarInfo
.mInfo
.mVarOffset
= QuestionHead
->VarStoreInfo
.VarOffset
;
1689 VarInfo
.mVarStoreId
= QuestionHead
->VarStoreId
;
1693 // Get the buffer storage info about this question.
1695 gCVfrDataStorage
.GetBufferVarStoreFieldInfo (&VarInfo
);
1700 gCVfrDefaultStore
.BufferVarStoreAltConfigAdd (
1711 Record the number and default id of all defaultstore opcode.
1715 CIfrRecordInfoDB::IfrGetDefaultStoreInfo (
1720 EFI_IFR_OP_HEADER
*pOpHead
;
1721 EFI_IFR_DEFAULTSTORE
*DefaultStore
;
1723 pNode
= mIfrRecordListHead
;
1724 mAllDefaultTypeCount
= 0;
1726 while (pNode
!= NULL
) {
1727 pOpHead
= (EFI_IFR_OP_HEADER
*) pNode
->mIfrBinBuf
;
1729 if (pOpHead
->OpCode
== EFI_IFR_DEFAULTSTORE_OP
){
1730 DefaultStore
= (EFI_IFR_DEFAULTSTORE
*) pNode
->mIfrBinBuf
;
1731 mAllDefaultIdArray
[mAllDefaultTypeCount
++] = DefaultStore
->DefaultId
;
1733 pNode
= pNode
->mNext
;
1738 Create new default opcode record.
1740 @param Size The new default opcode size.
1741 @param DefaultId The new default id.
1742 @param Type The new default type.
1743 @param LineNo The line number of the new record.
1744 @param Value The new default value.
1748 CIfrRecordInfoDB::IfrCreateDefaultRecord(
1750 IN UINT16 DefaultId
,
1753 IN EFI_IFR_TYPE_VALUE Value
1757 CIfrDefault2
*DObj2
;
1762 if (Type
== EFI_IFR_TYPE_OTHER
) {
1763 DObj2
= new CIfrDefault2 (Size
);
1764 DObj2
->SetDefaultId(DefaultId
);
1765 DObj2
->SetType(Type
);
1766 DObj2
->SetLineNo(LineNo
);
1767 DObj2
->SetScope (1);
1770 DObj
= new CIfrDefault (Size
);
1771 DObj
->SetDefaultId(DefaultId
);
1772 DObj
->SetType(Type
);
1773 DObj
->SetLineNo(LineNo
);
1774 DObj
->SetValue (Value
);
1780 Create new default opcode for question base on the QuestionDefaultInfo.
1782 @param pQuestionNode Point to the question opcode Node.
1783 @param QuestionDefaultInfo Point to the QuestionDefaultInfo for current question.
1787 CIfrRecordInfoDB::IfrCreateDefaultForQuestion (
1788 IN SIfrRecord
*pQuestionNode
,
1789 IN QuestionDefaultRecord
*QuestionDefaultInfo
1792 EFI_IFR_OP_HEADER
*pOpHead
;
1793 EFI_IFR_DEFAULT
*Default
;
1796 SIfrRecord
*pDefaultNode
;
1803 EFI_IFR_ONE_OF_OPTION
*DefaultOptionOpcode
;
1804 EFI_IFR_TYPE_VALUE CheckBoxDefaultValue
;
1806 CheckBoxDefaultValue
.b
= 1;
1807 pOpHead
= (EFI_IFR_OP_HEADER
*) pQuestionNode
->mIfrBinBuf
;
1813 // Record the offset of node which need to be adjust, will move the new created default opcode to this offset.
1815 gAdjustOpcodeOffset
= pQuestionNode
->mNext
->mOffset
;
1818 // For oneof, the default with smallest default id is given by the option flag.
1819 // So create the missing defaults base on the oneof option value(mDefaultValueRecord).
1821 if (pOpHead
->OpCode
== EFI_IFR_ONE_OF_OP
&& !QuestionDefaultInfo
->mIsDefaultOpcode
) {
1822 DefaultOptionOpcode
= (EFI_IFR_ONE_OF_OPTION
*)QuestionDefaultInfo
->mDefaultValueRecord
->mIfrBinBuf
;
1823 DefaultSize
= QuestionDefaultInfo
->mDefaultValueRecord
->mBinBufLen
- OFFSET_OF (EFI_IFR_ONE_OF_OPTION
, Value
);
1824 DefaultSize
+= OFFSET_OF (EFI_IFR_DEFAULT
, Value
);
1825 for (UINT8 i
= 0; i
< mAllDefaultTypeCount
; i
++) {
1826 if (!QuestionDefaultInfo
->mIsDefaultIdExist
[i
]) {
1827 IfrCreateDefaultRecord (DefaultSize
, mAllDefaultIdArray
[i
], DefaultOptionOpcode
->Type
, pQuestionNode
->mLineNo
, DefaultOptionOpcode
->Value
);
1829 // Save the new created default in the buffer storage.
1831 IfrAddDefaultToBufferConfig (mAllDefaultIdArray
[i
], pQuestionNode
, DefaultOptionOpcode
->Value
);
1839 // For checkbox, the default with smallest default id is given by the question flag.
1840 // And create the missing defaults with true value.
1842 if (pOpHead
-> OpCode
== EFI_IFR_CHECKBOX_OP
&& !QuestionDefaultInfo
->mIsDefaultOpcode
) {
1843 DefaultSize
= OFFSET_OF (EFI_IFR_DEFAULT
, Value
) + sizeof (BOOLEAN
);
1844 for (UINT8 i
= 0; i
< mAllDefaultTypeCount
; i
++) {
1845 if (!QuestionDefaultInfo
->mIsDefaultIdExist
[i
]) {
1846 IfrCreateDefaultRecord (DefaultSize
, mAllDefaultIdArray
[i
], EFI_IFR_TYPE_BOOLEAN
, pQuestionNode
->mLineNo
, CheckBoxDefaultValue
);
1848 // Save the new created default.
1850 IfrAddDefaultToBufferConfig (mAllDefaultIdArray
[i
], pQuestionNode
, CheckBoxDefaultValue
);
1858 // The default with smallest default id is given by the default opcode.
1859 // So create the missing defaults base on the value in the default opcode.
1863 // pDefaultNode point to the mDefaultValueRecord in QuestionDefaultInfo.
1865 pDefaultNode
= QuestionDefaultInfo
->mDefaultValueRecord
;
1866 Default
= (EFI_IFR_DEFAULT
*)pDefaultNode
->mIfrBinBuf
;
1868 // Record the offset of node which need to be adjust, will move the new created default opcode to this offset.
1870 gAdjustOpcodeOffset
= pDefaultNode
->mNext
->mOffset
;
1872 if (Default
->Type
== EFI_IFR_TYPE_OTHER
) {
1874 // EFI_IFR_DEFAULT_2 opcode.
1876 // Point to the first expression opcode.
1878 pSNode
= pDefaultNode
->mNext
;
1882 // Get opcode number behind the EFI_IFR_DEFAULT_2 until reach its END opcode (including the END opcode of EFI_IFR_DEFAULT_2)
1884 while (pSNode
!= NULL
&& pSNode
->mNext
!= NULL
&& ScopeCount
!= 0) {
1885 pOpHead
= (EFI_IFR_OP_HEADER
*) pSNode
->mIfrBinBuf
;
1886 if (pOpHead
->Scope
== 1) {
1889 if (pOpHead
->OpCode
== EFI_IFR_END_OP
) {
1893 pSNode
= pSNode
->mNext
;
1901 // Record the offset of node which need to be adjust, will move the new created default opcode to this offset.
1903 gAdjustOpcodeOffset
= pSNode
->mOffset
;
1905 // Create new default opcode node for missing default.
1907 for (UINT8 i
= 0; i
< mAllDefaultTypeCount
; i
++) {
1908 OpcodeNumber
= OpcodeCount
;
1909 if (!QuestionDefaultInfo
->mIsDefaultIdExist
[i
]) {
1910 IfrCreateDefaultRecord (Default
->Header
.Length
, mAllDefaultIdArray
[i
], Default
->Type
, pENode
->mLineNo
, Default
->Value
);
1912 // Point to the first expression opcode node.
1914 pSNode
= pDefaultNode
->mNext
;
1916 // Create the expression opcode and end opcode for the new created EFI_IFR_DEFAULT_2 opcode.
1918 while (pSNode
!= NULL
&& pSNode
->mNext
!= NULL
&& OpcodeNumber
-- != 0) {
1919 pOpHead
= (EFI_IFR_OP_HEADER
*) pSNode
->mIfrBinBuf
;
1920 Obj
= new CIfrObj (pOpHead
->OpCode
, NULL
, pSNode
->mBinBufLen
, FALSE
);
1921 assert (Obj
!= NULL
);
1922 Obj
->SetLineNo (pSNode
->mLineNo
);
1923 ObjBinBuf
= Obj
->GetObjBinAddr();
1924 memcpy (ObjBinBuf
, pSNode
->mIfrBinBuf
, (UINTN
)pSNode
->mBinBufLen
);
1926 pSNode
= pSNode
->mNext
;
1932 // EFI_IFR_DEFAULT opcode.
1934 // Create new default opcode node for missing default.
1936 for (UINT8 i
= 0; i
< mAllDefaultTypeCount
; i
++) {
1937 if (!QuestionDefaultInfo
->mIsDefaultIdExist
[i
]) {
1938 IfrCreateDefaultRecord (Default
->Header
.Length
, mAllDefaultIdArray
[i
], Default
->Type
, pDefaultNode
->mLineNo
, Default
->Value
);
1940 // Save the new created default in the buffer storage..
1942 IfrAddDefaultToBufferConfig (mAllDefaultIdArray
[i
], pQuestionNode
, Default
->Value
);
1949 Parse the default information in a question, get the QuestionDefaultInfo.
1951 @param pQuestionNode Point to the question record Node.
1952 @param QuestionDefaultInfo On return, point to the QuestionDefaultInfo.
1955 CIfrRecordInfoDB::IfrParseDefaulInfoInQuestion(
1956 IN SIfrRecord
*pQuestionNode
,
1957 OUT QuestionDefaultRecord
*QuestionDefaultInfo
1961 EFI_IFR_ONE_OF_OPTION
*OneofOptionOpcode
;
1962 EFI_IFR_OP_HEADER
*pSOpHead
;
1963 EFI_IFR_CHECKBOX
*CheckBoxOpcode
;
1964 EFI_IFR_DEFAULT
*DefaultOpcode
;
1965 BOOLEAN IsOneOfOpcode
;
1966 UINT16 SmallestDefaultId
;
1969 SmallestDefaultId
= 0xffff;
1970 IsOneOfOpcode
= FALSE
;
1972 pSNode
= pQuestionNode
;
1975 // Parse all the opcodes in the Question.
1977 while (pSNode
!= NULL
) {
1978 pSOpHead
= (EFI_IFR_OP_HEADER
*) pSNode
->mIfrBinBuf
;
1980 // For a question, its scope bit must be set, the scope exists until it reaches a corresponding EFI_IFR_END_OP.
1981 // Scopes may be nested within other scopes.
1982 // When finishing parsing a question, the scope count must be zero.
1984 if (pSOpHead
->Scope
== 1) {
1987 if (pSOpHead
->OpCode
== EFI_IFR_END_OP
) {
1991 // Check whether finishing parsing a question.
1993 if (ScopeCount
== 0) {
1998 // Record the default information in the question.
2000 switch (pSOpHead
->OpCode
) {
2001 case EFI_IFR_ONE_OF_OP
:
2002 IsOneOfOpcode
= TRUE
;
2004 case EFI_IFR_CHECKBOX_OP
:
2006 // The default info of check box may be given by flag.
2007 // So need to check the flag of check box.
2009 CheckBoxOpcode
= (EFI_IFR_CHECKBOX
*)pSNode
->mIfrBinBuf
;
2010 if ((CheckBoxOpcode
->Flags
& EFI_IFR_CHECKBOX_DEFAULT
) != 0) {
2012 // Check whether need to update the smallest default id.
2014 if (SmallestDefaultId
> EFI_HII_DEFAULT_CLASS_STANDARD
) {
2015 SmallestDefaultId
= EFI_HII_DEFAULT_CLASS_STANDARD
;
2018 // Update the QuestionDefaultInfo.
2020 for (UINT8 i
= 0; i
< mAllDefaultTypeCount
; i
++) {
2021 if (mAllDefaultIdArray
[i
] == EFI_HII_DEFAULT_CLASS_STANDARD
) {
2022 if (!QuestionDefaultInfo
->mIsDefaultIdExist
[i
]) {
2023 QuestionDefaultInfo
->mDefaultNumber
++;
2024 QuestionDefaultInfo
->mIsDefaultIdExist
[i
] = TRUE
;
2030 if ((CheckBoxOpcode
->Flags
& EFI_IFR_CHECKBOX_DEFAULT_MFG
) != 0) {
2032 // Check whether need to update the smallest default id.
2034 if (SmallestDefaultId
> EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
2035 SmallestDefaultId
= EFI_HII_DEFAULT_CLASS_MANUFACTURING
;
2038 // Update the QuestionDefaultInfo.
2040 for (UINT8 i
= 0; i
< mAllDefaultTypeCount
; i
++) {
2041 if (mAllDefaultIdArray
[i
] == EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
2042 if (!QuestionDefaultInfo
->mIsDefaultIdExist
[i
]) {
2043 QuestionDefaultInfo
->mDefaultNumber
++;
2044 QuestionDefaultInfo
->mIsDefaultIdExist
[i
] = TRUE
;
2051 case EFI_IFR_ONE_OF_OPTION_OP
:
2052 if (!IsOneOfOpcode
) {
2054 // Only check the option in oneof.
2058 OneofOptionOpcode
= (EFI_IFR_ONE_OF_OPTION
*)pSNode
->mIfrBinBuf
;
2059 if ((OneofOptionOpcode
->Flags
& EFI_IFR_OPTION_DEFAULT
) != 0) {
2061 // The option is used as the standard default.
2062 // Check whether need to update the smallest default id and QuestionDefaultInfo.
2064 if (SmallestDefaultId
> EFI_HII_DEFAULT_CLASS_STANDARD
) {
2065 SmallestDefaultId
= EFI_HII_DEFAULT_CLASS_STANDARD
;
2066 QuestionDefaultInfo
->mDefaultValueRecord
= pSNode
;
2069 // Update the IsDefaultIdExist array in QuestionDefaultInfo.
2071 for (UINT8 i
= 0; i
< mAllDefaultTypeCount
; i
++) {
2072 if (mAllDefaultIdArray
[i
] == EFI_HII_DEFAULT_CLASS_STANDARD
) {
2073 if (!QuestionDefaultInfo
->mIsDefaultIdExist
[i
]) {
2074 QuestionDefaultInfo
->mDefaultNumber
++;
2075 QuestionDefaultInfo
->mIsDefaultIdExist
[i
] = TRUE
;
2081 if ((OneofOptionOpcode
->Flags
& EFI_IFR_OPTION_DEFAULT_MFG
) != 0) {
2083 // This option is used as the manufacture default.
2084 // Check whether need to update the smallest default id and QuestionDefaultInfo.
2086 if (SmallestDefaultId
> EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
2087 SmallestDefaultId
= EFI_HII_DEFAULT_CLASS_MANUFACTURING
;
2088 QuestionDefaultInfo
->mDefaultValueRecord
= pSNode
;
2091 // Update the QuestionDefaultInfo.
2093 for (UINT8 i
= 0; i
< mAllDefaultTypeCount
; i
++) {
2094 if (mAllDefaultIdArray
[i
] == EFI_HII_DEFAULT_CLASS_MANUFACTURING
) {
2095 if (!QuestionDefaultInfo
->mIsDefaultIdExist
[i
]) {
2096 QuestionDefaultInfo
->mDefaultNumber
++;
2097 QuestionDefaultInfo
->mIsDefaultIdExist
[i
] = TRUE
;
2104 case EFI_IFR_DEFAULT_OP
:
2105 DefaultOpcode
= (EFI_IFR_DEFAULT
*) pSNode
->mIfrBinBuf
;
2107 // Check whether need to update the smallest default id and QuestionDefaultInfo.
2109 if (SmallestDefaultId
>= DefaultOpcode
->DefaultId
) {
2110 SmallestDefaultId
= DefaultOpcode
->DefaultId
;
2111 QuestionDefaultInfo
->mDefaultValueRecord
= pSNode
;
2112 QuestionDefaultInfo
->mIsDefaultOpcode
= TRUE
;
2115 // Update the QuestionDefaultInfo.
2117 for (UINT8 i
= 0; i
< mAllDefaultTypeCount
; i
++){
2118 if (mAllDefaultIdArray
[i
] == ((EFI_IFR_DEFAULT
*)pSNode
->mIfrBinBuf
)->DefaultId
) {
2119 if (!QuestionDefaultInfo
->mIsDefaultIdExist
[i
]) {
2120 QuestionDefaultInfo
->mDefaultNumber
++;
2121 QuestionDefaultInfo
->mIsDefaultIdExist
[i
] = TRUE
;
2131 // Parse next opcode in this question.
2133 pSNode
= pSNode
->mNext
;
2138 Check or add default for question if need.
2140 This function will check the default info for question.
2141 If the question has default, but the default number < defaultstore opcode number.
2142 will do following two action :
2144 1. if (AutoDefault) will add default for question to support all kinds of defaults.
2145 2. if (CheckDefault) will generate an error to tell user the question misses some default value.
2147 We assume that the two options can not be TRUE at same time.
2148 If they are TRUE at same time, only do the action corresponding to AutoDefault option.
2150 @param AutoDefault Add default for question if needed
2151 @param CheckDefault Check the default info, if missing default, generates an error.
2155 CIfrRecordInfoDB::IfrCheckAddDefaultRecord (
2156 BOOLEAN AutoDefault
,
2157 BOOLEAN CheckDefault
2161 SIfrRecord
*pTailNode
;
2162 SIfrRecord
*pStartAdjustNode
;
2163 EFI_IFR_OP_HEADER
*pOpHead
;
2164 QuestionDefaultRecord QuestionDefaultInfo
;
2165 UINT8 MissingDefaultCount
;
2166 CHAR8 Msg
[MAX_STRING_LEN
] = {0, };
2168 pNode
= mIfrRecordListHead
;
2171 // Record the number and default id of all defaultstore opcode.
2173 IfrGetDefaultStoreInfo ();
2175 while (pNode
!= NULL
) {
2176 pOpHead
= (EFI_IFR_OP_HEADER
*) pNode
->mIfrBinBuf
;
2178 // Check whether is question opcode.
2180 if (CheckQuestionOpCode (pOpHead
->OpCode
)) {
2182 // Initialize some local variables here, because they vary with question.
2183 // Record the mIfrRecordListTail for each question, because may create default node for question after mIfrRecordListTail.
2185 memset (&QuestionDefaultInfo
, 0, sizeof (QuestionDefaultRecord
));
2186 pTailNode
= mIfrRecordListTail
;
2188 // Get the QuestionDefaultInfo for current question.
2190 IfrParseDefaulInfoInQuestion (pNode
, &QuestionDefaultInfo
);
2192 if (QuestionDefaultInfo
.mDefaultNumber
!= mAllDefaultTypeCount
&& QuestionDefaultInfo
.mDefaultNumber
!= 0) {
2195 // Create default for question which misses default.
2197 IfrCreateDefaultForQuestion (pNode
, &QuestionDefaultInfo
);
2200 // Adjust the buffer content.
2201 // pStartAdjustNode->mIfrBinBuf points to the insert position.
2202 // pTailNode->mNext->mIfrBinBuf points to the inset opcodes.
2204 pStartAdjustNode
=GetRecordInfoFromOffset (gAdjustOpcodeOffset
);
2205 gCFormPkg
.AdjustDynamicInsertOpcode (pStartAdjustNode
->mIfrBinBuf
, pTailNode
->mNext
->mIfrBinBuf
, TRUE
);
2208 // Update the record info.
2210 IfrUpdateRecordInfoForDynamicOpcode (TRUE
);
2211 } else if (CheckDefault
) {
2213 // Generate an error for question which misses default.
2215 MissingDefaultCount
= mAllDefaultTypeCount
- QuestionDefaultInfo
.mDefaultNumber
;
2216 sprintf (Msg
, "The question misses %d default, the question's opcode is %d", MissingDefaultCount
, pOpHead
->OpCode
);
2217 gCVfrErrorHandle
.PrintMsg (pNode
->mLineNo
, NULL
, "Error", Msg
);
2222 // parse next opcode.
2224 pNode
= pNode
->mNext
;
2228 CIfrRecordInfoDB gCIfrRecordInfoDB
;
2231 CIfrObj::_EMIT_PENDING_OBJ (
2235 CHAR8
*ObjBinBuf
= NULL
;
2240 if (!mDelayEmit
|| !gCreateOp
) {
2244 mPkgOffset
= gCFormPkg
.GetPkgLength ();
2246 // update data buffer to package data
2248 ObjBinBuf
= gCFormPkg
.IfrBinBufferGet (mObjBinLen
);
2249 if (ObjBinBuf
!= NULL
) {
2250 memmove (ObjBinBuf
, mObjBinBuf
, mObjBinLen
);
2254 // update bin buffer to package data buffer
2256 if (mObjBinBuf
!= NULL
) {
2258 mObjBinBuf
= ObjBinBuf
;
2265 * The definition of CIfrObj's member function
2270 } gOpcodeSizesScopeTable
[] = {
2271 { 0, 0 }, // EFI_IFR_INVALID - 0x00
2272 { sizeof (EFI_IFR_FORM
), 1 }, // EFI_IFR_FORM_OP
2273 { sizeof (EFI_IFR_SUBTITLE
), 1 }, // EFI_IFR_SUBTITLE_OP
2274 { sizeof (EFI_IFR_TEXT
), 0 }, // EFI_IFR_TEXT_OP
2275 { sizeof (EFI_IFR_IMAGE
), 0 }, // EFI_IFR_IMAGE_OP
2276 { sizeof (EFI_IFR_ONE_OF
), 1 }, // EFI_IFR_ONE_OF_OP - 0x05
2277 { sizeof (EFI_IFR_CHECKBOX
), 1}, // EFI_IFR_CHECKBOX_OP
2278 { sizeof (EFI_IFR_NUMERIC
), 1 }, // EFI_IFR_NUMERIC_OP
2279 { sizeof (EFI_IFR_PASSWORD
), 1 }, // EFI_IFR_PASSWORD_OP
2280 { sizeof (EFI_IFR_ONE_OF_OPTION
), 0 }, // EFI_IFR_ONE_OF_OPTION_OP
2281 { sizeof (EFI_IFR_SUPPRESS_IF
), 1 }, // EFI_IFR_SUPPRESS_IF - 0x0A
2282 { sizeof (EFI_IFR_LOCKED
), 0 }, // EFI_IFR_LOCKED_OP
2283 { sizeof (EFI_IFR_ACTION
), 1 }, // EFI_IFR_ACTION_OP
2284 { sizeof (EFI_IFR_RESET_BUTTON
), 1 }, // EFI_IFR_RESET_BUTTON_OP
2285 { sizeof (EFI_IFR_FORM_SET
), 1 }, // EFI_IFR_FORM_SET_OP -0xE
2286 { sizeof (EFI_IFR_REF
), 0 }, // EFI_IFR_REF_OP
2287 { sizeof (EFI_IFR_NO_SUBMIT_IF
), 1}, // EFI_IFR_NO_SUBMIT_IF_OP -0x10
2288 { sizeof (EFI_IFR_INCONSISTENT_IF
), 1 }, // EFI_IFR_INCONSISTENT_IF_OP
2289 { sizeof (EFI_IFR_EQ_ID_VAL
), 0 }, // EFI_IFR_EQ_ID_VAL_OP
2290 { sizeof (EFI_IFR_EQ_ID_ID
), 0 }, // EFI_IFR_EQ_ID_ID_OP
2291 { sizeof (EFI_IFR_EQ_ID_VAL_LIST
), 0 }, // EFI_IFR_EQ_ID_LIST_OP - 0x14
2292 { sizeof (EFI_IFR_AND
), 0 }, // EFI_IFR_AND_OP
2293 { sizeof (EFI_IFR_OR
), 0 }, // EFI_IFR_OR_OP
2294 { sizeof (EFI_IFR_NOT
), 0 }, // EFI_IFR_NOT_OP
2295 { sizeof (EFI_IFR_RULE
), 1 }, // EFI_IFR_RULE_OP
2296 { sizeof (EFI_IFR_GRAY_OUT_IF
), 1 }, // EFI_IFR_GRAYOUT_IF_OP - 0x19
2297 { sizeof (EFI_IFR_DATE
), 1 }, // EFI_IFR_DATE_OP
2298 { sizeof (EFI_IFR_TIME
), 1 }, // EFI_IFR_TIME_OP
2299 { sizeof (EFI_IFR_STRING
), 1 }, // EFI_IFR_STRING_OP
2300 { sizeof (EFI_IFR_REFRESH
), 0 }, // EFI_IFR_REFRESH_OP
2301 { sizeof (EFI_IFR_DISABLE_IF
), 1 }, // EFI_IFR_DISABLE_IF_OP - 0x1E
2303 { sizeof (EFI_IFR_TO_LOWER
), 0 }, // EFI_IFR_TO_LOWER_OP - 0x20
2304 { sizeof (EFI_IFR_TO_UPPER
), 0 }, // EFI_IFR_TO_UPPER_OP - 0x21
2305 { sizeof (EFI_IFR_MAP
), 1 }, // EFI_IFR_MAP - 0x22
2306 { sizeof (EFI_IFR_ORDERED_LIST
), 1 }, // EFI_IFR_ORDERED_LIST_OP - 0x23
2307 { sizeof (EFI_IFR_VARSTORE
), 0 }, // EFI_IFR_VARSTORE_OP
2308 { sizeof (EFI_IFR_VARSTORE_NAME_VALUE
), 0 }, // EFI_IFR_VARSTORE_NAME_VALUE_OP
2309 { sizeof (EFI_IFR_VARSTORE_EFI
), 0 }, // EFI_IFR_VARSTORE_EFI_OP
2310 { sizeof (EFI_IFR_VARSTORE_DEVICE
), 1 }, // EFI_IFR_VARSTORE_DEVICE_OP
2311 { sizeof (EFI_IFR_VERSION
), 0 }, // EFI_IFR_VERSION_OP - 0x28
2312 { sizeof (EFI_IFR_END
), 0 }, // EFI_IFR_END_OP
2313 { sizeof (EFI_IFR_MATCH
), 0 }, // EFI_IFR_MATCH_OP - 0x2A
2314 { sizeof (EFI_IFR_GET
), 0 }, // EFI_IFR_GET - 0x2B
2315 { sizeof (EFI_IFR_SET
), 0 }, // EFI_IFR_SET - 0x2C
2316 { sizeof (EFI_IFR_READ
), 0 }, // EFI_IFR_READ - 0x2D
2317 { sizeof (EFI_IFR_WRITE
), 0 }, // EFI_IFR_WRITE - 0x2E
2318 { sizeof (EFI_IFR_EQUAL
), 0 }, // EFI_IFR_EQUAL_OP - 0x2F
2319 { sizeof (EFI_IFR_NOT_EQUAL
), 0 }, // EFI_IFR_NOT_EQUAL_OP
2320 { sizeof (EFI_IFR_GREATER_THAN
), 0 }, // EFI_IFR_GREATER_THAN_OP
2321 { sizeof (EFI_IFR_GREATER_EQUAL
), 0 }, // EFI_IFR_GREATER_EQUAL_OP
2322 { sizeof (EFI_IFR_LESS_THAN
), 0 }, // EFI_IFR_LESS_THAN_OP
2323 { sizeof (EFI_IFR_LESS_EQUAL
), 0 }, // EFI_IFR_LESS_EQUAL_OP - 0x34
2324 { sizeof (EFI_IFR_BITWISE_AND
), 0 }, // EFI_IFR_BITWISE_AND_OP
2325 { sizeof (EFI_IFR_BITWISE_OR
), 0 }, // EFI_IFR_BITWISE_OR_OP
2326 { sizeof (EFI_IFR_BITWISE_NOT
), 0 }, // EFI_IFR_BITWISE_NOT_OP
2327 { sizeof (EFI_IFR_SHIFT_LEFT
), 0 }, // EFI_IFR_SHIFT_LEFT_OP
2328 { sizeof (EFI_IFR_SHIFT_RIGHT
), 0 }, // EFI_IFR_SHIFT_RIGHT_OP
2329 { sizeof (EFI_IFR_ADD
), 0 }, // EFI_IFR_ADD_OP - 0x3A
2330 { sizeof (EFI_IFR_SUBTRACT
), 0 }, // EFI_IFR_SUBTRACT_OP
2331 { sizeof (EFI_IFR_MULTIPLY
), 0 }, // EFI_IFR_MULTIPLY_OP
2332 { sizeof (EFI_IFR_DIVIDE
), 0 }, // EFI_IFR_DIVIDE_OP
2333 { sizeof (EFI_IFR_MODULO
), 0 }, // EFI_IFR_MODULO_OP - 0x3E
2334 { sizeof (EFI_IFR_RULE_REF
), 0 }, // EFI_IFR_RULE_REF_OP
2335 { sizeof (EFI_IFR_QUESTION_REF1
), 0 }, // EFI_IFR_QUESTION_REF1_OP
2336 { sizeof (EFI_IFR_QUESTION_REF2
), 0 }, // EFI_IFR_QUESTION_REF2_OP - 0x41
2337 { sizeof (EFI_IFR_UINT8
), 0}, // EFI_IFR_UINT8
2338 { sizeof (EFI_IFR_UINT16
), 0}, // EFI_IFR_UINT16
2339 { sizeof (EFI_IFR_UINT32
), 0}, // EFI_IFR_UINT32
2340 { sizeof (EFI_IFR_UINT64
), 0}, // EFI_IFR_UTNT64
2341 { sizeof (EFI_IFR_TRUE
), 0 }, // EFI_IFR_TRUE_OP - 0x46
2342 { sizeof (EFI_IFR_FALSE
), 0 }, // EFI_IFR_FALSE_OP
2343 { sizeof (EFI_IFR_TO_UINT
), 0 }, // EFI_IFR_TO_UINT_OP
2344 { sizeof (EFI_IFR_TO_STRING
), 0 }, // EFI_IFR_TO_STRING_OP
2345 { sizeof (EFI_IFR_TO_BOOLEAN
), 0 }, // EFI_IFR_TO_BOOLEAN_OP
2346 { sizeof (EFI_IFR_MID
), 0 }, // EFI_IFR_MID_OP
2347 { sizeof (EFI_IFR_FIND
), 0 }, // EFI_IFR_FIND_OP
2348 { sizeof (EFI_IFR_TOKEN
), 0 }, // EFI_IFR_TOKEN_OP
2349 { sizeof (EFI_IFR_STRING_REF1
), 0 }, // EFI_IFR_STRING_REF1_OP - 0x4E
2350 { sizeof (EFI_IFR_STRING_REF2
), 0 }, // EFI_IFR_STRING_REF2_OP
2351 { sizeof (EFI_IFR_CONDITIONAL
), 0 }, // EFI_IFR_CONDITIONAL_OP
2352 { sizeof (EFI_IFR_QUESTION_REF3
), 0 }, // EFI_IFR_QUESTION_REF3_OP
2353 { sizeof (EFI_IFR_ZERO
), 0 }, // EFI_IFR_ZERO_OP
2354 { sizeof (EFI_IFR_ONE
), 0 }, // EFI_IFR_ONE_OP
2355 { sizeof (EFI_IFR_ONES
), 0 }, // EFI_IFR_ONES_OP
2356 { sizeof (EFI_IFR_UNDEFINED
), 0 }, // EFI_IFR_UNDEFINED_OP
2357 { sizeof (EFI_IFR_LENGTH
), 0 }, // EFI_IFR_LENGTH_OP
2358 { sizeof (EFI_IFR_DUP
), 0 }, // EFI_IFR_DUP_OP - 0x57
2359 { sizeof (EFI_IFR_THIS
), 0 }, // EFI_IFR_THIS_OP
2360 { sizeof (EFI_IFR_SPAN
), 0 }, // EFI_IFR_SPAN_OP
2361 { sizeof (EFI_IFR_VALUE
), 1 }, // EFI_IFR_VALUE_OP
2362 { sizeof (EFI_IFR_DEFAULT
), 0 }, // EFI_IFR_DEFAULT_OP
2363 { sizeof (EFI_IFR_DEFAULTSTORE
), 0 }, // EFI_IFR_DEFAULTSTORE_OP - 0x5C
2364 { sizeof (EFI_IFR_FORM_MAP
), 1}, // EFI_IFR_FORM_MAP_OP - 0x5D
2365 { sizeof (EFI_IFR_CATENATE
), 0 }, // EFI_IFR_CATENATE_OP
2366 { sizeof (EFI_IFR_GUID
), 0 }, // EFI_IFR_GUID_OP
2367 { sizeof (EFI_IFR_SECURITY
), 0 }, // EFI_IFR_SECURITY_OP - 0x60
2368 { sizeof (EFI_IFR_MODAL_TAG
), 0}, // EFI_IFR_MODAL_TAG_OP - 0x61
2369 { sizeof (EFI_IFR_REFRESH_ID
), 0}, // EFI_IFR_REFRESH_ID_OP - 0x62
2370 { sizeof (EFI_IFR_WARNING_IF
), 1}, // EFI_IFR_WARNING_IF_OP - 0x63
2371 { sizeof (EFI_IFR_MATCH2
), 0 }, // EFI_IFR_MATCH2_OP - 0x64
2374 #ifdef CIFROBJ_DEUBG
2377 } gIfrObjPrintDebugTable
[] = {
2378 "EFI_IFR_INVALID", "EFI_IFR_FORM", "EFI_IFR_SUBTITLE", "EFI_IFR_TEXT", "EFI_IFR_IMAGE", "EFI_IFR_ONE_OF",
2379 "EFI_IFR_CHECKBOX", "EFI_IFR_NUMERIC", "EFI_IFR_PASSWORD", "EFI_IFR_ONE_OF_OPTION", "EFI_IFR_SUPPRESS_IF", "EFI_IFR_LOCKED",
2380 "EFI_IFR_ACTION", "EFI_IFR_RESET_BUTTON", "EFI_IFR_FORM_SET", "EFI_IFR_REF", "EFI_IFR_NO_SUBMIT_IF", "EFI_IFR_INCONSISTENT_IF",
2381 "EFI_IFR_EQ_ID_VAL", "EFI_IFR_EQ_ID_ID", "EFI_IFR_EQ_ID_LIST", "EFI_IFR_AND", "EFI_IFR_OR", "EFI_IFR_NOT",
2382 "EFI_IFR_RULE", "EFI_IFR_GRAY_OUT_IF", "EFI_IFR_DATE", "EFI_IFR_TIME", "EFI_IFR_STRING", "EFI_IFR_REFRESH",
2383 "EFI_IFR_DISABLE_IF", "EFI_IFR_INVALID", "EFI_IFR_TO_LOWER", "EFI_IFR_TO_UPPER", "EFI_IFR_MAP", "EFI_IFR_ORDERED_LIST",
2384 "EFI_IFR_VARSTORE", "EFI_IFR_VARSTORE_NAME_VALUE", "EFI_IFR_VARSTORE_EFI", "EFI_IFR_VARSTORE_DEVICE", "EFI_IFR_VERSION", "EFI_IFR_END",
2385 "EFI_IFR_MATCH", "EFI_IFR_GET", "EFI_IFR_SET", "EFI_IFR_READ", "EFI_IFR_WRITE", "EFI_IFR_EQUAL",
2386 "EFI_IFR_NOT_EQUAL", "EFI_IFR_GREATER_THAN", "EFI_IFR_GREATER_EQUAL", "EFI_IFR_LESS_THAN", "EFI_IFR_LESS_EQUAL", "EFI_IFR_BITWISE_AND",
2387 "EFI_IFR_BITWISE_OR", "EFI_IFR_BITWISE_NOT", "EFI_IFR_SHIFT_LEFT", "EFI_IFR_SHIFT_RIGHT", "EFI_IFR_ADD", "EFI_IFR_SUBTRACT",
2388 "EFI_IFR_MULTIPLY", "EFI_IFR_DIVIDE", "EFI_IFR_MODULO", "EFI_IFR_RULE_REF", "EFI_IFR_QUESTION_REF1", "EFI_IFR_QUESTION_REF2",
2389 "EFI_IFR_UINT8", "EFI_IFR_UINT16", "EFI_IFR_UINT32", "EFI_IFR_UINT64", "EFI_IFR_TRUE", "EFI_IFR_FALSE",
2390 "EFI_IFR_TO_UINT", "EFI_IFR_TO_STRING", "EFI_IFR_TO_BOOLEAN", "EFI_IFR_MID", "EFI_IFR_FIND", "EFI_IFR_TOKEN",
2391 "EFI_IFR_STRING_REF1","EFI_IFR_STRING_REF2", "EFI_IFR_CONDITIONAL", "EFI_IFR_QUESTION_REF3", "EFI_IFR_ZERO", "EFI_IFR_ONE",
2392 "EFI_IFR_ONES", "EFI_IFR_UNDEFINED", "EFI_IFR_LENGTH", "EFI_IFR_DUP", "EFI_IFR_THIS", "EFI_IFR_SPAN",
2393 "EFI_IFR_VALUE", "EFI_IFR_DEFAULT", "EFI_IFR_DEFAULTSTORE", "EFI_IFR_FORM_MAP", "EFI_IFR_CATENATE", "EFI_IFR_GUID",
2394 "EFI_IFR_SECURITY", "EFI_IFR_MODAL_TAG", "EFI_IFR_REFRESH_ID", "EFI_IFR_WARNING_IF", "EFI_IFR_MATCH2",
2398 CIFROBJ_DEBUG_PRINT (
2402 printf ("======Create IFR [%s]\n", gIfrObjPrintDebugTable
[OpCode
].mIfrName
);
2406 #define CIFROBJ_DEBUG_PRINT(OpCode)
2410 BOOLEAN gCreateOp
= TRUE
;
2416 IN BOOLEAN DelayEmit
2419 mDelayEmit
= DelayEmit
;
2420 mPkgOffset
= gCFormPkg
.GetPkgLength ();
2421 mObjBinLen
= (ObjBinLen
== 0) ? gOpcodeSizesScopeTable
[OpCode
].mSize
: ObjBinLen
;
2422 mObjBinBuf
= ((DelayEmit
== FALSE
) && (gCreateOp
== TRUE
)) ? gCFormPkg
.IfrBinBufferGet (mObjBinLen
) : new CHAR8
[EFI_IFR_MAX_LENGTH
];
2423 mRecordIdx
= (gCreateOp
== TRUE
) ? gCIfrRecordInfoDB
.IfrRecordRegister (0xFFFFFFFF, mObjBinBuf
, mObjBinLen
, mPkgOffset
) : EFI_IFR_RECORDINFO_IDX_INVALUD
;
2425 assert (mObjBinBuf
!= NULL
);
2427 if (IfrObj
!= NULL
) {
2428 *IfrObj
= mObjBinBuf
;
2431 CIFROBJ_DEBUG_PRINT (OpCode
);
2438 if ((mDelayEmit
== TRUE
) && ((gCreateOp
== TRUE
))) {
2439 _EMIT_PENDING_OBJ ();
2442 gCIfrRecordInfoDB
.IfrRecordInfoUpdate (mRecordIdx
, mLineNo
, mObjBinBuf
, mObjBinLen
, mPkgOffset
);
2446 * The definition of CIfrObj's member function
2448 UINT8 gScopeCount
= 0;
2450 CIfrOpHeader::CIfrOpHeader (
2454 ) : mHeader ((EFI_IFR_OP_HEADER
*)StartAddr
)
2456 mHeader
->OpCode
= OpCode
;
2457 mHeader
->Length
= (Length
== 0) ? gOpcodeSizesScopeTable
[OpCode
].mSize
: Length
;
2458 mHeader
->Scope
= (gOpcodeSizesScopeTable
[OpCode
].mScope
+ gScopeCount
> 0) ? 1 : 0;
2461 CIfrOpHeader::CIfrOpHeader (
2462 IN CIfrOpHeader
&OpHdr
2465 mHeader
= OpHdr
.mHeader
;
2468 UINT32
CIfrFormId::FormIdBitMap
[EFI_FREE_FORM_ID_BITMAP_SIZE
] = {0, };