1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439
|
/** @file
The implementation of HII expression.
Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
(C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "HiiInternal.h"
//
// Global stack used to evaluate boolean expressions
//
EFI_HII_VALUE *mOpCodeScopeStack = NULL;
EFI_HII_VALUE *mOpCodeScopeStackEnd = NULL;
EFI_HII_VALUE *mOpCodeScopeStackPointer = NULL;
//
// Stack used for Suppressif/grayoutif/disableif expression list.
//
HII_EXPRESSION **mFormExpressionStack = NULL;
HII_EXPRESSION **mFormExpressionEnd = NULL;
HII_EXPRESSION **mFormExpressionPointer = NULL;
HII_EXPRESSION **mStatementExpressionStack = NULL;
HII_EXPRESSION **mStatementExpressionEnd = NULL;
HII_EXPRESSION **mStatementExpressionPointer = NULL;
HII_EXPRESSION **mOptionExpressionStack = NULL;
HII_EXPRESSION **mOptionExpressionEnd = NULL;
HII_EXPRESSION **mOptionExpressionPointer = NULL;
//
// Stack used for the sub expresion in map expression.
//
EFI_HII_VALUE *mCurrentExpressionStack = NULL;
EFI_HII_VALUE *mCurrentExpressionEnd = NULL;
EFI_HII_VALUE *mCurrentExpressionPointer = NULL;
//
// Stack used for the map expression list.
//
EFI_HII_VALUE *mMapExpressionListStack = NULL;
EFI_HII_VALUE *mMapExpressionListEnd = NULL;
EFI_HII_VALUE *mMapExpressionListPointer = NULL;
//
// Stack used for dependency expression.
//
HII_DEPENDENCY_EXPRESSION **mExpressionDependencyStack = NULL;
HII_DEPENDENCY_EXPRESSION **mExpressionDependencyEnd = NULL;
HII_DEPENDENCY_EXPRESSION **mExpressionDependencyPointer = NULL;
/**
Grow size of the stack.
This is an internal function.
@param Stack On input: old stack; On output: new stack
@param StackPtr On input: old stack pointer; On output: new stack
pointer
@param StackEnd On input: old stack end; On output: new stack end
@retval EFI_SUCCESS Grow stack success.
@retval EFI_OUT_OF_RESOURCES No enough memory for stack space.
**/
EFI_STATUS
GrowStack (
IN OUT EFI_HII_VALUE **Stack,
IN OUT EFI_HII_VALUE **StackPtr,
IN OUT EFI_HII_VALUE **StackEnd
)
{
UINTN Size;
EFI_HII_VALUE *NewStack;
Size = EXPRESSION_STACK_SIZE_INCREMENT;
if (*StackPtr != NULL) {
Size = Size + (*StackEnd - *Stack);
}
NewStack = AllocatePool (Size * sizeof (EFI_HII_VALUE));
if (NewStack == NULL) {
return EFI_OUT_OF_RESOURCES;
}
if (*StackPtr != NULL) {
//
// Copy from Old Stack to the New Stack
//
CopyMem (
NewStack,
*Stack,
(*StackEnd - *Stack) * sizeof (EFI_HII_VALUE)
);
//
// Free The Old Stack
//
FreePool (*Stack);
}
//
// Make the Stack pointer point to the old data in the new stack
//
*StackPtr = NewStack + (*StackPtr - *Stack);
*Stack = NewStack;
*StackEnd = NewStack + Size;
return EFI_SUCCESS;
}
/**
Push an element onto the Boolean Stack.
@param Stack On input: old stack; On output: new stack
@param StackPtr On input: old stack pointer; On output: new stack
pointer
@param StackEnd On input: old stack end; On output: new stack end
@param Data Data to push.
@retval EFI_SUCCESS Push stack success.
**/
EFI_STATUS
PushStack (
IN OUT EFI_HII_VALUE **Stack,
IN OUT EFI_HII_VALUE **StackPtr,
IN OUT EFI_HII_VALUE **StackEnd,
IN EFI_HII_VALUE *Data
)
{
EFI_STATUS Status;
//
// Check for a stack overflow condition
//
if (*StackPtr >= *StackEnd) {
//
// Grow the stack
//
Status = GrowStack (Stack, StackPtr, StackEnd);
if (EFI_ERROR (Status)) {
return Status;
}
}
//
// Push the item onto the stack
//
CopyMem (*StackPtr, Data, sizeof (EFI_HII_VALUE));
if (Data->Type == EFI_IFR_TYPE_BUFFER) {
(*StackPtr)->Buffer = AllocateCopyPool (Data->BufferLen, Data->Buffer);
if ((*StackPtr)->Buffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
}
*StackPtr = *StackPtr + 1;
return EFI_SUCCESS;
}
/**
Pop an element from the stack.
@param Stack On input: old stack
@param StackPtr On input: old stack pointer; On output: new stack pointer
@param Data Data to pop.
@retval EFI_SUCCESS The value was popped onto the stack.
@retval EFI_ACCESS_DENIED The pop operation underflowed the stack
**/
EFI_STATUS
PopStack (
IN EFI_HII_VALUE *Stack,
IN OUT EFI_HII_VALUE **StackPtr,
OUT EFI_HII_VALUE *Data
)
{
//
// Check for a stack underflow condition
//
if (*StackPtr == Stack) {
return EFI_ACCESS_DENIED;
}
//
// Pop the item off the stack
//
*StackPtr = *StackPtr - 1;
CopyMem (Data, *StackPtr, sizeof (EFI_HII_VALUE));
return EFI_SUCCESS;
}
/**
Reset stack pointer to begin of the stack.
**/
VOID
ResetCurrentExpressionStack (
VOID
)
{
mCurrentExpressionPointer = mCurrentExpressionStack;
mFormExpressionPointer = mFormExpressionStack;
mStatementExpressionPointer = mStatementExpressionStack;
mOptionExpressionPointer = mOptionExpressionStack;
}
/**
Push current expression onto the Stack
@param Pointer Pointer to current expression.
@retval EFI_SUCCESS The value was pushed onto the stack.
@retval EFI_OUT_OF_RESOURCES There is not enough system memory to grow the stack.
**/
EFI_STATUS
PushCurrentExpression (
IN VOID *Pointer
)
{
EFI_HII_VALUE Data;
Data.Type = EFI_IFR_TYPE_NUM_SIZE_64;
Data.Value.u64 = (UINT64)(UINTN)Pointer;
return PushStack (
&mCurrentExpressionStack,
&mCurrentExpressionPointer,
&mCurrentExpressionEnd,
&Data
);
}
/**
Pop current expression from the Stack
@param Pointer Pointer to current expression to be pop.
@retval EFI_SUCCESS The value was pushed onto the stack.
@retval EFI_OUT_OF_RESOURCES There is not enough system memory to grow the stack.
**/
EFI_STATUS
PopCurrentExpression (
OUT VOID **Pointer
)
{
EFI_STATUS Status;
EFI_HII_VALUE Data;
Status = PopStack (
mCurrentExpressionStack,
&mCurrentExpressionPointer,
&Data
);
*Pointer = (VOID *)(UINTN)Data.Value.u64;
return Status;
}
/**
Reset stack pointer to begin of the stack.
**/
VOID
ResetMapExpressionListStack (
VOID
)
{
mMapExpressionListPointer = mMapExpressionListStack;
}
/**
Grow size of the stack.
This is an internal function.
@param Stack On input: old stack; On output: new stack
@param StackPtr On input: old stack pointer; On output: new stack
pointer
@param StackEnd On input: old stack end; On output: new stack end
@param MemberSize The stack member size.
@retval EFI_SUCCESS Grow stack success.
@retval EFI_OUT_OF_RESOURCES No enough memory for stack space.
**/
EFI_STATUS
GrowConditionalStack (
IN OUT HII_EXPRESSION ***Stack,
IN OUT HII_EXPRESSION ***StackPtr,
IN OUT HII_EXPRESSION ***StackEnd,
IN UINTN MemberSize
)
{
UINTN Size;
HII_EXPRESSION **NewStack;
Size = EXPRESSION_STACK_SIZE_INCREMENT;
if (*StackPtr != NULL) {
Size = Size + (*StackEnd - *Stack);
}
NewStack = AllocatePool (Size * MemberSize);
if (NewStack == NULL) {
return EFI_OUT_OF_RESOURCES;
}
if (*StackPtr != NULL) {
//
// Copy from Old Stack to the New Stack
//
CopyMem (
NewStack,
*Stack,
(*StackEnd - *Stack) * MemberSize
);
//
// Free The Old Stack
//
FreePool (*Stack);
}
//
// Make the Stack pointer point to the old data in the new stack
//
*StackPtr = NewStack + (*StackPtr - *Stack);
*Stack = NewStack;
*StackEnd = NewStack + Size;
return EFI_SUCCESS;
}
/**
Push an element onto the Stack.
@param Stack On input: old stack; On output: new stack
@param StackPtr On input: old stack pointer; On output: new stack
pointer
@param StackEnd On input: old stack end; On output: new stack end
@param Data Data to push.
@retval EFI_SUCCESS Push stack success.
**/
EFI_STATUS
PushConditionalStack (
IN OUT HII_EXPRESSION ***Stack,
IN OUT HII_EXPRESSION ***StackPtr,
IN OUT HII_EXPRESSION ***StackEnd,
IN HII_EXPRESSION **Data
)
{
EFI_STATUS Status;
//
// Check for a stack overflow condition
//
if (*StackPtr >= *StackEnd) {
//
// Grow the stack
//
Status = GrowConditionalStack (Stack, StackPtr, StackEnd, sizeof (HII_EXPRESSION *));
if (EFI_ERROR (Status)) {
return Status;
}
}
//
// Push the item onto the stack
//
CopyMem (*StackPtr, Data, sizeof (HII_EXPRESSION *));
*StackPtr = *StackPtr + 1;
return EFI_SUCCESS;
}
/**
Pop an element from the stack.
@param Stack On input: old stack
@param StackPtr On input: old stack pointer; On output: new stack pointer
@param Data Data to pop.
@retval EFI_SUCCESS The value was popped onto the stack.
@retval EFI_ACCESS_DENIED The pop operation underflowed the stack
**/
EFI_STATUS
PopConditionalStack (
IN HII_EXPRESSION **Stack,
IN OUT HII_EXPRESSION ***StackPtr,
OUT HII_EXPRESSION **Data
)
{
//
// Check for a stack underflow condition
//
if (*StackPtr == Stack) {
return EFI_ACCESS_DENIED;
}
//
// Pop the item off the stack
//
*StackPtr = *StackPtr - 1;
CopyMem (Data, *StackPtr, sizeof (HII_EXPRESSION *));
return EFI_SUCCESS;
}
/**
Get the expression list count.
@param Level Which type this expression belong to. Form,
statement or option?
@retval >=0 The expression count
@retval -1 Input parameter error.
**/
INTN
GetConditionalExpressionCount (
IN EXPRESS_LEVEL Level
)
{
switch (Level) {
case ExpressForm:
return mFormExpressionPointer - mFormExpressionStack;
case ExpressStatement:
return mStatementExpressionPointer - mStatementExpressionStack;
case ExpressOption:
return mOptionExpressionPointer - mOptionExpressionStack;
default:
ASSERT (FALSE);
return -1;
}
}
/**
Get the expression Buffer pointer.
@param Level Which type this expression belong to. Form,
statement or option?
@retval The start pointer of the expression buffer or NULL.
**/
HII_EXPRESSION **
GetConditionalExpressionList (
IN EXPRESS_LEVEL Level
)
{
switch (Level) {
case ExpressForm:
return mFormExpressionStack;
case ExpressStatement:
return mStatementExpressionStack;
case ExpressOption:
return mOptionExpressionStack;
default:
ASSERT (FALSE);
return NULL;
}
}
/**
Push the expression options onto the Stack.
@param Pointer Pointer to the current expression.
@param Level Which type this expression belong to. Form,
statement or option?
@retval EFI_SUCCESS The value was pushed onto the stack.
@retval EFI_OUT_OF_RESOURCES There is not enough system memory to grow the stack.
**/
EFI_STATUS
PushConditionalExpression (
IN HII_EXPRESSION *Pointer,
IN EXPRESS_LEVEL Level
)
{
switch (Level) {
case ExpressForm:
return PushConditionalStack (
&mFormExpressionStack,
&mFormExpressionPointer,
&mFormExpressionEnd,
&Pointer
);
case ExpressStatement:
return PushConditionalStack (
&mStatementExpressionStack,
&mStatementExpressionPointer,
&mStatementExpressionEnd,
&Pointer
);
case ExpressOption:
return PushConditionalStack (
&mOptionExpressionStack,
&mOptionExpressionPointer,
&mOptionExpressionEnd,
&Pointer
);
default:
ASSERT (FALSE);
return EFI_INVALID_PARAMETER;
}
}
/**
Pop the expression options from the Stack
@param Level Which type this expression belong to. Form,
statement or option?
@retval EFI_SUCCESS The value was pushed onto the stack.
@retval EFI_OUT_OF_RESOURCES There is not enough system memory to grow the stack.
**/
EFI_STATUS
PopConditionalExpression (
IN EXPRESS_LEVEL Level
)
{
HII_EXPRESSION *Pointer;
switch (Level) {
case ExpressForm:
return PopConditionalStack (
mFormExpressionStack,
&mFormExpressionPointer,
&Pointer
);
case ExpressStatement:
return PopConditionalStack (
mStatementExpressionStack,
&mStatementExpressionPointer,
&Pointer
);
case ExpressOption:
return PopConditionalStack (
mOptionExpressionStack,
&mOptionExpressionPointer,
&Pointer
);
default:
ASSERT (FALSE);
return EFI_INVALID_PARAMETER;
}
}
/**
Push the list of map expression onto the Stack
@param Pointer Pointer to the list of map expression to be pushed.
@retval EFI_SUCCESS The value was pushed onto the stack.
@retval EFI_OUT_OF_RESOURCES There is not enough system memory to grow the stack.
**/
EFI_STATUS
PushMapExpressionList (
IN VOID *Pointer
)
{
EFI_HII_VALUE Data;
Data.Type = EFI_IFR_TYPE_NUM_SIZE_64;
Data.Value.u64 = (UINT64)(UINTN)Pointer;
return PushStack (
&mMapExpressionListStack,
&mMapExpressionListPointer,
&mMapExpressionListEnd,
&Data
);
}
/**
Pop the list of map expression from the Stack
@param Pointer Pointer to the list of map expression to be pop.
@retval EFI_SUCCESS The value was pushed onto the stack.
@retval EFI_OUT_OF_RESOURCES There is not enough system memory to grow the stack.
**/
EFI_STATUS
PopMapExpressionList (
OUT VOID **Pointer
)
{
EFI_STATUS Status;
EFI_HII_VALUE Data;
Status = PopStack (
mMapExpressionListStack,
&mMapExpressionListPointer,
&Data
);
*Pointer = (VOID *)(UINTN)Data.Value.u64;
return Status;
}
/**
Reset stack pointer to begin of the stack.
**/
VOID
ResetScopeStack (
VOID
)
{
mOpCodeScopeStackPointer = mOpCodeScopeStack;
}
/**
Push an Operand onto the Stack
@param Operand Operand to push.
@retval EFI_SUCCESS The value was pushed onto the stack.
@retval EFI_OUT_OF_RESOURCES There is not enough system memory to grow the
stack.
**/
EFI_STATUS
PushScope (
IN UINT8 Operand
)
{
EFI_HII_VALUE Data;
Data.Type = EFI_IFR_TYPE_NUM_SIZE_8;
Data.Value.u8 = Operand;
return PushStack (
&mOpCodeScopeStack,
&mOpCodeScopeStackPointer,
&mOpCodeScopeStackEnd,
&Data
);
}
/**
Pop an Operand from the Stack
@param Operand Operand to pop.
@retval EFI_SUCCESS The value was pushed onto the stack.
@retval EFI_OUT_OF_RESOURCES There is not enough system memory to grow the
stack.
**/
EFI_STATUS
PopScope (
OUT UINT8 *Operand
)
{
EFI_STATUS Status;
EFI_HII_VALUE Data;
Status = PopStack (
mOpCodeScopeStack,
&mOpCodeScopeStackPointer,
&Data
);
*Operand = Data.Value.u8;
return Status;
}
/**
Grow size of the stack for Expression Dependencies.
This is an internal function.
@param Stack On input: old stack; On output: new stack
@param StackPtr On input: old stack pointer; On output: new stack
pointer
@param StackEnd On input: old stack end; On output: new stack end
@retval EFI_SUCCESS Grow Dependency stack success.
@retval EFI_OUT_OF_RESOURCES No enough memory for stack space.
**/
EFI_STATUS
GrowDependencyStack (
IN OUT HII_DEPENDENCY_EXPRESSION ***Stack,
IN OUT HII_DEPENDENCY_EXPRESSION ***StackPtr,
IN OUT HII_DEPENDENCY_EXPRESSION ***StackEnd
)
{
UINTN Size;
HII_DEPENDENCY_EXPRESSION **NewStack;
Size = EXPRESSION_STACK_SIZE_INCREMENT;
if (*StackPtr != NULL) {
Size = Size + (*StackEnd - *Stack);
}
NewStack = AllocatePool (Size * sizeof (HII_DEPENDENCY_EXPRESSION *));
if (NewStack == NULL) {
return EFI_OUT_OF_RESOURCES;
}
if (*StackPtr != NULL) {
//
// Copy from Old Stack to the New Stack
//
CopyMem (
NewStack,
*Stack,
(*StackEnd - *Stack) * sizeof (HII_DEPENDENCY_EXPRESSION *)
);
//
// Free The Old Stack
//
FreePool (*Stack);
}
//
// Make the Stack pointer point to the old data in the new stack
//
*StackPtr = NewStack + (*StackPtr - *Stack);
*Stack = NewStack;
*StackEnd = NewStack + Size;
return EFI_SUCCESS;
}
/**
Push an element onto the Stack for Expression Dependencies.
@param Stack On input: old stack; On output: new stack
@param StackPtr On input: old stack pointer; On output: new stack
pointer
@param StackEnd On input: old stack end; On output: new stack end
@param Data Data to push.
@retval EFI_SUCCESS Push stack success.
**/
EFI_STATUS
PushDependencyStack (
IN OUT HII_DEPENDENCY_EXPRESSION ***Stack,
IN OUT HII_DEPENDENCY_EXPRESSION ***StackPtr,
IN OUT HII_DEPENDENCY_EXPRESSION ***StackEnd,
IN HII_DEPENDENCY_EXPRESSION **Data
)
{
EFI_STATUS Status;
//
// Check for a stack overflow condition
//
if (*StackPtr >= *StackEnd) {
//
// Grow the stack
//
Status = GrowDependencyStack (Stack, StackPtr, StackEnd);
if (EFI_ERROR (Status)) {
return Status;
}
}
//
// Push the item onto the stack
//
CopyMem (*StackPtr, Data, sizeof (HII_DEPENDENCY_EXPRESSION *));
*StackPtr = *StackPtr + 1;
return EFI_SUCCESS;
}
/**
Pop the Expression Dependency options from the Stack
@param Stack On input: old stack; On output: new stack
@param StackPtr On input: old stack pointer; On output: new stack
pointer
@param Data Data to push.
@retval EFI_SUCCESS The value was pushed onto the stack.
@retval EFI_OUT_OF_RESOURCES There is not enough system memory to grow the stack.
**/
EFI_STATUS
PopDependencyStack (
IN HII_DEPENDENCY_EXPRESSION **Stack,
IN OUT HII_DEPENDENCY_EXPRESSION ***StackPtr,
OUT HII_DEPENDENCY_EXPRESSION **Data
)
{
//
// Check for a stack underflow condition
//
if (*StackPtr == Stack) {
return EFI_ACCESS_DENIED;
}
//
// Pop the item off the stack
//
*StackPtr = *StackPtr - 1;
CopyMem (Data, *StackPtr, sizeof (HII_DEPENDENCY_EXPRESSION *));
return EFI_SUCCESS;
}
/**
Push the list of Expression Dependencies onto the Stack
@param Pointer Pointer to the list of map expression to be pushed.
@retval EFI_SUCCESS The value was pushed onto the stack.
@retval EFI_OUT_OF_RESOURCES There is not enough system memory to grow the stack.
**/
EFI_STATUS
PushDependencyExpDes (
IN HII_DEPENDENCY_EXPRESSION **Pointer
)
{
return PushDependencyStack (
&mExpressionDependencyStack,
&mExpressionDependencyPointer,
&mExpressionDependencyEnd,
Pointer
);
}
/**
Pop the list of Expression Dependencies from the Stack
@param Pointer Pointer to the list of map expression to be pop.
@retval EFI_SUCCESS The value was pushed onto the stack.
@retval EFI_OUT_OF_RESOURCES There is not enough system memory to grow the stack.
**/
EFI_STATUS
PopDependencyExpDes (
OUT HII_DEPENDENCY_EXPRESSION **Pointer
)
{
return PopDependencyStack (
mExpressionDependencyStack,
&mExpressionDependencyPointer,
Pointer
);
}
/**
Retrieve dependencies within an expression. These dependencies can express how
this expression will be evaluated.
@param[in,out] Expression Expression to retrieve dependencies.
@retval EFI_SUCCESS The dependencies were successfully retrieved.
@retval EFI_OUT_OF_RESOURCES There is not enough system memory.
**/
EFI_STATUS
GetHiiExpressionDependency (
IN OUT HII_EXPRESSION *Expression
)
{
EFI_STATUS Status;
LIST_ENTRY *Link;
HII_EXPRESSION_OPCODE *ExpressionOpCode;
HII_DEPENDENCY_EXPRESSION *DepExpressionOpCode;
LIST_ENTRY *SubExpressionLink;
HII_EXPRESSION *SubExpression;
UINT8 MapPairCount;
Link = GetFirstNode (&Expression->OpCodeListHead);
while (!IsNull (&Expression->OpCodeListHead, Link)) {
ExpressionOpCode = HII_EXPRESSION_OPCODE_FROM_LINK (Link);
Link = GetNextNode (&Expression->OpCodeListHead, Link);
Status = EFI_SUCCESS;
DepExpressionOpCode = (HII_DEPENDENCY_EXPRESSION *)AllocateZeroPool (sizeof (HII_DEPENDENCY_EXPRESSION));
if (DepExpressionOpCode == NULL) {
return EFI_OUT_OF_RESOURCES;
}
switch (ExpressionOpCode->Operand) {
//
// Constant
//
case EFI_IFR_FALSE_OP:
case EFI_IFR_ONE_OP:
case EFI_IFR_ONES_OP:
case EFI_IFR_TRUE_OP:
case EFI_IFR_UINT8_OP:
case EFI_IFR_UINT16_OP:
case EFI_IFR_UINT32_OP:
case EFI_IFR_UINT64_OP:
case EFI_IFR_UNDEFINED_OP:
case EFI_IFR_VERSION_OP:
case EFI_IFR_ZERO_OP:
DepExpressionOpCode->ConstantExp.Operand = ExpressionOpCode->Operand;
CopyMem (&DepExpressionOpCode->ConstantExp.Value, &ExpressionOpCode->ExtraData.Value, sizeof (EFI_HII_VALUE));
PushDependencyExpDes (&DepExpressionOpCode);
break;
//
// Built-in functions
//
case EFI_IFR_DUP_OP:
DepExpressionOpCode->DupExp.Operand = ExpressionOpCode->Operand;
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_EQ_ID_VAL_OP:
DepExpressionOpCode->EqIdValExp.Operand = ExpressionOpCode->Operand;
CopyMem (&DepExpressionOpCode->EqIdValExp.QuestionId, &ExpressionOpCode->ExtraData.EqIdValData.QuestionId, sizeof (EFI_QUESTION_ID));
CopyMem (&DepExpressionOpCode->EqIdValExp.Value, &ExpressionOpCode->ExtraData.EqIdValData.Value, sizeof (EFI_HII_VALUE));
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_EQ_ID_ID_OP:
DepExpressionOpCode->EqIdIdExp.Operand = ExpressionOpCode->Operand;
CopyMem (&DepExpressionOpCode->EqIdIdExp.QuestionId1, &ExpressionOpCode->ExtraData.EqIdIdData.QuestionId1, sizeof (EFI_QUESTION_ID));
CopyMem (&DepExpressionOpCode->EqIdIdExp.QuestionId2, &ExpressionOpCode->ExtraData.EqIdIdData.QuestionId2, sizeof (EFI_QUESTION_ID));
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_EQ_ID_VAL_LIST_OP:
DepExpressionOpCode->EqIdListExp.Operand = ExpressionOpCode->Operand;
DepExpressionOpCode->EqIdListExp.ListLength = ExpressionOpCode->ExtraData.EqIdListData.ListLength;
CopyMem (&DepExpressionOpCode->EqIdListExp.QuestionId, &ExpressionOpCode->ExtraData.EqIdListData.QuestionId, sizeof (EFI_QUESTION_ID));
PushDependencyExpDes (&DepExpressionOpCode);
DepExpressionOpCode->EqIdListExp.ValueList = AllocateCopyPool (
DepExpressionOpCode->EqIdListExp.ListLength * sizeof (UINT16),
ExpressionOpCode->ExtraData.EqIdListData.ValueList
);
if (DepExpressionOpCode->EqIdListExp.ValueList == NULL) {
return EFI_OUT_OF_RESOURCES;
}
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_GET_OP:
DepExpressionOpCode->GetExp.Operand = ExpressionOpCode->Operand;
DepExpressionOpCode->GetExp.VarStorage = ExpressionOpCode->ExtraData.GetSetData.VarStorage;
CopyMem (&DepExpressionOpCode->GetExp.VarStoreInfo.VarName, &ExpressionOpCode->ExtraData.GetSetData.VarStoreInfo.VarName, sizeof (EFI_STRING_ID));
CopyMem (&DepExpressionOpCode->GetExp.VarStoreInfo.VarOffset, &ExpressionOpCode->ExtraData.GetSetData.VarStoreInfo.VarOffset, sizeof (UINT16));
DepExpressionOpCode->GetExp.VarStoreInfo = ExpressionOpCode->ExtraData.GetSetData.VarStoreInfo;
if (ExpressionOpCode->ExtraData.GetSetData.ValueName != NULL) {
DepExpressionOpCode->GetExp.ValueName = (CHAR16 *)AllocateCopyPool (sizeof (ExpressionOpCode->ExtraData.GetSetData.ValueName), ExpressionOpCode->ExtraData.GetSetData.ValueName);
if (DepExpressionOpCode->GetExp.ValueName == NULL) {
return EFI_OUT_OF_RESOURCES;
}
}
DepExpressionOpCode->GetExp.ValueType = ExpressionOpCode->ExtraData.GetSetData.ValueType;
DepExpressionOpCode->GetExp.ValueWidth = ExpressionOpCode->ExtraData.GetSetData.ValueWidth;
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_QUESTION_REF1_OP:
DepExpressionOpCode->QuestionRef1Exp.Operand = ExpressionOpCode->Operand;
CopyMem (&DepExpressionOpCode->QuestionRef1Exp.QuestionId, &ExpressionOpCode->ExtraData.QuestionRef1Data.QuestionId, sizeof (EFI_QUESTION_ID));
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_RULE_REF_OP:
DepExpressionOpCode->RuleRefExp.Operand = ExpressionOpCode->Operand;
DepExpressionOpCode->RuleRefExp.RuleId = ExpressionOpCode->ExtraData.RuleId;
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_STRING_REF1_OP:
DepExpressionOpCode->StringRef1Exp.Operand = ExpressionOpCode->Operand;
CopyMem (&DepExpressionOpCode->StringRef1Exp.Value.Value.string, &ExpressionOpCode->ExtraData.Value.Value.string, sizeof (EFI_STRING_ID));
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_THIS_OP:
DepExpressionOpCode->ThisExp.Operand = ExpressionOpCode->Operand;
CopyMem (&DepExpressionOpCode->ThisExp.QuestionId, &ExpressionOpCode->ExtraData.QuestionRef1Data.QuestionId, sizeof (EFI_QUESTION_ID));
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_SECURITY_OP:
DepExpressionOpCode->SecurityExp.Operand = ExpressionOpCode->Operand;
CopyMem (&DepExpressionOpCode->SecurityExp.Permissions, &ExpressionOpCode->ExtraData.Guid, sizeof (EFI_GUID));
PushDependencyExpDes (&DepExpressionOpCode);
break;
//
// unary-op
//
case EFI_IFR_LENGTH_OP:
DepExpressionOpCode->LengthExp.Operand = ExpressionOpCode->Operand;
PopDependencyExpDes (&DepExpressionOpCode->LengthExp.SubExpression);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_NOT_OP:
DepExpressionOpCode->NotExp.Operand = ExpressionOpCode->Operand;
PopDependencyExpDes (&DepExpressionOpCode->NotExp.SubExpression);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_BITWISE_NOT_OP:
DepExpressionOpCode->BitWiseNotExp.Operand = ExpressionOpCode->Operand;
PopDependencyExpDes (&DepExpressionOpCode->BitWiseNotExp.SubExpression);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_QUESTION_REF2_OP:
DepExpressionOpCode->QuestionRef2Exp.Operand = ExpressionOpCode->Operand;
PopDependencyExpDes (&DepExpressionOpCode->QuestionRef2Exp.SubExpression);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_QUESTION_REF3_OP:
DepExpressionOpCode->QuestionRef3Exp.Operand = ExpressionOpCode->Operand;
CopyMem (&DepExpressionOpCode->QuestionRef3Exp.DevicePath, &ExpressionOpCode->ExtraData.QuestionRef3Data.DevicePath, sizeof (EFI_DEVICE_PATH));
CopyMem (&DepExpressionOpCode->QuestionRef3Exp.Guid, &ExpressionOpCode->ExtraData.QuestionRef3Data.Guid, sizeof (EFI_GUID));
PopDependencyExpDes (&DepExpressionOpCode->QuestionRef3Exp.SubExpression);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_SET_OP:
DepExpressionOpCode->SetExp.Operand = ExpressionOpCode->Operand;
DepExpressionOpCode->SetExp.VarStorage = ExpressionOpCode->ExtraData.GetSetData.VarStorage;
CopyMem (&DepExpressionOpCode->SetExp.VarStoreInfo.VarName, &ExpressionOpCode->ExtraData.GetSetData.VarStoreInfo.VarName, sizeof (EFI_STRING_ID));
CopyMem (&DepExpressionOpCode->SetExp.VarStoreInfo.VarOffset, &ExpressionOpCode->ExtraData.GetSetData.VarStoreInfo.VarOffset, sizeof (UINT16));
DepExpressionOpCode->SetExp.VarStoreInfo = ExpressionOpCode->ExtraData.GetSetData.VarStoreInfo;
if (ExpressionOpCode->ExtraData.GetSetData.ValueName != NULL) {
DepExpressionOpCode->SetExp.ValueName = (CHAR16 *)AllocateCopyPool (sizeof (ExpressionOpCode->ExtraData.GetSetData.ValueName), ExpressionOpCode->ExtraData.GetSetData.ValueName);
if (DepExpressionOpCode->SetExp.ValueName == NULL) {
return EFI_OUT_OF_RESOURCES;
}
}
DepExpressionOpCode->SetExp.ValueType = ExpressionOpCode->ExtraData.GetSetData.ValueType;
DepExpressionOpCode->SetExp.ValueWidth = ExpressionOpCode->ExtraData.GetSetData.ValueWidth;
PopDependencyExpDes (&DepExpressionOpCode->SetExp.SubExpression);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_STRING_REF2_OP:
DepExpressionOpCode->StringRef2Exp.Operand = ExpressionOpCode->Operand;
PopDependencyExpDes (&DepExpressionOpCode->StringRef2Exp.SubExpression);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_TO_BOOLEAN_OP:
DepExpressionOpCode->ToBooleanExp.Operand = ExpressionOpCode->Operand;
PopDependencyExpDes (&DepExpressionOpCode->ToBooleanExp.SubExpression);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_TO_STRING_OP:
DepExpressionOpCode->ToStringExp.Operand = ExpressionOpCode->Operand;
DepExpressionOpCode->ToStringExp.Format = ExpressionOpCode->ExtraData.Format;
PopDependencyExpDes (&DepExpressionOpCode->ToStringExp.SubExpression);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_TO_UINT_OP:
DepExpressionOpCode->ToUintExp.Operand = ExpressionOpCode->Operand;
PopDependencyExpDes (&DepExpressionOpCode->ToUintExp.SubExpression);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_TO_LOWER_OP:
DepExpressionOpCode->ToLowerExp.Operand = ExpressionOpCode->Operand;
PopDependencyExpDes (&DepExpressionOpCode->ToLowerExp.SubExpression);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_TO_UPPER_OP:
DepExpressionOpCode->ToUpperExp.Operand = ExpressionOpCode->Operand;
PopDependencyExpDes (&DepExpressionOpCode->ToUpperExp.SubExpression);
PushDependencyExpDes (&DepExpressionOpCode);
break;
//
// binary-op
//
case EFI_IFR_ADD_OP:
DepExpressionOpCode->AddExp.Operand = ExpressionOpCode->Operand;
PopDependencyExpDes (&DepExpressionOpCode->AddExp.LeftHandExp);
PopDependencyExpDes (&DepExpressionOpCode->AddExp.RightHandExp);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_AND_OP:
DepExpressionOpCode->AndExp.Operand = ExpressionOpCode->Operand;
PopDependencyExpDes (&DepExpressionOpCode->AndExp.SubExpression1);
PopDependencyExpDes (&DepExpressionOpCode->AndExp.SubExpression2);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_BITWISE_AND_OP:
DepExpressionOpCode->BitwiseAndExp.Operand = ExpressionOpCode->Operand;
PopDependencyExpDes (&DepExpressionOpCode->BitwiseAndExp.SubExpression1);
PopDependencyExpDes (&DepExpressionOpCode->BitwiseAndExp.SubExpression2);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_BITWISE_OR_OP:
DepExpressionOpCode->BitwiseOrExp.Operand = ExpressionOpCode->Operand;
PopDependencyExpDes (&DepExpressionOpCode->BitwiseOrExp.SubExpression1);
PopDependencyExpDes (&DepExpressionOpCode->BitwiseOrExp.SubExpression2);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_CATENATE_OP:
DepExpressionOpCode->CatenateExp.Operand = ExpressionOpCode->Operand;
PopDependencyExpDes (&DepExpressionOpCode->CatenateExp.LeftStringExp);
PopDependencyExpDes (&DepExpressionOpCode->CatenateExp.RightStringExp);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_DIVIDE_OP:
DepExpressionOpCode->DivExp.Operand = ExpressionOpCode->Operand;
PopDependencyExpDes (&DepExpressionOpCode->DivExp.LeftHandExp);
PopDependencyExpDes (&DepExpressionOpCode->DivExp.RightHandExp);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_EQUAL_OP:
DepExpressionOpCode->EqualExp.Operand = ExpressionOpCode->Operand;
PopDependencyExpDes (&DepExpressionOpCode->EqualExp.SubExpression1);
PopDependencyExpDes (&DepExpressionOpCode->EqualExp.SubExpression2);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_GREATER_EQUAL_OP:
DepExpressionOpCode->GreaterEqualExp.Operand = ExpressionOpCode->Operand;
PopDependencyExpDes (&DepExpressionOpCode->GreaterEqualExp.LeftHandExp);
PopDependencyExpDes (&DepExpressionOpCode->GreaterEqualExp.RightHandExp);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_GREATER_THAN_OP:
DepExpressionOpCode->GreaterThanExp.Operand = ExpressionOpCode->Operand;
PopDependencyExpDes (&DepExpressionOpCode->GreaterThanExp.LeftHandExp);
PopDependencyExpDes (&DepExpressionOpCode->GreaterThanExp.RightHandExp);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_LESS_EQUAL_OP:
DepExpressionOpCode->LessEqualExp.Operand = ExpressionOpCode->Operand;
PopDependencyExpDes (&DepExpressionOpCode->LessEqualExp.LeftHandExp);
PopDependencyExpDes (&DepExpressionOpCode->LessEqualExp.RightHandExp);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_LESS_THAN_OP:
DepExpressionOpCode->LessThanExp.Operand = ExpressionOpCode->Operand;
PopDependencyExpDes (&DepExpressionOpCode->LessThanExp.LeftHandExp);
PopDependencyExpDes (&DepExpressionOpCode->LessThanExp.RightHandExp);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_MATCH_OP:
DepExpressionOpCode->MatchExp.Operand = ExpressionOpCode->Operand;
PopDependencyExpDes (&DepExpressionOpCode->MatchExp.PatternExp);
PopDependencyExpDes (&DepExpressionOpCode->MatchExp.StringExp);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_MATCH2_OP:
DepExpressionOpCode->Match2Exp.Operand = ExpressionOpCode->Operand;
CopyMem (&DepExpressionOpCode->Match2Exp.SyntaxType, &ExpressionOpCode->ExtraData.Guid, sizeof (EFI_GUID));
PopDependencyExpDes (&DepExpressionOpCode->Match2Exp.PatternExp);
PopDependencyExpDes (&DepExpressionOpCode->Match2Exp.StringExp);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_MODULO_OP:
DepExpressionOpCode->ModExp.Operand = ExpressionOpCode->Operand;
PopDependencyExpDes (&DepExpressionOpCode->ModExp.LeftHandExp);
PopDependencyExpDes (&DepExpressionOpCode->ModExp.RightHandExp);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_MULTIPLY_OP:
DepExpressionOpCode->MultExp.Operand = ExpressionOpCode->Operand;
PopDependencyExpDes (&DepExpressionOpCode->MultExp.LeftHandExp);
PopDependencyExpDes (&DepExpressionOpCode->MultExp.RightHandExp);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_NOT_EQUAL_OP:
DepExpressionOpCode->NotEqualExp.Operand = ExpressionOpCode->Operand;
PopDependencyExpDes (&DepExpressionOpCode->NotEqualExp.SubExpression1);
PopDependencyExpDes (&DepExpressionOpCode->NotEqualExp.SubExpression2);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_OR_OP:
DepExpressionOpCode->OrExp.Operand = ExpressionOpCode->Operand;
PopDependencyExpDes (&DepExpressionOpCode->OrExp.SubExpression1);
PopDependencyExpDes (&DepExpressionOpCode->OrExp.SubExpression2);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_SHIFT_LEFT_OP:
DepExpressionOpCode->ShiftLeftExp.Operand = ExpressionOpCode->Operand;
PopDependencyExpDes (&DepExpressionOpCode->ShiftLeftExp.LeftHandExp);
PopDependencyExpDes (&DepExpressionOpCode->ShiftLeftExp.RightHandExp);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_SHIFT_RIGHT_OP:
DepExpressionOpCode->ShiftRightExp.Operand = ExpressionOpCode->Operand;
PopDependencyExpDes (&DepExpressionOpCode->ShiftRightExp.LeftHandExp);
PopDependencyExpDes (&DepExpressionOpCode->ShiftRightExp.RightHandExp);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_SUBTRACT_OP:
DepExpressionOpCode->SubtractExp.Operand = ExpressionOpCode->Operand;
PopDependencyExpDes (&DepExpressionOpCode->SubtractExp.LeftHandExp);
PopDependencyExpDes (&DepExpressionOpCode->SubtractExp.RightHandExp);
PushDependencyExpDes (&DepExpressionOpCode);
break;
//
// ternary-op
//
case EFI_IFR_CONDITIONAL_OP:
DepExpressionOpCode->ConditionalExp.Operand = ExpressionOpCode->Operand;
PopDependencyExpDes (&DepExpressionOpCode->ConditionalExp.CondTrueValExp);
PopDependencyExpDes (&DepExpressionOpCode->ConditionalExp.CondFalseValExp);
PopDependencyExpDes (&DepExpressionOpCode->ConditionalExp.ConditionExp);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_FIND_OP:
DepExpressionOpCode->FindExp.Operand = ExpressionOpCode->Operand;
PopDependencyExpDes (&DepExpressionOpCode->FindExp.StringToSearchExp);
PopDependencyExpDes (&DepExpressionOpCode->FindExp.StringToCompWithExp);
PopDependencyExpDes (&DepExpressionOpCode->FindExp.IndexExp);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_MID_OP:
DepExpressionOpCode->MidExp.Operand = ExpressionOpCode->Operand;
PopDependencyExpDes (&DepExpressionOpCode->MidExp.StringOrBufferExp);
PopDependencyExpDes (&DepExpressionOpCode->MidExp.IndexExp);
PopDependencyExpDes (&DepExpressionOpCode->MidExp.LengthExp);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_TOKEN_OP:
DepExpressionOpCode->TokenExp.Operand = ExpressionOpCode->Operand;
PopDependencyExpDes (&DepExpressionOpCode->TokenExp.StringToSearchExp);
PopDependencyExpDes (&DepExpressionOpCode->TokenExp.DelimiterExp);
PopDependencyExpDes (&DepExpressionOpCode->TokenExp.IndexExp);
PushDependencyExpDes (&DepExpressionOpCode);
break;
case EFI_IFR_SPAN_OP:
DepExpressionOpCode->SpanExp.Operand = ExpressionOpCode->Operand;
PopDependencyExpDes (&DepExpressionOpCode->SpanExp.StringToSearchExp);
PopDependencyExpDes (&DepExpressionOpCode->SpanExp.CharsetExp);
PopDependencyExpDes (&DepExpressionOpCode->SpanExp.IndexExp);
PushDependencyExpDes (&DepExpressionOpCode);
break;
//
// Map
//
case EFI_IFR_MAP_OP:
//
// Go through map expression list.
//
DepExpressionOpCode->MapExp.Operand = ExpressionOpCode->Operand;
MapPairCount = 0;
SubExpressionLink = GetFirstNode (&ExpressionOpCode->MapExpressionList);
while (!IsNull (&ExpressionOpCode->MapExpressionList, SubExpressionLink)) {
MapPairCount++;
SubExpressionLink = GetNextNode (&ExpressionOpCode->MapExpressionList, SubExpressionLink);
if (IsNull (&ExpressionOpCode->MapExpressionList, SubExpressionLink)) {
Status = EFI_INVALID_PARAMETER;
goto Done;
}
//
// Goto the first expression on next pair.
//
SubExpressionLink = GetNextNode (&ExpressionOpCode->MapExpressionList, SubExpressionLink);
}
DepExpressionOpCode->MapExp.ExpPair = (HII_DEPENDENCY_EXPRESSION_PAIR *)AllocateZeroPool (
MapPairCount * sizeof (HII_DEPENDENCY_EXPRESSION_PAIR)
);
if (DepExpressionOpCode->MapExp.ExpPair == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Done;
}
DepExpressionOpCode->MapExp.ExpPairNo = MapPairCount;
MapPairCount = 0;
PopDependencyExpDes (&DepExpressionOpCode->MapExp.SubExp);
//
// Go through map expression list.
//
SubExpressionLink = GetFirstNode (&ExpressionOpCode->MapExpressionList);
while (!IsNull (&ExpressionOpCode->MapExpressionList, SubExpressionLink)) {
SubExpression = HII_EXPRESSION_FROM_LINK (SubExpressionLink);
//
// Get the first expression description in this pair.
//
GetHiiExpressionDependency (SubExpression);
DepExpressionOpCode->MapExp.ExpPair[MapPairCount].MatchExp = SubExpression->RootDependencyExp;
//
// Get the second expression description in this pair.
//
SubExpressionLink = GetNextNode (&ExpressionOpCode->MapExpressionList, SubExpressionLink);
SubExpression = HII_EXPRESSION_FROM_LINK (SubExpressionLink);
GetHiiExpressionDependency (SubExpression);
DepExpressionOpCode->MapExp.ExpPair[MapPairCount].ReturnExp = SubExpression->RootDependencyExp;
//
// Goto the first expression on next pair.
//
SubExpressionLink = GetNextNode (&ExpressionOpCode->MapExpressionList, SubExpressionLink);
MapPairCount++;
}
PushDependencyExpDes (&DepExpressionOpCode);
break;
default:
break;
}
}
PopDependencyExpDes (&Expression->RootDependencyExp);
Done:
return Status;
}
/**
Return the result of the expression list. Check the expression list and
return the highest priority express result.
Priority: DisableIf > SuppressIf > GrayOutIf > FALSE
@param[in] ExpList The input expression list.
@param[in] Evaluate Whether need to evaluate the expression first.
@param[in] FormSet FormSet associated with this expression.
@param[in] Form Form associated with this expression.
@retval EXPRESS_RESULT Return the higher priority express result.
DisableIf > SuppressIf > GrayOutIf > FALSE
**/
EXPRESS_RESULT
EvaluateExpressionList (
IN HII_EXPRESSION_LIST *ExpList,
IN BOOLEAN Evaluate,
IN HII_FORMSET *FormSet OPTIONAL,
IN HII_FORM *Form OPTIONAL
)
{
UINTN Index;
EXPRESS_RESULT ReturnVal;
EXPRESS_RESULT CompareOne;
EFI_STATUS Status;
if (ExpList == NULL) {
return ExpressFalse;
}
ASSERT (ExpList->Signature == HII_EXPRESSION_LIST_SIGNATURE);
Index = 0;
//
// Check whether need to evaluate the expression first.
//
if (Evaluate) {
while (ExpList->Count > Index) {
Status = EvaluateHiiExpression (FormSet, Form, ExpList->Expression[Index++]);
if (EFI_ERROR (Status)) {
return ExpressFalse;
}
}
}
//
// Run the list of expressions.
//
ReturnVal = ExpressFalse;
for (Index = 0; Index < ExpList->Count; Index++) {
if (IsHiiValueTrue (&ExpList->Expression[Index]->Result)) {
switch (ExpList->Expression[Index]->Type) {
case EFI_HII_EXPRESSION_SUPPRESS_IF:
CompareOne = ExpressSuppress;
break;
case EFI_HII_EXPRESSION_GRAY_OUT_IF:
CompareOne = ExpressGrayOut;
break;
case EFI_HII_EXPRESSION_DISABLE_IF:
CompareOne = ExpressDisable;
break;
default:
return ExpressFalse;
}
ReturnVal = ReturnVal < CompareOne ? CompareOne : ReturnVal;
}
}
return ReturnVal;
}
|