BaseTool/VfrCompile: Support Union type in VFR
[mirror_edk2.git] / BaseTools / Source / C / VfrCompile / VfrFormPkg.cpp
CommitLineData
30fdf114
LG
1/** @file\r
2 \r
3 The definition of CFormPkg's member function\r
4\r
bec3a181 5Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
40d841f6 6This program and the accompanying materials \r
30fdf114
LG
7are licensed and made available under the terms and conditions of the BSD License \r
8which accompanies this distribution. The full text of the license may be found at \r
9http://opensource.org/licenses/bsd-license.php \r
10 \r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
13\r
14**/\r
15\r
16#include "stdio.h"\r
9b78c54a 17#include "assert.h"\r
30fdf114
LG
18#include "VfrFormPkg.h"\r
19\r
20/*\r
21 * The definition of CFormPkg's member function\r
22 */\r
23\r
24SPendingAssign::SPendingAssign (\r
25 IN CHAR8 *Key, \r
26 IN VOID *Addr, \r
27 IN UINT32 Len, \r
28 IN UINT32 LineNo,\r
52302d4d 29 IN CONST CHAR8 *Msg\r
30fdf114
LG
30 )\r
31{\r
32 mKey = NULL;\r
33 mAddr = Addr;\r
34 mLen = Len;\r
35 mFlag = PENDING;\r
36 mLineNo = LineNo;\r
37 mMsg = NULL;\r
38 mNext = NULL;\r
39 if (Key != NULL) {\r
40 mKey = new CHAR8[strlen (Key) + 1];\r
41 if (mKey != NULL) {\r
42 strcpy (mKey, Key);\r
43 }\r
44 }\r
45\r
46 if (Msg != NULL) {\r
47 mMsg = new CHAR8[strlen (Msg) + 1];\r
48 if (mMsg != NULL) {\r
49 strcpy (mMsg, Msg);\r
50 }\r
51 }\r
52}\r
53\r
54SPendingAssign::~SPendingAssign (\r
55 VOID\r
56 )\r
57{\r
58 if (mKey != NULL) {\r
fd542523 59 delete[] mKey;\r
30fdf114
LG
60 }\r
61 mAddr = NULL;\r
62 mLen = 0;\r
63 mLineNo = 0;\r
64 if (mMsg != NULL) {\r
fd542523 65 delete[] mMsg;\r
30fdf114
LG
66 }\r
67 mNext = NULL;\r
68}\r
69\r
70VOID\r
71SPendingAssign::SetAddrAndLen (\r
72 IN VOID *Addr, \r
73 IN UINT32 LineNo\r
74 )\r
75{\r
76 mAddr = Addr;\r
77 mLineNo = LineNo;\r
78}\r
79\r
80VOID\r
81SPendingAssign::AssignValue (\r
82 IN VOID *Addr, \r
83 IN UINT32 Len\r
84 )\r
85{\r
f51461c8 86 memmove (mAddr, Addr, (mLen < Len ? mLen : Len));\r
30fdf114
LG
87 mFlag = ASSIGNED;\r
88}\r
89\r
90CHAR8 *\r
91SPendingAssign::GetKey (\r
92 VOID\r
93 )\r
94{\r
95 return mKey;\r
96}\r
97\r
98CFormPkg::CFormPkg (\r
ed395cfe 99 IN UINT32 BufferSize\r
30fdf114
LG
100 )\r
101{\r
102 CHAR8 *BufferStart;\r
103 CHAR8 *BufferEnd;\r
104 SBufferNode *Node;\r
105\r
106 mPkgLength = 0;\r
107 mBufferNodeQueueHead = NULL;\r
108 mCurrBufferNode = NULL;\r
109\r
110 Node = new SBufferNode;\r
111 if (Node == NULL) {\r
112 return ;\r
113 }\r
114 BufferStart = new CHAR8[BufferSize];\r
115 if (BufferStart == NULL) {\r
bdf5f731 116 delete Node;\r
30fdf114
LG
117 return;\r
118 }\r
119 BufferEnd = BufferStart + BufferSize;\r
120\r
121 memset (BufferStart, 0, BufferSize);\r
122 Node->mBufferStart = BufferStart;\r
123 Node->mBufferEnd = BufferEnd;\r
124 Node->mBufferFree = BufferStart;\r
125 Node->mNext = NULL;\r
126\r
127 mBufferSize = BufferSize;\r
128 mBufferNodeQueueHead = Node;\r
129 mBufferNodeQueueTail = Node;\r
130 mCurrBufferNode = Node;\r
131}\r
132\r
133CFormPkg::~CFormPkg ()\r
134{\r
135 SBufferNode *pBNode;\r
136 SPendingAssign *pPNode;\r
137\r
138 while (mBufferNodeQueueHead != NULL) {\r
139 pBNode = mBufferNodeQueueHead;\r
140 mBufferNodeQueueHead = mBufferNodeQueueHead->mNext;\r
141 if (pBNode->mBufferStart != NULL) {\r
142 delete pBNode->mBufferStart;\r
143 delete pBNode;\r
144 }\r
145 }\r
146 mBufferNodeQueueTail = NULL;\r
147 mCurrBufferNode = NULL;\r
148\r
149 while (PendingAssignList != NULL) {\r
150 pPNode = PendingAssignList;\r
151 PendingAssignList = PendingAssignList->mNext;\r
152 delete pPNode;\r
153 }\r
154 PendingAssignList = NULL;\r
155}\r
156\r
4afd3d04
LG
157SBufferNode *\r
158CFormPkg::CreateNewNode (\r
159 VOID\r
160 )\r
161{\r
162 SBufferNode *Node;\r
163\r
164 Node = new SBufferNode;\r
165 if (Node == NULL) {\r
166 return NULL;\r
167 }\r
168\r
169 Node->mBufferStart = new CHAR8[mBufferSize];\r
170 if (Node->mBufferStart == NULL) {\r
171 delete Node;\r
172 return NULL;\r
173 } else {\r
174 memset (Node->mBufferStart, 0, mBufferSize);\r
175 Node->mBufferEnd = Node->mBufferStart + mBufferSize;\r
176 Node->mBufferFree = Node->mBufferStart;\r
177 Node->mNext = NULL;\r
178 }\r
179\r
180 return Node;\r
181}\r
182\r
30fdf114
LG
183CHAR8 *\r
184CFormPkg::IfrBinBufferGet (\r
185 IN UINT32 Len\r
186 )\r
187{\r
4afd3d04
LG
188 CHAR8 *BinBuffer = NULL;\r
189 SBufferNode *Node = NULL;\r
30fdf114
LG
190\r
191 if ((Len == 0) || (Len > mBufferSize)) {\r
192 return NULL;\r
193 }\r
194\r
195 if ((mCurrBufferNode->mBufferFree + Len) <= mCurrBufferNode->mBufferEnd) {\r
196 BinBuffer = mCurrBufferNode->mBufferFree;\r
197 mCurrBufferNode->mBufferFree += Len;\r
198 } else {\r
4afd3d04 199 Node = CreateNewNode ();\r
30fdf114
LG
200 if (Node == NULL) {\r
201 return NULL;\r
202 }\r
203\r
30fdf114
LG
204 if (mBufferNodeQueueTail == NULL) {\r
205 mBufferNodeQueueHead = mBufferNodeQueueTail = Node;\r
206 } else {\r
207 mBufferNodeQueueTail->mNext = Node;\r
208 mBufferNodeQueueTail = Node;\r
209 }\r
210 mCurrBufferNode = Node;\r
211\r
212 //\r
213 // Now try again.\r
214 //\r
215 BinBuffer = mCurrBufferNode->mBufferFree;\r
216 mCurrBufferNode->mBufferFree += Len;\r
217 }\r
218\r
219 mPkgLength += Len;\r
220\r
221 return BinBuffer;\r
222}\r
223\r
224inline\r
225UINT32\r
226CFormPkg::GetPkgLength (\r
227 VOID\r
228 )\r
229{\r
230 return mPkgLength;\r
231}\r
232\r
233VOID\r
234CFormPkg::Open (\r
235 VOID\r
236 )\r
237{\r
238 mReadBufferNode = mBufferNodeQueueHead;\r
239 mReadBufferOffset = 0;\r
240}\r
241\r
242VOID\r
243CFormPkg::Close (\r
244 VOID\r
245 )\r
246{\r
247 mReadBufferNode = NULL;\r
248 mReadBufferOffset = 0;\r
249}\r
250\r
251UINT32\r
252CFormPkg::Read (\r
253 IN CHAR8 *Buffer, \r
254 IN UINT32 Size\r
255 )\r
256{\r
257 UINT32 Index;\r
258\r
259 if ((Size == 0) || (Buffer == NULL)) {\r
260 return 0;\r
261 }\r
262\r
263 if (mReadBufferNode == NULL) {\r
4afd3d04 264 return 0;\r
30fdf114
LG
265 }\r
266\r
267 for (Index = 0; Index < Size; Index++) {\r
268 if ((mReadBufferNode->mBufferStart + mReadBufferOffset) < mReadBufferNode->mBufferFree) {\r
269 Buffer[Index] = mReadBufferNode->mBufferStart[mReadBufferOffset++];\r
270 } else {\r
271 if ((mReadBufferNode = mReadBufferNode->mNext) == NULL) {\r
272 return Index;\r
273 } else {\r
274 mReadBufferOffset = 0;\r
4afd3d04 275 Index --;\r
30fdf114
LG
276 }\r
277 }\r
278 }\r
279\r
280 return Size;\r
281}\r
282\r
283EFI_VFR_RETURN_CODE\r
284CFormPkg::BuildPkgHdr (\r
285 OUT EFI_HII_PACKAGE_HEADER **PkgHdr\r
286 )\r
287{\r
288 if (PkgHdr == NULL) {\r
289 return VFR_RETURN_FATAL_ERROR;\r
290 }\r
291\r
292 if (((*PkgHdr) = new EFI_HII_PACKAGE_HEADER) == NULL) {\r
293 return VFR_RETURN_OUT_FOR_RESOURCES;\r
294 }\r
295\r
296 (*PkgHdr)->Type = EFI_HII_PACKAGE_FORM;\r
297 (*PkgHdr)->Length = mPkgLength + sizeof (EFI_HII_PACKAGE_HEADER);\r
298\r
299 return VFR_RETURN_SUCCESS;\r
300}\r
301\r
302EFI_VFR_RETURN_CODE\r
303CFormPkg::BuildPkg (\r
304 OUT PACKAGE_DATA &TBuffer\r
305 )\r
306{\r
307 \r
308 CHAR8 *Temp;\r
309 UINT32 Size;\r
310 CHAR8 Buffer[1024];\r
311\r
312 if (TBuffer.Buffer != NULL) {\r
313 delete TBuffer.Buffer;\r
314 }\r
315\r
316 TBuffer.Size = mPkgLength;\r
317 TBuffer.Buffer = NULL;\r
318 if (TBuffer.Size != 0) {\r
319 TBuffer.Buffer = new CHAR8[TBuffer.Size];\r
320 } else {\r
321 return VFR_RETURN_SUCCESS;\r
322 }\r
323\r
324 Temp = TBuffer.Buffer;\r
325 Open ();\r
326 while ((Size = Read (Buffer, 1024)) != 0) {\r
327 memcpy (Temp, Buffer, Size);\r
328 Temp += Size;\r
329 }\r
330 Close ();\r
331 return VFR_RETURN_SUCCESS;\r
332}\r
333\r
334\r
335EFI_VFR_RETURN_CODE\r
336CFormPkg::BuildPkg (\r
337 IN FILE *Output,\r
338 IN PACKAGE_DATA *PkgData\r
339 )\r
340{\r
341 EFI_VFR_RETURN_CODE Ret;\r
342 CHAR8 Buffer[1024];\r
343 UINT32 Size;\r
344 EFI_HII_PACKAGE_HEADER *PkgHdr;\r
345\r
346 if (Output == NULL) {\r
347 return VFR_RETURN_FATAL_ERROR;\r
348 }\r
349\r
350 if ((Ret = BuildPkgHdr(&PkgHdr)) != VFR_RETURN_SUCCESS) {\r
351 return Ret;\r
352 }\r
353 fwrite (PkgHdr, sizeof (EFI_HII_PACKAGE_HEADER), 1, Output);\r
354 delete PkgHdr;\r
355 \r
356 if (PkgData == NULL) {\r
357 Open ();\r
358 while ((Size = Read (Buffer, 1024)) != 0) {\r
359 fwrite (Buffer, Size, 1, Output);\r
360 }\r
361 Close ();\r
362 } else {\r
363 fwrite (PkgData->Buffer, PkgData->Size, 1, Output);\r
364 }\r
365\r
366 return VFR_RETURN_SUCCESS;\r
367}\r
368\r
369VOID\r
370CFormPkg::_WRITE_PKG_LINE (\r
52302d4d
LG
371 IN FILE *pFile,\r
372 IN UINT32 LineBytes,\r
373 IN CONST CHAR8 *LineHeader,\r
374 IN CHAR8 *BlkBuf,\r
375 IN UINT32 BlkSize\r
30fdf114
LG
376 )\r
377{\r
378 UINT32 Index;\r
379\r
380 if ((pFile == NULL) || (LineHeader == NULL) || (BlkBuf == NULL)) {\r
381 return;\r
382 }\r
383\r
384 for (Index = 0; Index < BlkSize; Index++) {\r
385 if ((Index % LineBytes) == 0) {\r
386 fprintf (pFile, "\n%s", LineHeader);\r
387 }\r
388 fprintf (pFile, "0x%02X, ", (UINT8)BlkBuf[Index]);\r
389 }\r
390}\r
391\r
392VOID\r
393CFormPkg::_WRITE_PKG_END (\r
52302d4d
LG
394 IN FILE *pFile,\r
395 IN UINT32 LineBytes,\r
396 IN CONST CHAR8 *LineHeader,\r
397 IN CHAR8 *BlkBuf,\r
398 IN UINT32 BlkSize\r
30fdf114
LG
399 )\r
400{\r
401 UINT32 Index;\r
402\r
403 if ((BlkSize == 0) || (pFile == NULL) || (LineHeader == NULL) || (BlkBuf == NULL)) {\r
404 return;\r
405 }\r
406\r
407 for (Index = 0; Index < BlkSize - 1; Index++) {\r
408 if ((Index % LineBytes) == 0) {\r
409 fprintf (pFile, "\n%s", LineHeader);\r
410 }\r
411 fprintf (pFile, "0x%02X, ", (UINT8)BlkBuf[Index]);\r
412 }\r
413\r
414 if ((Index % LineBytes) == 0) {\r
415 fprintf (pFile, "\n%s", LineHeader);\r
416 }\r
417 fprintf (pFile, "0x%02X\n", (UINT8)BlkBuf[Index]);\r
418}\r
419\r
420#define BYTES_PRE_LINE 0x10\r
4afd3d04
LG
421UINT32 gAdjustOpcodeOffset = 0;\r
422BOOLEAN gNeedAdjustOpcode = FALSE;\r
423UINT32 gAdjustOpcodeLen = 0;\r
30fdf114
LG
424\r
425EFI_VFR_RETURN_CODE \r
426CFormPkg::GenCFile (\r
427 IN CHAR8 *BaseName,\r
428 IN FILE *pFile,\r
429 IN PACKAGE_DATA *PkgData\r
430 )\r
431{\r
432 EFI_VFR_RETURN_CODE Ret;\r
433 CHAR8 Buffer[BYTES_PRE_LINE * 8];\r
434 EFI_HII_PACKAGE_HEADER *PkgHdr;\r
435 UINT32 PkgLength = 0;\r
436 UINT32 ReadSize = 0;\r
437\r
438 if ((BaseName == NULL) || (pFile == NULL)) {\r
439 return VFR_RETURN_FATAL_ERROR;\r
440 }\r
441\r
442 fprintf (pFile, "\nunsigned char %sBin[] = {\n", BaseName);\r
443\r
444 if ((Ret = BuildPkgHdr(&PkgHdr)) != VFR_RETURN_SUCCESS) {\r
445 return Ret;\r
446 }\r
447\r
448 //\r
449 // For framework vfr file, the extension framework header will be added.\r
450 //\r
451 if (VfrCompatibleMode) {\r
452 fprintf (pFile, " // FRAMEWORK PACKAGE HEADER Length\n");\r
453 PkgLength = PkgHdr->Length + sizeof (UINT32) + 2;\r
454 _WRITE_PKG_LINE(pFile, BYTES_PRE_LINE, " ", (CHAR8 *)&PkgLength, sizeof (UINT32)); \r
455 fprintf (pFile, "\n\n // FRAMEWORK PACKAGE HEADER Type\n");\r
456 PkgLength = 3;\r
457 _WRITE_PKG_LINE(pFile, BYTES_PRE_LINE, " ", (CHAR8 *)&PkgLength, sizeof (UINT16)); \r
458 } else {\r
459 fprintf (pFile, " // ARRAY LENGTH\n");\r
460 PkgLength = PkgHdr->Length + sizeof (UINT32);\r
461 _WRITE_PKG_LINE(pFile, BYTES_PRE_LINE, " ", (CHAR8 *)&PkgLength, sizeof (UINT32)); \r
462 }\r
463\r
464 fprintf (pFile, "\n\n // PACKAGE HEADER\n");\r
465 _WRITE_PKG_LINE(pFile, BYTES_PRE_LINE, " ", (CHAR8 *)PkgHdr, sizeof (EFI_HII_PACKAGE_HEADER));\r
466 PkgLength = sizeof (EFI_HII_PACKAGE_HEADER);\r
467\r
468 fprintf (pFile, "\n\n // PACKAGE DATA\n");\r
469 \r
470 if (PkgData == NULL) {\r
471 Open ();\r
472 while ((ReadSize = Read ((CHAR8 *)Buffer, BYTES_PRE_LINE * 8)) != 0) {\r
473 PkgLength += ReadSize;\r
474 if (PkgLength < PkgHdr->Length) {\r
475 _WRITE_PKG_LINE (pFile, BYTES_PRE_LINE, " ", Buffer, ReadSize);\r
476 } else {\r
477 _WRITE_PKG_END (pFile, BYTES_PRE_LINE, " ", Buffer, ReadSize);\r
478 }\r
479 }\r
480 Close ();\r
481 } else {\r
482 if (PkgData->Size % BYTES_PRE_LINE != 0) {\r
483 PkgLength = PkgData->Size - (PkgData->Size % BYTES_PRE_LINE);\r
484 _WRITE_PKG_LINE (pFile, BYTES_PRE_LINE, " ", PkgData->Buffer, PkgLength);\r
485 _WRITE_PKG_END (pFile, BYTES_PRE_LINE, " ", PkgData->Buffer + PkgLength, PkgData->Size % BYTES_PRE_LINE);\r
486 } else {\r
487 PkgLength = PkgData->Size - BYTES_PRE_LINE;\r
488 _WRITE_PKG_LINE (pFile, BYTES_PRE_LINE, " ", PkgData->Buffer, PkgLength);\r
489 _WRITE_PKG_END (pFile, BYTES_PRE_LINE, " ", PkgData->Buffer + PkgLength, BYTES_PRE_LINE);\r
490 }\r
491 }\r
492\r
493 delete PkgHdr;\r
494 fprintf (pFile, "\n};\n");\r
495\r
496 return VFR_RETURN_SUCCESS;\r
497}\r
498\r
499EFI_VFR_RETURN_CODE\r
500CFormPkg::AssignPending (\r
501 IN CHAR8 *Key, \r
502 IN VOID *ValAddr, \r
503 IN UINT32 ValLen,\r
504 IN UINT32 LineNo,\r
52302d4d 505 IN CONST CHAR8 *Msg\r
30fdf114
LG
506 )\r
507{\r
508 SPendingAssign *pNew;\r
509\r
510 pNew = new SPendingAssign (Key, ValAddr, ValLen, LineNo, Msg);\r
511 if (pNew == NULL) {\r
512 return VFR_RETURN_OUT_FOR_RESOURCES;\r
513 }\r
514\r
515 pNew->mNext = PendingAssignList;\r
516 PendingAssignList = pNew;\r
517 return VFR_RETURN_SUCCESS;\r
518}\r
519\r
520VOID\r
521CFormPkg::DoPendingAssign (\r
522 IN CHAR8 *Key, \r
523 IN VOID *ValAddr, \r
524 IN UINT32 ValLen\r
525 )\r
526{\r
527 SPendingAssign *pNode;\r
528\r
529 if ((Key == NULL) || (ValAddr == NULL)) {\r
530 return;\r
531 }\r
532\r
533 for (pNode = PendingAssignList; pNode != NULL; pNode = pNode->mNext) {\r
534 if (strcmp (pNode->mKey, Key) == 0) {\r
535 pNode->AssignValue (ValAddr, ValLen);\r
536 }\r
537 }\r
538}\r
539\r
540bool\r
541CFormPkg::HavePendingUnassigned (\r
542 VOID\r
543 )\r
544{\r
545 SPendingAssign *pNode;\r
546\r
547 for (pNode = PendingAssignList; pNode != NULL; pNode = pNode->mNext) {\r
548 if (pNode->mFlag == PENDING) {\r
549 return TRUE;\r
550 }\r
551 }\r
552\r
553 return FALSE;\r
554}\r
555\r
556VOID\r
557CFormPkg::PendingAssignPrintAll (\r
558 VOID\r
559 )\r
560{\r
561 SPendingAssign *pNode;\r
562\r
563 for (pNode = PendingAssignList; pNode != NULL; pNode = pNode->mNext) {\r
564 if (pNode->mFlag == PENDING) {\r
565 gCVfrErrorHandle.PrintMsg (pNode->mLineNo, pNode->mKey, "Error", pNode->mMsg);\r
566 }\r
567 }\r
568}\r
569\r
4afd3d04
LG
570SBufferNode *\r
571CFormPkg::GetBinBufferNodeForAddr (\r
572 IN CHAR8 *BinBuffAddr\r
573 )\r
574{\r
575 SBufferNode *TmpNode;\r
576\r
577 TmpNode = mBufferNodeQueueHead;\r
578\r
579 while (TmpNode != NULL) {\r
580 if (TmpNode->mBufferStart <= BinBuffAddr && TmpNode->mBufferFree >= BinBuffAddr) {\r
581 return TmpNode;\r
582 }\r
583\r
584 TmpNode = TmpNode->mNext;\r
585 }\r
586\r
587 return NULL;\r
588}\r
589\r
590SBufferNode *\r
591CFormPkg::GetNodeBefore(\r
592 IN SBufferNode *CurrentNode\r
593 )\r
594{\r
595 SBufferNode *FirstNode = mBufferNodeQueueHead;\r
596 SBufferNode *LastNode = mBufferNodeQueueHead;\r
597\r
598 while (FirstNode != NULL) {\r
599 if (FirstNode == CurrentNode) {\r
600 break;\r
601 }\r
602\r
603 LastNode = FirstNode;\r
604 FirstNode = FirstNode->mNext;\r
605 }\r
606\r
607 if (FirstNode == NULL) {\r
608 LastNode = NULL;\r
609 }\r
610\r
611 return LastNode;\r
612}\r
613\r
614EFI_VFR_RETURN_CODE\r
615CFormPkg::InsertNodeBefore(\r
616 IN SBufferNode *CurrentNode,\r
617 IN SBufferNode *NewNode\r
618 )\r
619{\r
620 SBufferNode *LastNode = GetNodeBefore (CurrentNode);\r
621\r
622 if (LastNode == NULL) {\r
623 return VFR_RETURN_MISMATCHED;\r
624 }\r
625\r
626 NewNode->mNext = LastNode->mNext;\r
627 LastNode->mNext = NewNode;\r
628\r
629 return VFR_RETURN_SUCCESS;\r
630}\r
631\r
632CHAR8 *\r
633CFormPkg::GetBufAddrBaseOnOffset (\r
634 IN UINT32 Offset\r
635 )\r
636{\r
637 SBufferNode *TmpNode;\r
638 UINT32 TotalBufLen;\r
639 UINT32 CurrentBufLen;\r
640\r
641 TotalBufLen = 0;\r
642\r
643 for (TmpNode = mBufferNodeQueueHead; TmpNode != NULL; TmpNode = TmpNode->mNext) {\r
644 CurrentBufLen = TmpNode->mBufferFree - TmpNode->mBufferStart;\r
645 if (Offset >= TotalBufLen && Offset < TotalBufLen + CurrentBufLen) {\r
646 return TmpNode->mBufferStart + (Offset - TotalBufLen);\r
647 }\r
648\r
649 TotalBufLen += CurrentBufLen;\r
650 }\r
651\r
652 return NULL;\r
653}\r
654\r
655EFI_VFR_RETURN_CODE\r
656CFormPkg::AdjustDynamicInsertOpcode (\r
74bbe31b
DB
657 IN CHAR8 *InserPositionAddr,\r
658 IN CHAR8 *InsertOpcodeAddr,\r
659 IN BOOLEAN CreateOpcodeAfterParsingVfr\r
4afd3d04
LG
660 )\r
661{\r
74bbe31b 662 SBufferNode *InserPositionNode;\r
4afd3d04
LG
663 SBufferNode *InsertOpcodeNode;\r
664 SBufferNode *NewRestoreNodeBegin;\r
665 SBufferNode *NewRestoreNodeEnd;\r
666 SBufferNode *NewLastEndNode;\r
667 SBufferNode *TmpNode;\r
668 UINT32 NeedRestoreCodeLen;\r
669\r
670 NewRestoreNodeEnd = NULL;\r
671\r
74bbe31b 672 InserPositionNode = GetBinBufferNodeForAddr(InserPositionAddr);\r
4afd3d04 673 InsertOpcodeNode = GetBinBufferNodeForAddr(InsertOpcodeAddr);\r
9b78c54a
HW
674 assert (InserPositionNode != NULL);\r
675 assert (InsertOpcodeNode != NULL);\r
4afd3d04 676\r
74bbe31b 677 if (InserPositionNode == InsertOpcodeNode) {\r
4afd3d04
LG
678 //\r
679 // Create New Node to save the restore opcode.\r
680 //\r
74bbe31b 681 NeedRestoreCodeLen = InsertOpcodeAddr - InserPositionAddr;\r
4afd3d04
LG
682 gAdjustOpcodeLen = NeedRestoreCodeLen;\r
683 NewRestoreNodeBegin = CreateNewNode ();\r
684 if (NewRestoreNodeBegin == NULL) {\r
685 return VFR_RETURN_OUT_FOR_RESOURCES;\r
686 }\r
74bbe31b 687 memcpy (NewRestoreNodeBegin->mBufferFree, InserPositionAddr, NeedRestoreCodeLen);\r
4afd3d04
LG
688 NewRestoreNodeBegin->mBufferFree += NeedRestoreCodeLen;\r
689\r
690 //\r
691 // Override the restore buffer data.\r
692 //\r
74bbe31b 693 memmove (InserPositionAddr, InsertOpcodeAddr, InsertOpcodeNode->mBufferFree - InsertOpcodeAddr);\r
4afd3d04
LG
694 InsertOpcodeNode->mBufferFree -= NeedRestoreCodeLen;\r
695 memset (InsertOpcodeNode->mBufferFree, 0, NeedRestoreCodeLen);\r
696 } else {\r
697 //\r
698 // Create New Node to save the restore opcode.\r
699 //\r
74bbe31b 700 NeedRestoreCodeLen = InserPositionNode->mBufferFree - InserPositionAddr;\r
4afd3d04
LG
701 gAdjustOpcodeLen = NeedRestoreCodeLen;\r
702 NewRestoreNodeBegin = CreateNewNode ();\r
703 if (NewRestoreNodeBegin == NULL) {\r
704 return VFR_RETURN_OUT_FOR_RESOURCES;\r
705 }\r
74bbe31b 706 memcpy (NewRestoreNodeBegin->mBufferFree, InserPositionAddr, NeedRestoreCodeLen);\r
4afd3d04
LG
707 NewRestoreNodeBegin->mBufferFree += NeedRestoreCodeLen;\r
708 //\r
709 // Override the restore buffer data.\r
710 //\r
74bbe31b 711 InserPositionNode->mBufferFree -= NeedRestoreCodeLen;\r
4afd3d04
LG
712 //\r
713 // Link the restore data to new node.\r
714 //\r
74bbe31b 715 NewRestoreNodeBegin->mNext = InserPositionNode->mNext;\r
4afd3d04
LG
716\r
717 //\r
718 // Count the Adjust opcode len.\r
719 //\r
74bbe31b 720 TmpNode = InserPositionNode->mNext;\r
4afd3d04
LG
721 while (TmpNode != InsertOpcodeNode) {\r
722 gAdjustOpcodeLen += TmpNode->mBufferFree - TmpNode->mBufferStart;\r
723 TmpNode = TmpNode->mNext;\r
724 }\r
725\r
726 //\r
727 // Create New Node to save the last node of restore opcode.\r
728 //\r
729 NeedRestoreCodeLen = InsertOpcodeAddr - InsertOpcodeNode->mBufferStart;\r
730 gAdjustOpcodeLen += NeedRestoreCodeLen;\r
731 if (NeedRestoreCodeLen > 0) {\r
732 NewRestoreNodeEnd = CreateNewNode ();\r
733 if (NewRestoreNodeEnd == NULL) {\r
734 return VFR_RETURN_OUT_FOR_RESOURCES;\r
735 }\r
736 memcpy (NewRestoreNodeEnd->mBufferFree, InsertOpcodeNode->mBufferStart, NeedRestoreCodeLen);\r
737 NewRestoreNodeEnd->mBufferFree += NeedRestoreCodeLen;\r
738 //\r
739 // Override the restore buffer data.\r
740 //\r
f51461c8 741 memmove (InsertOpcodeNode->mBufferStart, InsertOpcodeAddr, InsertOpcodeNode->mBufferFree - InsertOpcodeAddr);\r
4afd3d04
LG
742 InsertOpcodeNode->mBufferFree -= InsertOpcodeAddr - InsertOpcodeNode->mBufferStart;\r
743\r
744 //\r
745 // Insert the last restore data node.\r
746 //\r
747 TmpNode = GetNodeBefore (InsertOpcodeNode);\r
9b78c54a
HW
748 assert (TmpNode != NULL);\r
749\r
74bbe31b 750 if (TmpNode == InserPositionNode) {\r
4afd3d04
LG
751 NewRestoreNodeBegin->mNext = NewRestoreNodeEnd;\r
752 } else {\r
753 TmpNode->mNext = NewRestoreNodeEnd;\r
754 }\r
755 //\r
74bbe31b 756 // Connect the dynamic opcode node to the node after InserPositionNode.\r
4afd3d04 757 //\r
74bbe31b 758 InserPositionNode->mNext = InsertOpcodeNode;\r
4afd3d04
LG
759 }\r
760 }\r
761\r
74bbe31b 762 if (CreateOpcodeAfterParsingVfr) {\r
4afd3d04 763 //\r
74bbe31b
DB
764 // Th new opcodes were created after Parsing Vfr file,\r
765 // so the content in mBufferNodeQueueTail must be the new created opcodes.\r
766 // So connet the NewRestoreNodeBegin to the tail and update the tail node.\r
4afd3d04 767 //\r
4afd3d04
LG
768 mBufferNodeQueueTail->mNext = NewRestoreNodeBegin;\r
769 if (NewRestoreNodeEnd != NULL) {\r
74bbe31b 770 mBufferNodeQueueTail = NewRestoreNodeEnd;\r
4afd3d04 771 } else {\r
74bbe31b 772 mBufferNodeQueueTail = NewRestoreNodeBegin;\r
4afd3d04 773 }\r
74bbe31b
DB
774 } else {\r
775 if (mBufferNodeQueueTail->mBufferFree - mBufferNodeQueueTail->mBufferStart > 2) {\r
776 //\r
777 // End form set opcode all in the mBufferNodeQueueTail node.\r
778 //\r
779 NewLastEndNode = CreateNewNode ();\r
780 if (NewLastEndNode == NULL) {\r
781 return VFR_RETURN_OUT_FOR_RESOURCES;\r
782 }\r
783 NewLastEndNode->mBufferStart[0] = 0x29;\r
784 NewLastEndNode->mBufferStart[1] = 0x02;\r
785 NewLastEndNode->mBufferFree += 2;\r
4afd3d04 786\r
74bbe31b
DB
787 mBufferNodeQueueTail->mBufferFree -= 2;\r
788\r
789 mBufferNodeQueueTail->mNext = NewRestoreNodeBegin;\r
790 if (NewRestoreNodeEnd != NULL) {\r
791 NewRestoreNodeEnd->mNext = NewLastEndNode;\r
792 } else {\r
793 NewRestoreNodeBegin->mNext = NewLastEndNode;\r
794 }\r
795\r
796 mBufferNodeQueueTail = NewLastEndNode;\r
797 } else if (mBufferNodeQueueTail->mBufferFree - mBufferNodeQueueTail->mBufferStart == 2) {\r
798 TmpNode = GetNodeBefore(mBufferNodeQueueTail);\r
9b78c54a
HW
799 assert (TmpNode != NULL);\r
800\r
74bbe31b
DB
801 TmpNode->mNext = NewRestoreNodeBegin;\r
802 if (NewRestoreNodeEnd != NULL) {\r
803 NewRestoreNodeEnd->mNext = mBufferNodeQueueTail;\r
804 } else {\r
805 NewRestoreNodeBegin->mNext = mBufferNodeQueueTail;\r
806 }\r
4afd3d04
LG
807 }\r
808 }\r
74bbe31b 809 mCurrBufferNode = mBufferNodeQueueTail;\r
4afd3d04
LG
810 return VFR_RETURN_SUCCESS;\r
811}\r
812\r
30fdf114
LG
813EFI_VFR_RETURN_CODE\r
814CFormPkg::DeclarePendingQuestion (\r
815 IN CVfrVarDataTypeDB &lCVfrVarDataTypeDB,\r
816 IN CVfrDataStorage &lCVfrDataStorage,\r
817 IN CVfrQuestionDB &lCVfrQuestionDB,\r
818 IN EFI_GUID *LocalFormSetGuid,\r
4afd3d04
LG
819 IN UINT32 LineNo,\r
820 OUT CHAR8 **InsertOpcodeAddr\r
30fdf114
LG
821 )\r
822{\r
823 SPendingAssign *pNode;\r
824 CHAR8 *VarStr;\r
825 UINT32 ArrayIdx;\r
826 CHAR8 FName[MAX_NAME_LEN];\r
b36d134f
LG
827 CHAR8 *SName;\r
828 CHAR8 *NewStr;\r
61eb9834 829 UINT32 ShrinkSize = 0;\r
30fdf114
LG
830 EFI_VFR_RETURN_CODE ReturnCode;\r
831 EFI_VFR_VARSTORE_TYPE VarStoreType = EFI_VFR_VARSTORE_INVALID;\r
832\r
b36d134f
LG
833 //\r
834 // Declare all questions as Numeric in DisableIf True\r
835 //\r
836 // DisableIf\r
837 CIfrDisableIf DIObj;\r
838 DIObj.SetLineNo (LineNo);\r
4afd3d04 839 *InsertOpcodeAddr = DIObj.GetObjBinAddr ();\r
b36d134f
LG
840 \r
841 //TrueOpcode\r
842 CIfrTrue TObj (LineNo);\r
843\r
844 // Declare Numeric qeustion for each undefined question.\r
30fdf114
LG
845 for (pNode = PendingAssignList; pNode != NULL; pNode = pNode->mNext) {\r
846 if (pNode->mFlag == PENDING) {\r
30fdf114
LG
847 CIfrNumeric CNObj;\r
848 EFI_VARSTORE_INFO Info; \r
4afd3d04 849 EFI_QUESTION_ID QId = EFI_QUESTION_ID_INVALID;\r
30fdf114
LG
850\r
851 CNObj.SetLineNo (LineNo);\r
852 CNObj.SetPrompt (0x0);\r
853 CNObj.SetHelp (0x0);\r
854\r
855 //\r
856 // Register this question, assume it is normal question, not date or time question\r
857 //\r
858 VarStr = pNode->mKey;\r
859 ReturnCode = lCVfrQuestionDB.RegisterQuestion (NULL, VarStr, QId);\r
860 if (ReturnCode != VFR_RETURN_SUCCESS) {\r
861 gCVfrErrorHandle.HandleError (ReturnCode, pNode->mLineNo, pNode->mKey);\r
862 return ReturnCode;\r
863 }\r
864 \r
865#ifdef VFREXP_DEBUG\r
866 printf ("Undefined Question name is %s and Id is 0x%x\n", VarStr, QId);\r
867#endif\r
868 //\r
869 // Get Question Info, framework vfr VarName == StructName\r
870 //\r
871 ReturnCode = lCVfrVarDataTypeDB.ExtractFieldNameAndArrary (VarStr, FName, ArrayIdx);\r
872 if (ReturnCode != VFR_RETURN_SUCCESS) {\r
873 gCVfrErrorHandle.PrintMsg (pNode->mLineNo, pNode->mKey, "Error", "Var string is not the valid C variable");\r
874 return ReturnCode;\r
875 }\r
876 //\r
877 // Get VarStoreType\r
878 //\r
4afd3d04 879 ReturnCode = lCVfrDataStorage.GetVarStoreId (FName, &Info.mVarStoreId);\r
30fdf114
LG
880 if (ReturnCode != VFR_RETURN_SUCCESS) {\r
881 gCVfrErrorHandle.PrintMsg (pNode->mLineNo, FName, "Error", "Var Store Type is not defined");\r
882 return ReturnCode;\r
883 }\r
4afd3d04 884 VarStoreType = lCVfrDataStorage.GetVarStoreType (Info.mVarStoreId); \r
30fdf114
LG
885\r
886 if (*VarStr == '\0' && ArrayIdx != INVALID_ARRAY_INDEX) {\r
887 ReturnCode = lCVfrDataStorage.GetNameVarStoreInfo (&Info, ArrayIdx);\r
888 } else {\r
889 if (VarStoreType == EFI_VFR_VARSTORE_EFI) {\r
890 ReturnCode = lCVfrDataStorage.GetEfiVarStoreInfo (&Info);\r
891 } else if (VarStoreType == EFI_VFR_VARSTORE_BUFFER) {\r
892 VarStr = pNode->mKey;\r
b36d134f 893 //convert VarStr with store name to VarStr with structure name\r
4afd3d04 894 ReturnCode = lCVfrDataStorage.GetBufferVarStoreDataTypeName (Info.mVarStoreId, &SName);\r
b36d134f
LG
895 if (ReturnCode == VFR_RETURN_SUCCESS) {\r
896 NewStr = new CHAR8[strlen (VarStr) + strlen (SName) + 1];\r
897 NewStr[0] = '\0';\r
898 strcpy (NewStr, SName);\r
899 strcat (NewStr, VarStr + strlen (FName));\r
900 ReturnCode = lCVfrVarDataTypeDB.GetDataFieldInfo (NewStr, Info.mInfo.mVarOffset, Info.mVarType, Info.mVarTotalSize);\r
fd542523 901 delete[] NewStr;\r
b36d134f 902 }\r
30fdf114
LG
903 } else {\r
904 ReturnCode = VFR_RETURN_UNSUPPORTED;\r
905 }\r
906 }\r
907 if (ReturnCode != VFR_RETURN_SUCCESS) {\r
908 gCVfrErrorHandle.HandleError (ReturnCode, pNode->mLineNo, pNode->mKey);\r
909 return ReturnCode;\r
910 }\r
911\r
912 CNObj.SetQuestionId (QId);\r
913 CNObj.SetVarStoreInfo (&Info);\r
0d2711a6
LG
914 //\r
915 // Numeric doesn't support BOOLEAN data type. \r
916 // BOOLEAN type has the same data size to UINT8. \r
917 //\r
918 if (Info.mVarType == EFI_IFR_TYPE_BOOLEAN) {\r
919 Info.mVarType = EFI_IFR_TYPE_NUM_SIZE_8;\r
920 }\r
30fdf114 921 CNObj.SetFlags (0, Info.mVarType);\r
2bcc713e
LG
922 //\r
923 // Use maximum value not to limit the vaild value for the undefined question.\r
924 //\r
925 switch (Info.mVarType) {\r
926 case EFI_IFR_TYPE_NUM_SIZE_64:\r
927 CNObj.SetMinMaxStepData ((UINT64) 0, (UINT64) -1 , (UINT64) 0);\r
4afd3d04 928 ShrinkSize = 0;\r
2bcc713e
LG
929 break;\r
930 case EFI_IFR_TYPE_NUM_SIZE_32:\r
931 CNObj.SetMinMaxStepData ((UINT32) 0, (UINT32) -1 , (UINT32) 0);\r
4afd3d04 932 ShrinkSize = 12;\r
2bcc713e
LG
933 break;\r
934 case EFI_IFR_TYPE_NUM_SIZE_16:\r
935 CNObj.SetMinMaxStepData ((UINT16) 0, (UINT16) -1 , (UINT16) 0);\r
4afd3d04 936 ShrinkSize = 18;\r
2bcc713e
LG
937 break;\r
938 case EFI_IFR_TYPE_NUM_SIZE_8:\r
939 CNObj.SetMinMaxStepData ((UINT8) 0, (UINT8) -1 , (UINT8) 0);\r
4afd3d04 940 ShrinkSize = 21;\r
2bcc713e
LG
941 break;\r
942 default:\r
943 break;\r
944 }\r
4afd3d04 945 CNObj.ShrinkBinSize (ShrinkSize);\r
30fdf114
LG
946\r
947 //\r
948 // For undefined Efi VarStore type question\r
949 // Append the extended guided opcode to contain VarName\r
950 //\r
b36d134f 951 if (VarStoreType == EFI_VFR_VARSTORE_EFI || VfrCompatibleMode) {\r
30fdf114
LG
952 CIfrVarEqName CVNObj (QId, Info.mInfo.mVarName);\r
953 CVNObj.SetLineNo (LineNo);\r
954 }\r
4afd3d04 955\r
30fdf114
LG
956 //\r
957 // End for Numeric\r
958 //\r
959 CIfrEnd CEObj; \r
960 CEObj.SetLineNo (LineNo);\r
30fdf114
LG
961 }\r
962 }\r
b36d134f
LG
963\r
964 //\r
965 // End for DisableIf\r
966 //\r
967 CIfrEnd SEObj;\r
968 SEObj.SetLineNo (LineNo);\r
969\r
30fdf114
LG
970 return VFR_RETURN_SUCCESS;\r
971}\r
972\r
973CFormPkg gCFormPkg;\r
974\r
975SIfrRecord::SIfrRecord (\r
976 VOID\r
977 )\r
978{\r
979 mIfrBinBuf = NULL;\r
980 mBinBufLen = 0;\r
981 mLineNo = 0xFFFFFFFF;\r
982 mOffset = 0xFFFFFFFF;\r
983 mNext = NULL;\r
984}\r
985\r
986SIfrRecord::~SIfrRecord (\r
987 VOID\r
988 )\r
989{\r
990 if (mIfrBinBuf != NULL) {\r
991 //delete mIfrBinBuf;\r
992 mIfrBinBuf = NULL;\r
993 }\r
994 mLineNo = 0xFFFFFFFF;\r
995 mOffset = 0xFFFFFFFF;\r
996 mBinBufLen = 0;\r
997 mNext = NULL;\r
998}\r
999\r
1000CIfrRecordInfoDB::CIfrRecordInfoDB (\r
1001 VOID\r
1002 )\r
1003{\r
1004 mSwitch = TRUE;\r
1005 mRecordCount = EFI_IFR_RECORDINFO_IDX_START;\r
1006 mIfrRecordListHead = NULL;\r
1007 mIfrRecordListTail = NULL;\r
74bbe31b
DB
1008 mAllDefaultTypeCount = 0;\r
1009 for (UINT8 i = 0; i < EFI_HII_MAX_SUPPORT_DEFAULT_TYPE; i++) {\r
1010 mAllDefaultIdArray[i] = 0xffff;\r
1011 }\r
30fdf114
LG
1012}\r
1013\r
1014CIfrRecordInfoDB::~CIfrRecordInfoDB (\r
1015 VOID\r
1016 )\r
1017{\r
1018 SIfrRecord *pNode;\r
1019\r
1020 while (mIfrRecordListHead != NULL) {\r
1021 pNode = mIfrRecordListHead;\r
1022 mIfrRecordListHead = mIfrRecordListHead->mNext;\r
1023 delete pNode;\r
1024 }\r
1025}\r
1026\r
1027SIfrRecord *\r
1028CIfrRecordInfoDB::GetRecordInfoFromIdx (\r
1029 IN UINT32 RecordIdx\r
1030 )\r
1031{\r
1032 UINT32 Idx;\r
1033 SIfrRecord *pNode = NULL;\r
1034\r
1035 if (RecordIdx == EFI_IFR_RECORDINFO_IDX_INVALUD) {\r
1036 return NULL;\r
1037 }\r
1038\r
1039 for (Idx = (EFI_IFR_RECORDINFO_IDX_START + 1), pNode = mIfrRecordListHead;\r
1040 (Idx != RecordIdx) && (pNode != NULL);\r
1041 Idx++, pNode = pNode->mNext)\r
1042 ;\r
1043\r
1044 return pNode;\r
1045}\r
1046\r
1047UINT32\r
1048CIfrRecordInfoDB::IfrRecordRegister (\r
1049 IN UINT32 LineNo,\r
1050 IN CHAR8 *IfrBinBuf,\r
1051 IN UINT8 BinBufLen,\r
1052 IN UINT32 Offset\r
1053 )\r
1054{\r
1055 SIfrRecord *pNew;\r
1056\r
1057 if (mSwitch == FALSE) {\r
1058 return EFI_IFR_RECORDINFO_IDX_INVALUD;\r
1059 }\r
1060\r
1061 if ((pNew = new SIfrRecord) == NULL) {\r
1062 return EFI_IFR_RECORDINFO_IDX_INVALUD;\r
1063 }\r
1064\r
1065 if (mIfrRecordListHead == NULL) {\r
1066 mIfrRecordListHead = pNew;\r
1067 mIfrRecordListTail = pNew;\r
1068 } else {\r
1069 mIfrRecordListTail->mNext = pNew;\r
1070 mIfrRecordListTail = pNew;\r
1071 }\r
1072 mRecordCount++;\r
1073\r
1074 return mRecordCount;\r
1075}\r
1076\r
1077VOID\r
1078CIfrRecordInfoDB::IfrRecordInfoUpdate (\r
1079 IN UINT32 RecordIdx,\r
1080 IN UINT32 LineNo,\r
1081 IN CHAR8 *BinBuf,\r
1082 IN UINT8 BinBufLen,\r
1083 IN UINT32 Offset\r
1084 )\r
1085{\r
1086 SIfrRecord *pNode;\r
fd171542 1087 SIfrRecord *Prev;\r
30fdf114
LG
1088\r
1089 if ((pNode = GetRecordInfoFromIdx (RecordIdx)) == NULL) {\r
1090 return;\r
1091 }\r
1092\r
fd171542 1093 if (LineNo == 0) {\r
1094 //\r
1095 // Line number is not specified explicitly, try to use line number of previous opcode\r
1096 //\r
1097 Prev = GetRecordInfoFromIdx (RecordIdx - 1);\r
1098 if (Prev != NULL) {\r
1099 LineNo = Prev->mLineNo;\r
1100 }\r
1101 }\r
1102\r
30fdf114
LG
1103 pNode->mLineNo = LineNo;\r
1104 pNode->mOffset = Offset;\r
1105 pNode->mBinBufLen = BinBufLen;\r
1106 pNode->mIfrBinBuf = BinBuf;\r
1107\r
1108}\r
1109\r
1110VOID\r
1111CIfrRecordInfoDB::IfrRecordOutput (\r
1112 OUT PACKAGE_DATA &TBuffer\r
1113 )\r
1114{\r
1115 CHAR8 *Temp;\r
1116 SIfrRecord *pNode; \r
1117\r
1118 if (TBuffer.Buffer != NULL) {\r
1119 delete TBuffer.Buffer;\r
1120 }\r
1121\r
1122 TBuffer.Size = 0;\r
1123 TBuffer.Buffer = NULL;\r
1124\r
1125\r
1126 if (mSwitch == FALSE) {\r
1127 return;\r
1128 } \r
1129 \r
1130 for (pNode = mIfrRecordListHead; pNode != NULL; pNode = pNode->mNext) {\r
1131 TBuffer.Size += pNode->mBinBufLen;\r
1132 }\r
1133 \r
1134 if (TBuffer.Size != 0) {\r
1135 TBuffer.Buffer = new CHAR8[TBuffer.Size];\r
1136 } else {\r
1137 return;\r
1138 }\r
1139 \r
1140 Temp = TBuffer.Buffer;\r
1141\r
1142 for (pNode = mIfrRecordListHead; pNode != NULL; pNode = pNode->mNext) {\r
1143 if (pNode->mIfrBinBuf != NULL) {\r
1144 memcpy (Temp, pNode->mIfrBinBuf, pNode->mBinBufLen);\r
1145 Temp += pNode->mBinBufLen;\r
1146 }\r
1147 }\r
1148\r
1149 return; \r
1150} \r
1151\r
1152VOID\r
1153CIfrRecordInfoDB::IfrRecordOutput (\r
1154 IN FILE *File,\r
1155 IN UINT32 LineNo\r
1156 )\r
1157{\r
1158 SIfrRecord *pNode;\r
1159 UINT8 Index;\r
1160 UINT32 TotalSize;\r
1161\r
1162 if (mSwitch == FALSE) {\r
1163 return;\r
1164 }\r
1165\r
1166 if (File == NULL) {\r
1167 return;\r
1168 }\r
1169\r
1170 TotalSize = 0;\r
1171\r
1172 for (pNode = mIfrRecordListHead; pNode != NULL; pNode = pNode->mNext) {\r
1173 if (pNode->mLineNo == LineNo || LineNo == 0) {\r
1174 fprintf (File, ">%08X: ", pNode->mOffset);\r
1175 TotalSize += pNode->mBinBufLen;\r
1176 if (pNode->mIfrBinBuf != NULL) {\r
1177 for (Index = 0; Index < pNode->mBinBufLen; Index++) {\r
1178 fprintf (File, "%02X ", (UINT8)(pNode->mIfrBinBuf[Index]));\r
1179 }\r
1180 }\r
1181 fprintf (File, "\n");\r
1182 }\r
1183 }\r
1184 \r
1185 if (LineNo == 0) {\r
1186 fprintf (File, "\nTotal Size of all record is 0x%08X\n", TotalSize);\r
1187 }\r
1188}\r
1189\r
1190//\r
1191// for framework vfr file\r
1192// adjust opcode sequence for uefi IFR format\r
1193// adjust inconsistent and varstore into the right position.\r
1194//\r
1195BOOLEAN\r
1196CIfrRecordInfoDB::CheckQuestionOpCode (\r
1197 IN UINT8 OpCode\r
1198 )\r
1199{\r
1200 switch (OpCode) {\r
1201 case EFI_IFR_CHECKBOX_OP:\r
1202 case EFI_IFR_NUMERIC_OP:\r
1203 case EFI_IFR_PASSWORD_OP:\r
1204 case EFI_IFR_ONE_OF_OP:\r
1205 case EFI_IFR_ACTION_OP:\r
1206 case EFI_IFR_STRING_OP:\r
1207 case EFI_IFR_DATE_OP:\r
1208 case EFI_IFR_TIME_OP:\r
1209 case EFI_IFR_ORDERED_LIST_OP:\r
bec3a181 1210 case EFI_IFR_REF_OP:\r
30fdf114
LG
1211 return TRUE;\r
1212 default:\r
1213 return FALSE;\r
1214 }\r
1215}\r
1216\r
1217BOOLEAN\r
1218CIfrRecordInfoDB::CheckIdOpCode (\r
1219 IN UINT8 OpCode\r
1220 )\r
1221{\r
1222 switch (OpCode) {\r
1223 case EFI_IFR_EQ_ID_VAL_OP:\r
1224 case EFI_IFR_EQ_ID_ID_OP:\r
64b2609f 1225 case EFI_IFR_EQ_ID_VAL_LIST_OP:\r
30fdf114
LG
1226 case EFI_IFR_QUESTION_REF1_OP:\r
1227 return TRUE;\r
1228 default:\r
1229 return FALSE;\r
1230 }\r
1231} \r
1232\r
1233EFI_QUESTION_ID\r
1234CIfrRecordInfoDB::GetOpcodeQuestionId (\r
1235 IN EFI_IFR_OP_HEADER *OpHead\r
1236 )\r
1237{\r
1238 EFI_IFR_QUESTION_HEADER *QuestionHead;\r
1239 \r
1240 QuestionHead = (EFI_IFR_QUESTION_HEADER *) (OpHead + 1);\r
1241 \r
1242 return QuestionHead->QuestionId;\r
1243}\r
1244\r
4afd3d04
LG
1245SIfrRecord *\r
1246CIfrRecordInfoDB::GetRecordInfoFromOffset (\r
1247 IN UINT32 Offset\r
1248 )\r
1249{\r
1250 SIfrRecord *pNode = NULL;\r
1251\r
1252 for (pNode = mIfrRecordListHead; pNode != NULL; pNode = pNode->mNext) {\r
1253 if (pNode->mOffset == Offset) {\r
1254 return pNode;\r
1255 }\r
1256 }\r
1257\r
1258 return pNode;\r
1259}\r
1260\r
74bbe31b 1261/**\r
4afd3d04
LG
1262 Add just the op code position.\r
1263\r
74bbe31b
DB
1264 Case1 (CreateOpcodeAfterParsingVfr == FALSE): The dynamic opcodes were created before the formset opcode,\r
1265 so pDynamicOpcodeNodes is before mIfrRecordListTail.\r
1266\r
4afd3d04 1267 From\r
74bbe31b
DB
1268\r
1269 |mIfrRecordListHead + ...+ pAdjustNode + pDynamicOpcodeNodes + mIfrRecordListTail|\r
1270\r
4afd3d04 1271 To\r
4afd3d04 1272\r
74bbe31b
DB
1273 |mIfrRecordListHead + ...+ pDynamicOpcodeNodes + pAdjustNode + mIfrRecordListTail|\r
1274\r
1275 Case2 (CreateOpcodeAfterParsingVfr == TRUE): The dynamic opcodes were created after paring the vfr file,\r
1276 so new records are appennded to the end of OriginalIfrRecordListTail.\r
1277\r
1278 From\r
1279\r
1280 |mIfrRecordListHead + ...+ pAdjustNode + ... + OriginalIfrRecordListTail + pDynamicOpcodeNodes|\r
1281\r
1282 To\r
1283\r
1284 |mIfrRecordListHead + ...+ pDynamicOpcodeNodes + pAdjustNode + ... + OriginalIfrRecordListTail|\r
1285\r
1286\r
1287 @param CreateOpcodeAfterParsingVfr Whether create the dynamic opcode after parsing the VFR file.\r
1288\r
1289**/\r
4afd3d04
LG
1290BOOLEAN\r
1291CIfrRecordInfoDB::IfrAdjustDynamicOpcodeInRecords (\r
74bbe31b 1292 IN BOOLEAN CreateOpcodeAfterParsingVfr\r
4afd3d04
LG
1293 )\r
1294{\r
1295 UINT32 OpcodeOffset;\r
1296 SIfrRecord *pNode, *pPreNode;\r
74bbe31b
DB
1297 SIfrRecord *pAdjustNode, *pNodeBeforeAdjust;\r
1298 SIfrRecord *pNodeBeforeDynamic;\r
1299\r
61eb9834 1300 pPreNode = NULL;\r
74bbe31b
DB
1301 pAdjustNode = NULL;\r
1302 pNodeBeforeDynamic = NULL;\r
1303 OpcodeOffset = 0;\r
4afd3d04
LG
1304\r
1305 //\r
74bbe31b
DB
1306 // Base on the gAdjustOpcodeOffset and gAdjustOpcodeLen to find the pAdjustNod, the node before pAdjustNode,\r
1307 // and the node before pDynamicOpcodeNode.\r
4afd3d04 1308 //\r
74bbe31b 1309 for (pNode = mIfrRecordListHead; pNode!= NULL; pNode = pNode->mNext) {\r
4afd3d04 1310 if (OpcodeOffset == gAdjustOpcodeOffset) {\r
74bbe31b
DB
1311 pAdjustNode = pNode;\r
1312 pNodeBeforeAdjust = pPreNode;\r
4afd3d04 1313 } else if (OpcodeOffset == gAdjustOpcodeOffset + gAdjustOpcodeLen) {\r
74bbe31b
DB
1314 pNodeBeforeDynamic = pPreNode;\r
1315 }\r
1316 if (pNode->mNext != NULL) {\r
1317 pPreNode = pNode;\r
4afd3d04 1318 }\r
4afd3d04
LG
1319 OpcodeOffset += pNode->mBinBufLen;\r
1320 }\r
1321\r
1322 //\r
74bbe31b 1323 // Check the nodes whether exist.\r
4afd3d04 1324 //\r
9b78c54a 1325 if (pNodeBeforeDynamic == NULL || pAdjustNode == NULL || pNodeBeforeAdjust == NULL) {\r
4afd3d04
LG
1326 return FALSE;\r
1327 }\r
1328\r
1329 //\r
1330 // Adjust the node. pPreNode save the Node before mIfrRecordListTail\r
1331 //\r
74bbe31b
DB
1332 pNodeBeforeAdjust->mNext = pNodeBeforeDynamic->mNext;\r
1333 if (CreateOpcodeAfterParsingVfr) {\r
1334 //\r
1335 // mIfrRecordListTail is the end of pDynamicNode (Case2).\r
1336 //\r
1337 mIfrRecordListTail->mNext = pAdjustNode;\r
1338 mIfrRecordListTail = pNodeBeforeDynamic;\r
1339 mIfrRecordListTail->mNext = NULL;\r
1340 } else {\r
1341 //\r
1342 //pPreNode is the end of pDynamicNode(Case1).\r
1343 //\r
1344 pPreNode->mNext = pAdjustNode;\r
1345 pNodeBeforeDynamic->mNext = mIfrRecordListTail;\r
1346 }\r
4afd3d04
LG
1347\r
1348 return TRUE;\r
1349}\r
1350\r
74bbe31b
DB
1351/**\r
1352 Update the record info(the position in the record list, offset and mIfrBinBuf) for new created record.\r
1353\r
1354 @param CreateOpcodeAfterParsingVfr Whether create the dynamic opcode after parsing the VFR file.\r
1355\r
1356**/\r
1357VOID\r
1358CIfrRecordInfoDB::IfrUpdateRecordInfoForDynamicOpcode (\r
1359 IN BOOLEAN CreateOpcodeAfterParsingVfr\r
1360 )\r
1361{\r
1362 SIfrRecord *pRecord;\r
1363\r
1364 //\r
1365 // Base on the original offset info to update the record list.\r
1366 //\r
1367 if (!IfrAdjustDynamicOpcodeInRecords(CreateOpcodeAfterParsingVfr)) {\r
00de920a 1368 gCVfrErrorHandle.PrintMsg (0, (CHAR8 *)"Error", (CHAR8 *)"Can not find the adjust offset in the record.");\r
74bbe31b
DB
1369 }\r
1370\r
1371 //\r
1372 // Base on the opcode binary length to recalculate the offset for each opcode.\r
1373 //\r
1374 IfrAdjustOffsetForRecord();\r
1375\r
1376 //\r
1377 // Base on the offset to find the binary address.\r
1378 //\r
1379 pRecord = GetRecordInfoFromOffset(gAdjustOpcodeOffset);\r
1380 while (pRecord != NULL) {\r
1381 pRecord->mIfrBinBuf = gCFormPkg.GetBufAddrBaseOnOffset(pRecord->mOffset);\r
1382 pRecord = pRecord->mNext;\r
1383 }\r
1384}\r
1385\r
1386\r
4afd3d04
LG
1387VOID\r
1388CIfrRecordInfoDB::IfrAdjustOffsetForRecord (\r
1389 VOID\r
1390 )\r
1391{\r
1392 UINT32 OpcodeOffset;\r
1393 SIfrRecord *pNode;\r
1394\r
1395 OpcodeOffset = 0;\r
1396 for (pNode = mIfrRecordListHead; pNode != NULL; pNode = pNode->mNext) {\r
1397 pNode->mOffset = OpcodeOffset;\r
1398 OpcodeOffset += pNode->mBinBufLen;\r
1399 }\r
1400}\r
1401\r
30fdf114
LG
1402EFI_VFR_RETURN_CODE\r
1403CIfrRecordInfoDB::IfrRecordAdjust (\r
1404 VOID\r
1405 )\r
1406{\r
1407 SIfrRecord *pNode, *preNode;\r
1408 SIfrRecord *uNode, *tNode;\r
1409 EFI_IFR_OP_HEADER *OpHead, *tOpHead;\r
1410 EFI_QUESTION_ID QuestionId;\r
1411 UINT32 StackCount;\r
1412 UINT32 QuestionScope;\r
30fdf114
LG
1413 CHAR8 ErrorMsg[MAX_STRING_LEN] = {0, };\r
1414 EFI_VFR_RETURN_CODE Status;\r
1415\r
1416 //\r
1417 // Init local variable\r
1418 //\r
1419 Status = VFR_RETURN_SUCCESS;\r
1420 pNode = mIfrRecordListHead;\r
1421 preNode = pNode;\r
1422 QuestionScope = 0;\r
1423 while (pNode != NULL) {\r
1424 OpHead = (EFI_IFR_OP_HEADER *) pNode->mIfrBinBuf;\r
1425 \r
1426 //\r
1427 // make sure the inconsistent opcode in question scope\r
1428 //\r
1429 if (QuestionScope > 0) {\r
1430 QuestionScope += OpHead->Scope;\r
1431 if (OpHead->OpCode == EFI_IFR_END_OP) {\r
1432 QuestionScope --;\r
1433 }\r
1434 }\r
1435 \r
1436 if (CheckQuestionOpCode (OpHead->OpCode)) {\r
1437 QuestionScope = 1;\r
1438 }\r
1439 //\r
1440 // for the inconsistent opcode not in question scope, adjust it\r
1441 //\r
1442 if (OpHead->OpCode == EFI_IFR_INCONSISTENT_IF_OP && QuestionScope == 0) {\r
1443 //\r
1444 // for inconsistent opcode not in question scope\r
1445 //\r
1446\r
1447 //\r
1448 // Count inconsistent opcode Scope \r
1449 //\r
1450 StackCount = OpHead->Scope;\r
1451 QuestionId = EFI_QUESTION_ID_INVALID;\r
1452 tNode = pNode;\r
1453 while (tNode != NULL && StackCount > 0) {\r
1454 tNode = tNode->mNext;\r
1455 tOpHead = (EFI_IFR_OP_HEADER *) tNode->mIfrBinBuf;\r
1456 //\r
1457 // Calculate Scope Number\r
1458 //\r
1459 StackCount += tOpHead->Scope;\r
1460 if (tOpHead->OpCode == EFI_IFR_END_OP) {\r
1461 StackCount --;\r
1462 }\r
1463 //\r
1464 // by IdEqual opcode to get QuestionId\r
1465 //\r
1466 if (QuestionId == EFI_QUESTION_ID_INVALID && \r
1467 CheckIdOpCode (tOpHead->OpCode)) {\r
1468 QuestionId = *(EFI_QUESTION_ID *) (tOpHead + 1);\r
1469 }\r
1470 }\r
1471 if (tNode == NULL || QuestionId == EFI_QUESTION_ID_INVALID) {\r
1472 //\r
1473 // report error; not found\r
1474 //\r
1475 sprintf (ErrorMsg, "Inconsistent OpCode Record list invalid QuestionId is 0x%X", QuestionId);\r
1476 gCVfrErrorHandle.PrintMsg (0, NULL, "Error", ErrorMsg);\r
1477 Status = VFR_RETURN_MISMATCHED;\r
1478 break;\r
1479 }\r
1480 //\r
1481 // extract inconsistent opcode list\r
1482 // pNode is Incosistent opcode, tNode is End Opcode\r
1483 //\r
1484 \r
1485 //\r
1486 // insert inconsistent opcode list into the right question scope by questionid\r
1487 //\r
1488 for (uNode = mIfrRecordListHead; uNode != NULL; uNode = uNode->mNext) {\r
1489 tOpHead = (EFI_IFR_OP_HEADER *) uNode->mIfrBinBuf;\r
1490 if (CheckQuestionOpCode (tOpHead->OpCode) && \r
1491 (QuestionId == GetOpcodeQuestionId (tOpHead))) {\r
1492 break;\r
1493 }\r
1494 }\r
1495 //\r
1496 // insert inconsistent opcode list and check LATE_CHECK flag\r
1497 //\r
1498 if (uNode != NULL) {\r
1499 if ((((EFI_IFR_QUESTION_HEADER *)(tOpHead + 1))->Flags & 0x20) != 0) {\r
1500 //\r
1501 // if LATE_CHECK flag is set, change inconsistent to nosumbit\r
1502 //\r
1503 OpHead->OpCode = EFI_IFR_NO_SUBMIT_IF_OP;\r
1504 }\r
1505 \r
1506 //\r
1507 // skip the default storage for Date and Time\r
1508 //\r
1509 if ((uNode->mNext != NULL) && (*uNode->mNext->mIfrBinBuf == EFI_IFR_DEFAULT_OP)) {\r
1510 uNode = uNode->mNext;\r
1511 }\r
1512\r
1513 preNode->mNext = tNode->mNext;\r
1514 tNode->mNext = uNode->mNext;\r
1515 uNode->mNext = pNode;\r
1516 //\r
1517 // reset pNode to head list, scan the whole list again.\r
1518 //\r
1519 pNode = mIfrRecordListHead;\r
1520 preNode = pNode;\r
1521 QuestionScope = 0;\r
1522 continue;\r
1523 } else {\r
1524 //\r
1525 // not found matched question id, report error\r
1526 //\r
1527 sprintf (ErrorMsg, "QuestionId required by Inconsistent OpCode is not found. QuestionId is 0x%X", QuestionId);\r
1528 gCVfrErrorHandle.PrintMsg (0, NULL, "Error", ErrorMsg);\r
1529 Status = VFR_RETURN_MISMATCHED;\r
1530 break;\r
1531 }\r
1532 } else if (OpHead->OpCode == EFI_IFR_VARSTORE_OP || \r
1533 OpHead->OpCode == EFI_IFR_VARSTORE_EFI_OP) {\r
1534 //\r
1535 // for new added group of varstore opcode\r
1536 //\r
1537 tNode = pNode;\r
1538 while (tNode->mNext != NULL) {\r
1539 tOpHead = (EFI_IFR_OP_HEADER *) tNode->mNext->mIfrBinBuf;\r
1540 if (tOpHead->OpCode != EFI_IFR_VARSTORE_OP && \r
1541 tOpHead->OpCode != EFI_IFR_VARSTORE_EFI_OP) {\r
1542 break; \r
1543 }\r
1544 tNode = tNode->mNext;\r
1545 }\r
1546\r
1547 if (tNode->mNext == NULL) {\r
1548 //\r
1549 // invalid IfrCode, IfrCode end by EndOpCode\r
1550 // \r
1551 gCVfrErrorHandle.PrintMsg (0, NULL, "Error", "No found End Opcode in the end");\r
1552 Status = VFR_RETURN_MISMATCHED;\r
1553 break;\r
1554 }\r
1555 \r
1556 if (tOpHead->OpCode != EFI_IFR_END_OP) {\r
1557 //\r
1558 // not new added varstore, which are not needed to be adjust.\r
1559 //\r
1560 preNode = tNode;\r
1561 pNode = tNode->mNext;\r
1562 continue; \r
1563 } else {\r
1564 //\r
1565 // move new added varstore opcode to the position befor form opcode \r
1566 // varstore opcode between pNode and tNode\r
1567 //\r
1568\r
1569 //\r
1570 // search form opcode from begin\r
1571 //\r
1572 for (uNode = mIfrRecordListHead; uNode->mNext != NULL; uNode = uNode->mNext) {\r
1573 tOpHead = (EFI_IFR_OP_HEADER *) uNode->mNext->mIfrBinBuf;\r
1574 if (tOpHead->OpCode == EFI_IFR_FORM_OP) {\r
1575 break;\r
1576 }\r
1577 }\r
1578 //\r
1579 // Insert varstore opcode beform form opcode if form opcode is found\r
1580 //\r
1581 if (uNode->mNext != NULL) {\r
1582 preNode->mNext = tNode->mNext;\r
1583 tNode->mNext = uNode->mNext;\r
1584 uNode->mNext = pNode;\r
1585 //\r
1586 // reset pNode to head list, scan the whole list again.\r
1587 //\r
1588 pNode = mIfrRecordListHead;\r
1589 preNode = pNode;\r
1590 QuestionScope = 0;\r
1591 continue;\r
1592 } else {\r
1593 //\r
1594 // not found form, continue scan IfrRecord list\r
1595 //\r
1596 preNode = tNode;\r
1597 pNode = tNode->mNext;\r
1598 continue;\r
1599 }\r
1600 }\r
1601 }\r
1602 //\r
1603 // next node\r
1604 //\r
1605 preNode = pNode;\r
1606 pNode = pNode->mNext; \r
1607 }\r
1608 \r
1609 //\r
1610 // Update Ifr Opcode Offset\r
1611 //\r
1612 if (Status == VFR_RETURN_SUCCESS) {\r
4afd3d04 1613 IfrAdjustOffsetForRecord ();\r
30fdf114
LG
1614 }\r
1615 return Status;\r
1616}\r
1617\r
74bbe31b
DB
1618/**\r
1619 When the Varstore of the question is EFI_VFR_VARSTORE_BUFFER and the default value is not\r
1620 given by expression, should save the default info for the Buffer VarStore.\r
1621\r
1622 @param DefaultId The default id.\r
1623 @param pQuestionNode Point to the question opcode node.\r
1624 @param Value The default value.\r
1625**/\r
1626VOID\r
1627CIfrRecordInfoDB::IfrAddDefaultToBufferConfig (\r
1628 IN UINT16 DefaultId,\r
1629 IN SIfrRecord *pQuestionNode,\r
1630 IN EFI_IFR_TYPE_VALUE Value\r
1631 )\r
1632{\r
1633 CHAR8 *VarStoreName = NULL;\r
1634 EFI_VFR_VARSTORE_TYPE VarStoreType = EFI_VFR_VARSTORE_INVALID;\r
1635 EFI_GUID *VarGuid = NULL;\r
1636 EFI_VARSTORE_INFO VarInfo;\r
1637 EFI_IFR_QUESTION_HEADER *QuestionHead;\r
1638 EFI_IFR_OP_HEADER *pQuestionOpHead;\r
1639\r
1640 pQuestionOpHead = (EFI_IFR_OP_HEADER *) pQuestionNode->mIfrBinBuf;\r
1641 QuestionHead = (EFI_IFR_QUESTION_HEADER *) (pQuestionOpHead + 1);\r
1642\r
1643 //\r
1644 // Get the Var Store name and type.\r
1645 //\r
1646 gCVfrDataStorage.GetVarStoreName (QuestionHead->VarStoreId, &VarStoreName);\r
1647 VarGuid= gCVfrDataStorage.GetVarStoreGuid (QuestionHead->VarStoreId);\r
1648 VarStoreType = gCVfrDataStorage.GetVarStoreType (QuestionHead->VarStoreId);\r
1649\r
1650 //\r
1651 // Only for Buffer storage need to save the default info in the storage.\r
1652 // Other type storage, just return.\r
1653 //\r
1654 if (VarStoreType != EFI_VFR_VARSTORE_BUFFER) {\r
1655 return;\r
1656 } else {\r
1657 VarInfo.mInfo.mVarOffset = QuestionHead->VarStoreInfo.VarOffset;\r
1658 VarInfo.mVarStoreId = QuestionHead->VarStoreId;\r
1659 }\r
1660\r
1661 //\r
1662 // Get the buffer storage info about this question.\r
1663 //\r
1664 gCVfrDataStorage.GetBufferVarStoreFieldInfo (&VarInfo);\r
1665\r
1666 //\r
1667 // Add action.\r
1668 //\r
1669 gCVfrDefaultStore.BufferVarStoreAltConfigAdd (\r
1670 DefaultId,\r
1671 VarInfo,\r
1672 VarStoreName,\r
1673 VarGuid,\r
1674 VarInfo.mVarType,\r
1675 Value\r
1676 );\r
1677}\r
1678\r
1679/**\r
1680 Record the number and default id of all defaultstore opcode.\r
1681\r
1682**/\r
1683VOID\r
1684CIfrRecordInfoDB::IfrGetDefaultStoreInfo (\r
1685 VOID\r
1686 )\r
1687{\r
1688 SIfrRecord *pNode;\r
1689 EFI_IFR_OP_HEADER *pOpHead;\r
1690 EFI_IFR_DEFAULTSTORE *DefaultStore;\r
1691\r
1692 pNode = mIfrRecordListHead;\r
1693 mAllDefaultTypeCount = 0;\r
1694\r
1695 while (pNode != NULL) {\r
1696 pOpHead = (EFI_IFR_OP_HEADER *) pNode->mIfrBinBuf;\r
1697\r
1698 if (pOpHead->OpCode == EFI_IFR_DEFAULTSTORE_OP){\r
1699 DefaultStore = (EFI_IFR_DEFAULTSTORE *) pNode->mIfrBinBuf;\r
1700 mAllDefaultIdArray[mAllDefaultTypeCount++] = DefaultStore->DefaultId;\r
1701 }\r
1702 pNode = pNode->mNext;\r
1703 }\r
1704}\r
1705\r
1706/**\r
1707 Create new default opcode record.\r
1708\r
1709 @param Size The new default opcode size.\r
1710 @param DefaultId The new default id.\r
1711 @param Type The new default type.\r
1712 @param LineNo The line number of the new record.\r
1713 @param Value The new default value.\r
1714\r
1715**/\r
1716VOID\r
1717CIfrRecordInfoDB::IfrCreateDefaultRecord(\r
1718 IN UINT8 Size,\r
1719 IN UINT16 DefaultId,\r
1720 IN UINT8 Type,\r
1721 IN UINT32 LineNo,\r
1722 IN EFI_IFR_TYPE_VALUE Value\r
1723 )\r
1724{\r
1725 CIfrDefault *DObj;\r
1726 CIfrDefault2 *DObj2;\r
1727\r
1728 DObj = NULL;\r
1729 DObj2 = NULL;\r
1730\r
1731 if (Type == EFI_IFR_TYPE_OTHER) {\r
1732 DObj2 = new CIfrDefault2 (Size);\r
1733 DObj2->SetDefaultId(DefaultId);\r
1734 DObj2->SetType(Type);\r
1735 DObj2->SetLineNo(LineNo);\r
1736 DObj2->SetScope (1);\r
1737 delete DObj2;\r
1738 } else {\r
1739 DObj = new CIfrDefault (Size);\r
1740 DObj->SetDefaultId(DefaultId);\r
1741 DObj->SetType(Type);\r
1742 DObj->SetLineNo(LineNo);\r
1743 DObj->SetValue (Value);\r
1744 delete DObj;\r
1745 }\r
1746}\r
1747\r
1748/**\r
1749 Create new default opcode for question base on the QuestionDefaultInfo.\r
1750\r
1751 @param pQuestionNode Point to the question opcode Node.\r
1752 @param QuestionDefaultInfo Point to the QuestionDefaultInfo for current question.\r
1753\r
1754**/\r
1755VOID\r
1756CIfrRecordInfoDB::IfrCreateDefaultForQuestion (\r
1757 IN SIfrRecord *pQuestionNode,\r
1758 IN QuestionDefaultRecord *QuestionDefaultInfo\r
1759 )\r
1760{\r
1761 EFI_IFR_OP_HEADER *pOpHead;\r
1762 EFI_IFR_DEFAULT *Default;\r
1763 SIfrRecord *pSNode;\r
1764 SIfrRecord *pENode;\r
1765 SIfrRecord *pDefaultNode;\r
1766 CIfrObj *Obj;\r
1767 CHAR8 *ObjBinBuf;\r
1768 UINT8 ScopeCount;\r
1769 UINT8 OpcodeNumber;\r
1770 UINT8 OpcodeCount;\r
1771 UINT8 DefaultSize;\r
1772 EFI_IFR_ONE_OF_OPTION *DefaultOptionOpcode;\r
1773 EFI_IFR_TYPE_VALUE CheckBoxDefaultValue;\r
1774\r
1775 CheckBoxDefaultValue.b = 1;\r
1776 pOpHead = (EFI_IFR_OP_HEADER *) pQuestionNode->mIfrBinBuf;\r
1777 ScopeCount = 0;\r
1778 OpcodeCount = 0;\r
1779 Obj = NULL;\r
1780\r
1781 //\r
1782 // Record the offset of node which need to be adjust, will move the new created default opcode to this offset.\r
1783 //\r
1784 gAdjustOpcodeOffset = pQuestionNode->mNext->mOffset;\r
1785 //\r
1786 // Case 1:\r
1787 // For oneof, the default with smallest default id is given by the option flag.\r
1788 // So create the missing defaults base on the oneof option value(mDefaultValueRecord).\r
1789 //\r
1790 if (pOpHead->OpCode == EFI_IFR_ONE_OF_OP && !QuestionDefaultInfo->mIsDefaultOpcode) {\r
1791 DefaultOptionOpcode = (EFI_IFR_ONE_OF_OPTION *)QuestionDefaultInfo->mDefaultValueRecord->mIfrBinBuf;\r
1792 DefaultSize = QuestionDefaultInfo->mDefaultValueRecord->mBinBufLen - OFFSET_OF (EFI_IFR_ONE_OF_OPTION, Value);\r
1793 DefaultSize += OFFSET_OF (EFI_IFR_DEFAULT, Value);\r
1794 for (UINT8 i = 0; i < mAllDefaultTypeCount; i++) {\r
1795 if (!QuestionDefaultInfo->mIsDefaultIdExist[i]) {\r
1796 IfrCreateDefaultRecord (DefaultSize, mAllDefaultIdArray[i], DefaultOptionOpcode->Type, pQuestionNode->mLineNo, DefaultOptionOpcode->Value);\r
1797 //\r
1798 // Save the new created default in the buffer storage.\r
1799 //\r
1800 IfrAddDefaultToBufferConfig (mAllDefaultIdArray[i], pQuestionNode, DefaultOptionOpcode->Value);\r
1801 }\r
1802 }\r
1803 return;\r
1804 }\r
1805\r
1806 //\r
1807 // Case2:\r
1808 // For checkbox, the default with smallest default id is given by the question flag.\r
1809 // And create the missing defaults with true value.\r
1810 //\r
1811 if (pOpHead-> OpCode == EFI_IFR_CHECKBOX_OP && !QuestionDefaultInfo->mIsDefaultOpcode) {\r
1812 DefaultSize = OFFSET_OF (EFI_IFR_DEFAULT, Value) + sizeof (BOOLEAN);\r
1813 for (UINT8 i = 0; i < mAllDefaultTypeCount; i++) {\r
1814 if (!QuestionDefaultInfo->mIsDefaultIdExist[i]) {\r
1815 IfrCreateDefaultRecord (DefaultSize, mAllDefaultIdArray[i], EFI_IFR_TYPE_BOOLEAN, pQuestionNode->mLineNo, CheckBoxDefaultValue);\r
1816 //\r
1817 // Save the new created default.\r
1818 //\r
1819 IfrAddDefaultToBufferConfig (mAllDefaultIdArray[i], pQuestionNode, CheckBoxDefaultValue);\r
1820 }\r
1821 }\r
1822 return;\r
1823 }\r
1824\r
1825 //\r
1826 // Case3:\r
1827 // The default with smallest default id is given by the default opcode.\r
1828 // So create the missing defaults base on the value in the default opcode.\r
1829 //\r
1830\r
1831 //\r
1832 // pDefaultNode point to the mDefaultValueRecord in QuestionDefaultInfo.\r
1833 //\r
1834 pDefaultNode = QuestionDefaultInfo->mDefaultValueRecord;\r
1835 Default = (EFI_IFR_DEFAULT *)pDefaultNode->mIfrBinBuf;\r
1836 //\r
1837 // Record the offset of node which need to be adjust, will move the new created default opcode to this offset.\r
1838 //\r
1839 gAdjustOpcodeOffset = pDefaultNode->mNext->mOffset;\r
1840\r
1841 if (Default->Type == EFI_IFR_TYPE_OTHER) {\r
1842 //\r
1843 // EFI_IFR_DEFAULT_2 opcode.\r
1844 //\r
1845 // Point to the first expression opcode.\r
1846 //\r
1847 pSNode = pDefaultNode->mNext;\r
61eb9834 1848 pENode = NULL;\r
74bbe31b
DB
1849 ScopeCount++;\r
1850 //\r
1851 // Get opcode number behind the EFI_IFR_DEFAULT_2 until reach its END opcode (including the END opcode of EFI_IFR_DEFAULT_2)\r
1852 //\r
1853 while (pSNode != NULL && pSNode->mNext != NULL && ScopeCount != 0) {\r
1854 pOpHead = (EFI_IFR_OP_HEADER *) pSNode->mIfrBinBuf;\r
1855 if (pOpHead->Scope == 1) {\r
1856 ScopeCount++;\r
1857 }\r
1858 if (pOpHead->OpCode == EFI_IFR_END_OP) {\r
1859 ScopeCount--;\r
1860 }\r
1861 pENode = pSNode;\r
1862 pSNode = pSNode->mNext;\r
1863 OpcodeCount++;\r
1864 }\r
9b78c54a
HW
1865\r
1866 assert (pSNode);\r
1867 assert (pENode);\r
1868\r
74bbe31b
DB
1869 //\r
1870 // Record the offset of node which need to be adjust, will move the new created default opcode to this offset.\r
1871 //\r
1872 gAdjustOpcodeOffset = pSNode->mOffset;\r
1873 //\r
1874 // Create new default opcode node for missing default.\r
1875 //\r
1876 for (UINT8 i = 0; i < mAllDefaultTypeCount; i++) {\r
1877 OpcodeNumber = OpcodeCount;\r
1878 if (!QuestionDefaultInfo->mIsDefaultIdExist[i]) {\r
1879 IfrCreateDefaultRecord (Default->Header.Length, mAllDefaultIdArray[i], Default->Type, pENode->mLineNo, Default->Value);\r
1880 //\r
1881 // Point to the first expression opcode node.\r
1882 //\r
1883 pSNode = pDefaultNode->mNext;\r
1884 //\r
1885 // Create the expression opcode and end opcode for the new created EFI_IFR_DEFAULT_2 opcode.\r
1886 //\r
1887 while (pSNode != NULL && pSNode->mNext != NULL && OpcodeNumber-- != 0) {\r
1888 pOpHead = (EFI_IFR_OP_HEADER *) pSNode->mIfrBinBuf;\r
1889 Obj = new CIfrObj (pOpHead->OpCode, NULL, pSNode->mBinBufLen, FALSE);\r
9b78c54a 1890 assert (Obj != NULL);\r
74bbe31b
DB
1891 Obj->SetLineNo (pSNode->mLineNo);\r
1892 ObjBinBuf = Obj->GetObjBinAddr();\r
1893 memcpy (ObjBinBuf, pSNode->mIfrBinBuf, (UINTN)pSNode->mBinBufLen);\r
1894 delete Obj;\r
1895 pSNode = pSNode->mNext;\r
1896 }\r
1897 }\r
1898 }\r
1899 } else {\r
1900 //\r
1901 // EFI_IFR_DEFAULT opcode.\r
1902 //\r
1903 // Create new default opcode node for missing default.\r
1904 //\r
1905 for (UINT8 i = 0; i < mAllDefaultTypeCount; i++) {\r
1906 if (!QuestionDefaultInfo->mIsDefaultIdExist[i]) {\r
1907 IfrCreateDefaultRecord (Default->Header.Length, mAllDefaultIdArray[i], Default->Type, pDefaultNode->mLineNo, Default->Value);\r
1908 //\r
1909 // Save the new created default in the buffer storage..\r
1910 //\r
1911 IfrAddDefaultToBufferConfig (mAllDefaultIdArray[i], pQuestionNode, Default->Value);\r
1912 }\r
1913 }\r
1914 }\r
1915}\r
1916\r
1917/**\r
1918 Parse the default information in a question, get the QuestionDefaultInfo.\r
1919\r
1920 @param pQuestionNode Point to the question record Node.\r
1921 @param QuestionDefaultInfo On return, point to the QuestionDefaultInfo.\r
1922**/\r
1923VOID\r
1924CIfrRecordInfoDB::IfrParseDefaulInfoInQuestion(\r
1925 IN SIfrRecord *pQuestionNode,\r
1926 OUT QuestionDefaultRecord *QuestionDefaultInfo\r
1927 )\r
1928{\r
1929 SIfrRecord *pSNode;\r
1930 EFI_IFR_ONE_OF_OPTION *OneofOptionOpcode;\r
1931 EFI_IFR_OP_HEADER *pSOpHead;\r
1932 EFI_IFR_CHECKBOX *CheckBoxOpcode;\r
1933 EFI_IFR_DEFAULT *DefaultOpcode;\r
1934 BOOLEAN IsOneOfOpcode;\r
1935 UINT16 SmallestDefaultId;\r
1936 UINT8 ScopeCount;\r
1937\r
1938 SmallestDefaultId = 0xffff;\r
1939 IsOneOfOpcode = FALSE;\r
1940 ScopeCount = 0;\r
1941 pSNode = pQuestionNode;\r
1942\r
1943 //\r
1944 // Parse all the opcodes in the Question.\r
1945 //\r
1946 while (pSNode != NULL) {\r
1947 pSOpHead = (EFI_IFR_OP_HEADER *) pSNode->mIfrBinBuf;\r
1948 //\r
1949 // For a question, its scope bit must be set, the scope exists until it reaches a corresponding EFI_IFR_END_OP.\r
1950 // Scopes may be nested within other scopes.\r
1951 // When finishing parsing a question, the scope count must be zero.\r
1952 //\r
1953 if (pSOpHead->Scope == 1) {\r
1954 ScopeCount++;\r
1955 }\r
1956 if (pSOpHead->OpCode == EFI_IFR_END_OP) {\r
1957 ScopeCount--;\r
1958 }\r
1959 //\r
1960 // Check whether finishing parsing a question.\r
1961 //\r
1962 if (ScopeCount == 0) {\r
1963 break;\r
1964 }\r
1965\r
1966 //\r
1967 // Record the default information in the question.\r
1968 //\r
1969 switch (pSOpHead->OpCode) {\r
1970 case EFI_IFR_ONE_OF_OP:\r
1971 IsOneOfOpcode = TRUE;\r
1972 break;\r
1973 case EFI_IFR_CHECKBOX_OP:\r
1974 //\r
1975 // The default info of check box may be given by flag.\r
1976 // So need to check the flag of check box.\r
1977 //\r
1978 CheckBoxOpcode = (EFI_IFR_CHECKBOX *)pSNode->mIfrBinBuf;\r
1979 if ((CheckBoxOpcode->Flags & EFI_IFR_CHECKBOX_DEFAULT) != 0) {\r
1980 //\r
1981 // Check whether need to update the smallest default id.\r
1982 //\r
1983 if (SmallestDefaultId > EFI_HII_DEFAULT_CLASS_STANDARD) {\r
1984 SmallestDefaultId = EFI_HII_DEFAULT_CLASS_STANDARD;\r
1985 }\r
1986 //\r
1987 // Update the QuestionDefaultInfo.\r
1988 //\r
1989 for (UINT8 i = 0; i < mAllDefaultTypeCount; i++) {\r
1990 if (mAllDefaultIdArray[i] == EFI_HII_DEFAULT_CLASS_STANDARD) {\r
1991 if (!QuestionDefaultInfo->mIsDefaultIdExist[i]) {\r
1992 QuestionDefaultInfo->mDefaultNumber ++;\r
1993 QuestionDefaultInfo->mIsDefaultIdExist[i] = TRUE;\r
1994 }\r
1995 break;\r
1996 }\r
1997 }\r
1998 }\r
1999 if ((CheckBoxOpcode->Flags & EFI_IFR_CHECKBOX_DEFAULT_MFG) != 0) {\r
2000 //\r
2001 // Check whether need to update the smallest default id.\r
2002 //\r
2003 if (SmallestDefaultId > EFI_HII_DEFAULT_CLASS_MANUFACTURING) {\r
2004 SmallestDefaultId = EFI_HII_DEFAULT_CLASS_MANUFACTURING;\r
2005 }\r
2006 //\r
2007 // Update the QuestionDefaultInfo.\r
2008 //\r
2009 for (UINT8 i = 0; i < mAllDefaultTypeCount; i++) {\r
2010 if (mAllDefaultIdArray[i] == EFI_HII_DEFAULT_CLASS_MANUFACTURING) {\r
2011 if (!QuestionDefaultInfo->mIsDefaultIdExist[i]) {\r
2012 QuestionDefaultInfo->mDefaultNumber ++;\r
2013 QuestionDefaultInfo->mIsDefaultIdExist[i] = TRUE;\r
2014 }\r
2015 break;\r
2016 }\r
2017 }\r
2018 }\r
2019 break;\r
2020 case EFI_IFR_ONE_OF_OPTION_OP:\r
2021 if (!IsOneOfOpcode) {\r
2022 //\r
2023 // Only check the option in oneof.\r
2024 //\r
2025 break;\r
2026 }\r
2027 OneofOptionOpcode = (EFI_IFR_ONE_OF_OPTION *)pSNode->mIfrBinBuf;\r
2028 if ((OneofOptionOpcode->Flags & EFI_IFR_OPTION_DEFAULT) != 0) {\r
2029 //\r
2030 // The option is used as the standard default.\r
2031 // Check whether need to update the smallest default id and QuestionDefaultInfo.\r
2032 //\r
2033 if (SmallestDefaultId > EFI_HII_DEFAULT_CLASS_STANDARD) {\r
2034 SmallestDefaultId = EFI_HII_DEFAULT_CLASS_STANDARD;\r
2035 QuestionDefaultInfo->mDefaultValueRecord = pSNode;\r
2036 }\r
2037 //\r
2038 // Update the IsDefaultIdExist array in QuestionDefaultInfo.\r
2039 //\r
2040 for (UINT8 i = 0; i < mAllDefaultTypeCount; i++) {\r
2041 if (mAllDefaultIdArray[i] == EFI_HII_DEFAULT_CLASS_STANDARD) {\r
2042 if (!QuestionDefaultInfo->mIsDefaultIdExist[i]) {\r
2043 QuestionDefaultInfo->mDefaultNumber ++;\r
2044 QuestionDefaultInfo->mIsDefaultIdExist[i] = TRUE;\r
2045 }\r
2046 break;\r
2047 }\r
2048 }\r
2049 }\r
2050 if ((OneofOptionOpcode->Flags & EFI_IFR_OPTION_DEFAULT_MFG) != 0) {\r
2051 //\r
2052 // This option is used as the manufacture default.\r
2053 // Check whether need to update the smallest default id and QuestionDefaultInfo.\r
2054 //\r
2055 if (SmallestDefaultId > EFI_HII_DEFAULT_CLASS_MANUFACTURING) {\r
2056 SmallestDefaultId = EFI_HII_DEFAULT_CLASS_MANUFACTURING;\r
2057 QuestionDefaultInfo->mDefaultValueRecord = pSNode;\r
2058 }\r
2059 //\r
2060 // Update the QuestionDefaultInfo.\r
2061 //\r
2062 for (UINT8 i = 0; i < mAllDefaultTypeCount; i++) {\r
2063 if (mAllDefaultIdArray[i] == EFI_HII_DEFAULT_CLASS_MANUFACTURING) {\r
2064 if (!QuestionDefaultInfo->mIsDefaultIdExist[i]) {\r
2065 QuestionDefaultInfo->mDefaultNumber ++;\r
2066 QuestionDefaultInfo->mIsDefaultIdExist[i] = TRUE;\r
2067 }\r
2068 break;\r
2069 }\r
2070 }\r
2071 }\r
2072 break;\r
2073 case EFI_IFR_DEFAULT_OP:\r
2074 DefaultOpcode = (EFI_IFR_DEFAULT *) pSNode->mIfrBinBuf;\r
2075 //\r
2076 // Check whether need to update the smallest default id and QuestionDefaultInfo.\r
2077 //\r
2078 if (SmallestDefaultId >= DefaultOpcode->DefaultId ) {\r
2079 SmallestDefaultId = DefaultOpcode->DefaultId;\r
2080 QuestionDefaultInfo->mDefaultValueRecord= pSNode;\r
2081 QuestionDefaultInfo->mIsDefaultOpcode= TRUE;\r
2082 }\r
2083 //\r
2084 // Update the QuestionDefaultInfo.\r
2085 //\r
2086 for (UINT8 i = 0; i < mAllDefaultTypeCount; i++){\r
2087 if (mAllDefaultIdArray[i] == ((EFI_IFR_DEFAULT *)pSNode->mIfrBinBuf)->DefaultId) {\r
2088 if (!QuestionDefaultInfo->mIsDefaultIdExist[i]) {\r
2089 QuestionDefaultInfo->mDefaultNumber ++;\r
2090 QuestionDefaultInfo->mIsDefaultIdExist[i] = TRUE;\r
2091 }\r
2092 break;\r
2093 }\r
2094 }\r
2095 break;\r
2096 default:\r
2097 break;\r
2098 }\r
2099 //\r
2100 // Parse next opcode in this question.\r
2101 //\r
2102 pSNode = pSNode->mNext;\r
2103 }\r
2104}\r
2105\r
2106/**\r
2107 Check or add default for question if need.\r
2108\r
2109 This function will check the default info for question.\r
2110 If the question has default, but the default number < defaultstore opcode number.\r
2111 will do following two action :\r
2112\r
2113 1. if (AutoDefault) will add default for question to support all kinds of defaults.\r
2114 2. if (CheckDefault) will generate an error to tell user the question misses some default value.\r
2115\r
2116 We assume that the two options can not be TRUE at same time.\r
2117 If they are TRUE at same time, only do the action corresponding to AutoDefault option.\r
2118\r
2119 @param AutoDefault Add default for question if needed\r
2120 @param CheckDefault Check the default info, if missing default, generates an error.\r
2121\r
2122**/\r
2123VOID\r
2124CIfrRecordInfoDB::IfrCheckAddDefaultRecord (\r
2125 BOOLEAN AutoDefault,\r
2126 BOOLEAN CheckDefault\r
2127 )\r
2128{\r
2129 SIfrRecord *pNode;\r
2130 SIfrRecord *pTailNode;\r
2131 SIfrRecord *pStartAdjustNode;\r
2132 EFI_IFR_OP_HEADER *pOpHead;\r
2133 QuestionDefaultRecord QuestionDefaultInfo;\r
2134 UINT8 MissingDefaultCount;\r
2135 CHAR8 Msg[MAX_STRING_LEN] = {0, };\r
2136\r
2137 pNode = mIfrRecordListHead;\r
2138\r
2139 //\r
2140 // Record the number and default id of all defaultstore opcode.\r
2141 //\r
2142 IfrGetDefaultStoreInfo ();\r
2143\r
2144 while (pNode != NULL) {\r
2145 pOpHead = (EFI_IFR_OP_HEADER *) pNode->mIfrBinBuf;\r
2146 //\r
2147 // Check whether is question opcode.\r
2148 //\r
2149 if (CheckQuestionOpCode (pOpHead->OpCode)) {\r
2150 //\r
2151 // Initialize some local variables here, because they vary with question.\r
2152 // Record the mIfrRecordListTail for each question, because may create default node for question after mIfrRecordListTail.\r
2153 //\r
2154 memset (&QuestionDefaultInfo, 0, sizeof (QuestionDefaultRecord));\r
2155 pTailNode = mIfrRecordListTail;\r
2156 //\r
2157 // Get the QuestionDefaultInfo for current question.\r
2158 //\r
2159 IfrParseDefaulInfoInQuestion (pNode, &QuestionDefaultInfo);\r
2160\r
2161 if (QuestionDefaultInfo.mDefaultNumber != mAllDefaultTypeCount && QuestionDefaultInfo.mDefaultNumber != 0) {\r
2162 if (AutoDefault) {\r
2163 //\r
2164 // Create default for question which misses default.\r
2165 //\r
2166 IfrCreateDefaultForQuestion (pNode, &QuestionDefaultInfo);\r
2167\r
2168 //\r
2169 // Adjust the buffer content.\r
2170 // pStartAdjustNode->mIfrBinBuf points to the insert position.\r
2171 // pTailNode->mNext->mIfrBinBuf points to the inset opcodes.\r
2172 //\r
2173 pStartAdjustNode =GetRecordInfoFromOffset (gAdjustOpcodeOffset);\r
2174 gCFormPkg.AdjustDynamicInsertOpcode (pStartAdjustNode->mIfrBinBuf, pTailNode->mNext->mIfrBinBuf, TRUE);\r
2175\r
2176 //\r
2177 // Update the record info.\r
2178 //\r
2179 IfrUpdateRecordInfoForDynamicOpcode (TRUE);\r
2180 } else if (CheckDefault) {\r
2181 //\r
2182 // Generate an error for question which misses default.\r
2183 //\r
2184 MissingDefaultCount = mAllDefaultTypeCount - QuestionDefaultInfo.mDefaultNumber;\r
2185 sprintf (Msg, "The question misses %d default, the question's opcode is %d", MissingDefaultCount, pOpHead->OpCode);\r
2186 gCVfrErrorHandle.PrintMsg (pNode->mLineNo, NULL, "Error", Msg);\r
2187 }\r
2188 }\r
2189 }\r
2190 //\r
2191 // parse next opcode.\r
2192 //\r
2193 pNode = pNode->mNext;\r
2194 }\r
2195}\r
2196\r
30fdf114
LG
2197CIfrRecordInfoDB gCIfrRecordInfoDB;\r
2198\r
2199VOID\r
2200CIfrObj::_EMIT_PENDING_OBJ (\r
2201 VOID\r
2202 )\r
2203{\r
2204 CHAR8 *ObjBinBuf = NULL;\r
2205 \r
2206 //\r
2207 // do nothing\r
2208 //\r
2209 if (!mDelayEmit || !gCreateOp) {\r
2210 return;\r
2211 }\r
2212\r
2213 mPkgOffset = gCFormPkg.GetPkgLength ();\r
2214 //\r
2215 // update data buffer to package data\r
2216 //\r
2217 ObjBinBuf = gCFormPkg.IfrBinBufferGet (mObjBinLen);\r
2218 if (ObjBinBuf != NULL) {\r
f51461c8 2219 memmove (ObjBinBuf, mObjBinBuf, mObjBinLen);\r
30fdf114
LG
2220 }\r
2221 \r
2222 //\r
2223 // update bin buffer to package data buffer\r
2224 //\r
2225 if (mObjBinBuf != NULL) {\r
2226 delete mObjBinBuf;\r
2227 mObjBinBuf = ObjBinBuf;\r
2228 }\r
2229 \r
2230 mDelayEmit = FALSE;\r
2231}\r
2232\r
2233/*\r
2234 * The definition of CIfrObj's member function\r
2235 */\r
2236static struct {\r
2237 UINT8 mSize;\r
2238 UINT8 mScope;\r
2239} gOpcodeSizesScopeTable[] = {\r
2240 { 0, 0 }, // EFI_IFR_INVALID - 0x00\r
2241 { sizeof (EFI_IFR_FORM), 1 }, // EFI_IFR_FORM_OP\r
2242 { sizeof (EFI_IFR_SUBTITLE), 1 }, // EFI_IFR_SUBTITLE_OP\r
2243 { sizeof (EFI_IFR_TEXT), 0 }, // EFI_IFR_TEXT_OP\r
2244 { sizeof (EFI_IFR_IMAGE), 0 }, // EFI_IFR_IMAGE_OP\r
2245 { sizeof (EFI_IFR_ONE_OF), 1 }, // EFI_IFR_ONE_OF_OP - 0x05\r
2246 { sizeof (EFI_IFR_CHECKBOX), 1}, // EFI_IFR_CHECKBOX_OP\r
2247 { sizeof (EFI_IFR_NUMERIC), 1 }, // EFI_IFR_NUMERIC_OP\r
2248 { sizeof (EFI_IFR_PASSWORD), 1 }, // EFI_IFR_PASSWORD_OP\r
2249 { sizeof (EFI_IFR_ONE_OF_OPTION), 0 }, // EFI_IFR_ONE_OF_OPTION_OP\r
2250 { sizeof (EFI_IFR_SUPPRESS_IF), 1 }, // EFI_IFR_SUPPRESS_IF - 0x0A\r
2251 { sizeof (EFI_IFR_LOCKED), 0 }, // EFI_IFR_LOCKED_OP\r
2252 { sizeof (EFI_IFR_ACTION), 1 }, // EFI_IFR_ACTION_OP\r
2253 { sizeof (EFI_IFR_RESET_BUTTON), 1 }, // EFI_IFR_RESET_BUTTON_OP\r
2254 { sizeof (EFI_IFR_FORM_SET), 1 }, // EFI_IFR_FORM_SET_OP -0xE\r
2255 { sizeof (EFI_IFR_REF), 0 }, // EFI_IFR_REF_OP\r
2256 { sizeof (EFI_IFR_NO_SUBMIT_IF), 1}, // EFI_IFR_NO_SUBMIT_IF_OP -0x10\r
2257 { sizeof (EFI_IFR_INCONSISTENT_IF), 1 }, // EFI_IFR_INCONSISTENT_IF_OP\r
2258 { sizeof (EFI_IFR_EQ_ID_VAL), 0 }, // EFI_IFR_EQ_ID_VAL_OP\r
2259 { sizeof (EFI_IFR_EQ_ID_ID), 0 }, // EFI_IFR_EQ_ID_ID_OP\r
b303ea72 2260 { sizeof (EFI_IFR_EQ_ID_VAL_LIST), 0 }, // EFI_IFR_EQ_ID_LIST_OP - 0x14\r
30fdf114
LG
2261 { sizeof (EFI_IFR_AND), 0 }, // EFI_IFR_AND_OP\r
2262 { sizeof (EFI_IFR_OR), 0 }, // EFI_IFR_OR_OP\r
2263 { sizeof (EFI_IFR_NOT), 0 }, // EFI_IFR_NOT_OP\r
2264 { sizeof (EFI_IFR_RULE), 1 }, // EFI_IFR_RULE_OP\r
2265 { sizeof (EFI_IFR_GRAY_OUT_IF), 1 }, // EFI_IFR_GRAYOUT_IF_OP - 0x19\r
2266 { sizeof (EFI_IFR_DATE), 1 }, // EFI_IFR_DATE_OP\r
2267 { sizeof (EFI_IFR_TIME), 1 }, // EFI_IFR_TIME_OP\r
2268 { sizeof (EFI_IFR_STRING), 1 }, // EFI_IFR_STRING_OP\r
2269 { sizeof (EFI_IFR_REFRESH), 0 }, // EFI_IFR_REFRESH_OP\r
2270 { sizeof (EFI_IFR_DISABLE_IF), 1 }, // EFI_IFR_DISABLE_IF_OP - 0x1E\r
2271 { 0, 0 }, // 0x1F\r
2272 { sizeof (EFI_IFR_TO_LOWER), 0 }, // EFI_IFR_TO_LOWER_OP - 0x20\r
2273 { sizeof (EFI_IFR_TO_UPPER), 0 }, // EFI_IFR_TO_UPPER_OP - 0x21\r
52302d4d 2274 { sizeof (EFI_IFR_MAP), 1 }, // EFI_IFR_MAP - 0x22\r
30fdf114
LG
2275 { sizeof (EFI_IFR_ORDERED_LIST), 1 }, // EFI_IFR_ORDERED_LIST_OP - 0x23\r
2276 { sizeof (EFI_IFR_VARSTORE), 0 }, // EFI_IFR_VARSTORE_OP\r
2277 { sizeof (EFI_IFR_VARSTORE_NAME_VALUE), 0 }, // EFI_IFR_VARSTORE_NAME_VALUE_OP\r
2278 { sizeof (EFI_IFR_VARSTORE_EFI), 0 }, // EFI_IFR_VARSTORE_EFI_OP\r
2279 { sizeof (EFI_IFR_VARSTORE_DEVICE), 1 }, // EFI_IFR_VARSTORE_DEVICE_OP\r
2280 { sizeof (EFI_IFR_VERSION), 0 }, // EFI_IFR_VERSION_OP - 0x28\r
2281 { sizeof (EFI_IFR_END), 0 }, // EFI_IFR_END_OP\r
52302d4d
LG
2282 { sizeof (EFI_IFR_MATCH), 0 }, // EFI_IFR_MATCH_OP - 0x2A\r
2283 { sizeof (EFI_IFR_GET), 0 }, // EFI_IFR_GET - 0x2B\r
2284 { sizeof (EFI_IFR_SET), 0 }, // EFI_IFR_SET - 0x2C\r
2285 { sizeof (EFI_IFR_READ), 0 }, // EFI_IFR_READ - 0x2D\r
2286 { sizeof (EFI_IFR_WRITE), 0 }, // EFI_IFR_WRITE - 0x2E\r
30fdf114
LG
2287 { sizeof (EFI_IFR_EQUAL), 0 }, // EFI_IFR_EQUAL_OP - 0x2F\r
2288 { sizeof (EFI_IFR_NOT_EQUAL), 0 }, // EFI_IFR_NOT_EQUAL_OP\r
2289 { sizeof (EFI_IFR_GREATER_THAN), 0 }, // EFI_IFR_GREATER_THAN_OP\r
2290 { sizeof (EFI_IFR_GREATER_EQUAL), 0 }, // EFI_IFR_GREATER_EQUAL_OP\r
2291 { sizeof (EFI_IFR_LESS_THAN), 0 }, // EFI_IFR_LESS_THAN_OP\r
2292 { sizeof (EFI_IFR_LESS_EQUAL), 0 }, // EFI_IFR_LESS_EQUAL_OP - 0x34\r
2293 { sizeof (EFI_IFR_BITWISE_AND), 0 }, // EFI_IFR_BITWISE_AND_OP\r
2294 { sizeof (EFI_IFR_BITWISE_OR), 0 }, // EFI_IFR_BITWISE_OR_OP\r
2295 { sizeof (EFI_IFR_BITWISE_NOT), 0 }, // EFI_IFR_BITWISE_NOT_OP\r
2296 { sizeof (EFI_IFR_SHIFT_LEFT), 0 }, // EFI_IFR_SHIFT_LEFT_OP\r
2297 { sizeof (EFI_IFR_SHIFT_RIGHT), 0 }, // EFI_IFR_SHIFT_RIGHT_OP\r
2298 { sizeof (EFI_IFR_ADD), 0 }, // EFI_IFR_ADD_OP - 0x3A\r
2299 { sizeof (EFI_IFR_SUBTRACT), 0 }, // EFI_IFR_SUBTRACT_OP\r
2300 { sizeof (EFI_IFR_MULTIPLY), 0 }, // EFI_IFR_MULTIPLY_OP\r
2301 { sizeof (EFI_IFR_DIVIDE), 0 }, // EFI_IFR_DIVIDE_OP\r
2302 { sizeof (EFI_IFR_MODULO), 0 }, // EFI_IFR_MODULO_OP - 0x3E\r
2303 { sizeof (EFI_IFR_RULE_REF), 0 }, // EFI_IFR_RULE_REF_OP\r
2304 { sizeof (EFI_IFR_QUESTION_REF1), 0 }, // EFI_IFR_QUESTION_REF1_OP\r
2305 { sizeof (EFI_IFR_QUESTION_REF2), 0 }, // EFI_IFR_QUESTION_REF2_OP - 0x41\r
2306 { sizeof (EFI_IFR_UINT8), 0}, // EFI_IFR_UINT8\r
2307 { sizeof (EFI_IFR_UINT16), 0}, // EFI_IFR_UINT16\r
2308 { sizeof (EFI_IFR_UINT32), 0}, // EFI_IFR_UINT32\r
2309 { sizeof (EFI_IFR_UINT64), 0}, // EFI_IFR_UTNT64\r
2310 { sizeof (EFI_IFR_TRUE), 0 }, // EFI_IFR_TRUE_OP - 0x46\r
2311 { sizeof (EFI_IFR_FALSE), 0 }, // EFI_IFR_FALSE_OP\r
2312 { sizeof (EFI_IFR_TO_UINT), 0 }, // EFI_IFR_TO_UINT_OP\r
2313 { sizeof (EFI_IFR_TO_STRING), 0 }, // EFI_IFR_TO_STRING_OP\r
2314 { sizeof (EFI_IFR_TO_BOOLEAN), 0 }, // EFI_IFR_TO_BOOLEAN_OP\r
2315 { sizeof (EFI_IFR_MID), 0 }, // EFI_IFR_MID_OP\r
2316 { sizeof (EFI_IFR_FIND), 0 }, // EFI_IFR_FIND_OP\r
2317 { sizeof (EFI_IFR_TOKEN), 0 }, // EFI_IFR_TOKEN_OP\r
2318 { sizeof (EFI_IFR_STRING_REF1), 0 }, // EFI_IFR_STRING_REF1_OP - 0x4E\r
2319 { sizeof (EFI_IFR_STRING_REF2), 0 }, // EFI_IFR_STRING_REF2_OP\r
2320 { sizeof (EFI_IFR_CONDITIONAL), 0 }, // EFI_IFR_CONDITIONAL_OP\r
2321 { sizeof (EFI_IFR_QUESTION_REF3), 0 }, // EFI_IFR_QUESTION_REF3_OP\r
2322 { sizeof (EFI_IFR_ZERO), 0 }, // EFI_IFR_ZERO_OP\r
2323 { sizeof (EFI_IFR_ONE), 0 }, // EFI_IFR_ONE_OP\r
2324 { sizeof (EFI_IFR_ONES), 0 }, // EFI_IFR_ONES_OP\r
2325 { sizeof (EFI_IFR_UNDEFINED), 0 }, // EFI_IFR_UNDEFINED_OP\r
2326 { sizeof (EFI_IFR_LENGTH), 0 }, // EFI_IFR_LENGTH_OP\r
2327 { sizeof (EFI_IFR_DUP), 0 }, // EFI_IFR_DUP_OP - 0x57\r
2328 { sizeof (EFI_IFR_THIS), 0 }, // EFI_IFR_THIS_OP\r
2329 { sizeof (EFI_IFR_SPAN), 0 }, // EFI_IFR_SPAN_OP\r
2330 { sizeof (EFI_IFR_VALUE), 1 }, // EFI_IFR_VALUE_OP\r
2331 { sizeof (EFI_IFR_DEFAULT), 0 }, // EFI_IFR_DEFAULT_OP\r
2332 { sizeof (EFI_IFR_DEFAULTSTORE), 0 }, // EFI_IFR_DEFAULTSTORE_OP - 0x5C\r
52302d4d 2333 { sizeof (EFI_IFR_FORM_MAP), 1}, // EFI_IFR_FORM_MAP_OP - 0x5D\r
30fdf114
LG
2334 { sizeof (EFI_IFR_CATENATE), 0 }, // EFI_IFR_CATENATE_OP\r
2335 { sizeof (EFI_IFR_GUID), 0 }, // EFI_IFR_GUID_OP\r
a709adfa 2336 { sizeof (EFI_IFR_SECURITY), 0 }, // EFI_IFR_SECURITY_OP - 0x60\r
4afd3d04 2337 { sizeof (EFI_IFR_MODAL_TAG), 0}, // EFI_IFR_MODAL_TAG_OP - 0x61\r
4234283c 2338 { sizeof (EFI_IFR_REFRESH_ID), 0}, // EFI_IFR_REFRESH_ID_OP - 0x62\r
ea0f6464 2339 { sizeof (EFI_IFR_WARNING_IF), 1}, // EFI_IFR_WARNING_IF_OP - 0x63\r
5d377616 2340 { sizeof (EFI_IFR_MATCH2), 0 }, // EFI_IFR_MATCH2_OP - 0x64\r
30fdf114
LG
2341};\r
2342\r
2343#ifdef CIFROBJ_DEUBG\r
2344static struct {\r
2345 CHAR8 *mIfrName;\r
2346} gIfrObjPrintDebugTable[] = {\r
2347 "EFI_IFR_INVALID", "EFI_IFR_FORM", "EFI_IFR_SUBTITLE", "EFI_IFR_TEXT", "EFI_IFR_IMAGE", "EFI_IFR_ONE_OF",\r
2348 "EFI_IFR_CHECKBOX", "EFI_IFR_NUMERIC", "EFI_IFR_PASSWORD", "EFI_IFR_ONE_OF_OPTION", "EFI_IFR_SUPPRESS_IF", "EFI_IFR_LOCKED",\r
2349 "EFI_IFR_ACTION", "EFI_IFR_RESET_BUTTON", "EFI_IFR_FORM_SET", "EFI_IFR_REF", "EFI_IFR_NO_SUBMIT_IF", "EFI_IFR_INCONSISTENT_IF",\r
2350 "EFI_IFR_EQ_ID_VAL", "EFI_IFR_EQ_ID_ID", "EFI_IFR_EQ_ID_LIST", "EFI_IFR_AND", "EFI_IFR_OR", "EFI_IFR_NOT",\r
2351 "EFI_IFR_RULE", "EFI_IFR_GRAY_OUT_IF", "EFI_IFR_DATE", "EFI_IFR_TIME", "EFI_IFR_STRING", "EFI_IFR_REFRESH",\r
52302d4d 2352 "EFI_IFR_DISABLE_IF", "EFI_IFR_INVALID", "EFI_IFR_TO_LOWER", "EFI_IFR_TO_UPPER", "EFI_IFR_MAP", "EFI_IFR_ORDERED_LIST",\r
30fdf114 2353 "EFI_IFR_VARSTORE", "EFI_IFR_VARSTORE_NAME_VALUE", "EFI_IFR_VARSTORE_EFI", "EFI_IFR_VARSTORE_DEVICE", "EFI_IFR_VERSION", "EFI_IFR_END",\r
52302d4d 2354 "EFI_IFR_MATCH", "EFI_IFR_GET", "EFI_IFR_SET", "EFI_IFR_READ", "EFI_IFR_WRITE", "EFI_IFR_EQUAL",\r
30fdf114
LG
2355 "EFI_IFR_NOT_EQUAL", "EFI_IFR_GREATER_THAN", "EFI_IFR_GREATER_EQUAL", "EFI_IFR_LESS_THAN", "EFI_IFR_LESS_EQUAL", "EFI_IFR_BITWISE_AND",\r
2356 "EFI_IFR_BITWISE_OR", "EFI_IFR_BITWISE_NOT", "EFI_IFR_SHIFT_LEFT", "EFI_IFR_SHIFT_RIGHT", "EFI_IFR_ADD", "EFI_IFR_SUBTRACT",\r
2357 "EFI_IFR_MULTIPLY", "EFI_IFR_DIVIDE", "EFI_IFR_MODULO", "EFI_IFR_RULE_REF", "EFI_IFR_QUESTION_REF1", "EFI_IFR_QUESTION_REF2",\r
2358 "EFI_IFR_UINT8", "EFI_IFR_UINT16", "EFI_IFR_UINT32", "EFI_IFR_UINT64", "EFI_IFR_TRUE", "EFI_IFR_FALSE",\r
2359 "EFI_IFR_TO_UINT", "EFI_IFR_TO_STRING", "EFI_IFR_TO_BOOLEAN", "EFI_IFR_MID", "EFI_IFR_FIND", "EFI_IFR_TOKEN",\r
2360 "EFI_IFR_STRING_REF1","EFI_IFR_STRING_REF2", "EFI_IFR_CONDITIONAL", "EFI_IFR_QUESTION_REF3", "EFI_IFR_ZERO", "EFI_IFR_ONE",\r
2361 "EFI_IFR_ONES", "EFI_IFR_UNDEFINED", "EFI_IFR_LENGTH", "EFI_IFR_DUP", "EFI_IFR_THIS", "EFI_IFR_SPAN",\r
52302d4d 2362 "EFI_IFR_VALUE", "EFI_IFR_DEFAULT", "EFI_IFR_DEFAULTSTORE", "EFI_IFR_FORM_MAP", "EFI_IFR_CATENATE", "EFI_IFR_GUID",\r
5d377616 2363 "EFI_IFR_SECURITY", "EFI_IFR_MODAL_TAG", "EFI_IFR_REFRESH_ID", "EFI_IFR_WARNING_IF", "EFI_IFR_MATCH2",\r
30fdf114
LG
2364};\r
2365\r
2366VOID\r
2367CIFROBJ_DEBUG_PRINT (\r
2368 IN UINT8 OpCode\r
2369 )\r
2370{\r
2371 printf ("======Create IFR [%s]\n", gIfrObjPrintDebugTable[OpCode].mIfrName);\r
2372}\r
2373#else\r
2374\r
2375#define CIFROBJ_DEBUG_PRINT(OpCode)\r
2376\r
2377#endif\r
2378\r
52302d4d 2379BOOLEAN gCreateOp = TRUE;\r
30fdf114
LG
2380\r
2381CIfrObj::CIfrObj (\r
2382 IN UINT8 OpCode,\r
2383 OUT CHAR8 **IfrObj,\r
2384 IN UINT8 ObjBinLen,\r
2385 IN BOOLEAN DelayEmit\r
2386 )\r
2387{\r
2388 mDelayEmit = DelayEmit;\r
2389 mPkgOffset = gCFormPkg.GetPkgLength ();\r
2390 mObjBinLen = (ObjBinLen == 0) ? gOpcodeSizesScopeTable[OpCode].mSize : ObjBinLen;\r
2391 mObjBinBuf = ((DelayEmit == FALSE) && (gCreateOp == TRUE)) ? gCFormPkg.IfrBinBufferGet (mObjBinLen) : new CHAR8[EFI_IFR_MAX_LENGTH];\r
2392 mRecordIdx = (gCreateOp == TRUE) ? gCIfrRecordInfoDB.IfrRecordRegister (0xFFFFFFFF, mObjBinBuf, mObjBinLen, mPkgOffset) : EFI_IFR_RECORDINFO_IDX_INVALUD;\r
2393\r
9b78c54a
HW
2394 assert (mObjBinBuf != NULL);\r
2395\r
30fdf114
LG
2396 if (IfrObj != NULL) {\r
2397 *IfrObj = mObjBinBuf;\r
2398 }\r
2399\r
2400 CIFROBJ_DEBUG_PRINT (OpCode);\r
2401}\r
2402\r
2403CIfrObj::~CIfrObj (\r
2404 VOID\r
2405 )\r
2406{\r
2407 if ((mDelayEmit == TRUE) && ((gCreateOp == TRUE))) {\r
2408 _EMIT_PENDING_OBJ ();\r
2409 }\r
2410\r
2411 gCIfrRecordInfoDB.IfrRecordInfoUpdate (mRecordIdx, mLineNo, mObjBinBuf, mObjBinLen, mPkgOffset);\r
2412}\r
2413\r
2414/*\r
2415 * The definition of CIfrObj's member function\r
2416 */\r
2417UINT8 gScopeCount = 0;\r
2418\r
2419CIfrOpHeader::CIfrOpHeader (\r
2420 IN UINT8 OpCode,\r
2421 IN VOID *StartAddr,\r
2422 IN UINT8 Length\r
2423 ) : mHeader ((EFI_IFR_OP_HEADER *)StartAddr)\r
2424{\r
2425 mHeader->OpCode = OpCode;\r
2426 mHeader->Length = (Length == 0) ? gOpcodeSizesScopeTable[OpCode].mSize : Length;\r
2427 mHeader->Scope = (gOpcodeSizesScopeTable[OpCode].mScope + gScopeCount > 0) ? 1 : 0;\r
2428}\r
2429\r
2430CIfrOpHeader::CIfrOpHeader (\r
2431 IN CIfrOpHeader &OpHdr\r
2432 )\r
2433{\r
2434 mHeader = OpHdr.mHeader;\r
2435}\r
2436\r
52302d4d 2437UINT32 CIfrFormId::FormIdBitMap[EFI_FREE_FORM_ID_BITMAP_SIZE] = {0, };\r