processoptions.c

来自「EFI BIOS是Intel提出的下一代的BIOS标准。这里上传的Edk源代码是」· C语言 代码 · 共 1,634 行 · 第 1/5 页

C
1,634
字号
        //
        // If a late check is required save off the information.  This is used when consistency checks
        // are required, but certain values might be bound by an impossible consistency check such as
        // if two questions are bound by consistency checks and each only has two possible choices, there
        // would be no way for a user to switch the values.  Thus we require late checking.
        //
        if (Tag->Flags & EFI_IFR_FLAG_LATE_CHECK) {
          EfiCopyMem (&Tag->OldValue, &Value, Tag->StorageWidth);
        } else {
          //
          // In theory, passing the value and the Id are sufficient to determine what needs
          // to be done.  The Id is the key to look for the entry needed in the Inconsistency
          // database.  That will yields operand and ID data - and since the ID's correspond
          // to the NV storage, we can determine the values for other IDs there.
          //
          if (ValueIsNotValid (TRUE, 0, Tag, FileFormTags, &PopUp)) {
            if (PopUp == 0x0000) {
              //
              // Restore Old Value
              //
              if (!Tag->Suppress && !Tag->GrayOut) {
                EfiCopyMem (NvRamMap, &Number, MenuOption->ThisTag->StorageWidth);
              }
              break;
            }

            StringPtr = GetToken (PopUp, MenuOption->Handle);

            CreatePopUp (GetStringWidth (StringPtr) / 2, 3, &NullCharacter, StringPtr, &NullCharacter);

            do {
              Status = WaitForKeyStroke (&Key);

              switch (Key.UnicodeChar) {

              case CHAR_CARRIAGE_RETURN:
                //
                // Since the value can be one byte long or two bytes long, do a CopyMem based on StorageWidth
                //
                EfiCopyMem (NvRamMap, &Number, MenuOption->ThisTag->StorageWidth);
                gBS->FreePool (StringPtr);
                break;

              default:
                break;
              }
            } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
          }
        }

        UpdateStatusBar (NV_UPDATE_REQUIRED, Tag->Flags, TRUE);
      } else {
        if (Tag->Operand == EFI_IFR_ORDERED_LIST_OP) {
          gBS->FreePool (ValueArray);
        }

        return EFI_SUCCESS;
      }
    } else {
      for (Index = MenuOption->TagIndex; MenuOption->Tags[Index].Operand != EFI_IFR_END_ONE_OF_OP; Index++) {
        //
        // We found an option - which assumedly has a string.  We will eventually have to support
        // wrapping of strings.  For now, let's pretend they don't wrap and code that up.
        //
        if (MenuOption->Tags[Index].Operand == EFI_IFR_ONE_OF_OPTION_OP) {
          if (OrderedList) {
            if (!Initialized) {
              //
              // If the first entry is invalid, then the "default" settings are based on what is reflected
              // in the order of the op-codes
              //
              ((UINT8 *) NvRamMap)[Index - MenuOption->TagIndex - 1] = (UINT8) MenuOption->Tags[Index].Value;
            }
            //
            // Only display 3 lines of stuff at most
            //
            if ((Index - MenuOption->TagIndex) > ORDERED_LIST_SIZE) {
              break;
            }

            if (((Index - MenuOption->TagIndex) != 1) && !Skip) {
              Character[0] = LEFT_ONEOF_DELIMITER;
              NewStrCat (OptionString[0], Character);
            }

            MenuOption->ThisTag->NumberOfLines = (UINT16) (Index - MenuOption->TagIndex);
            if (!Initialized) {
              StringPtr = GetToken (MenuOption->Tags[Index].Text, MenuOption->Handle);
            } else {
              for (Value = (UINT16) (MenuOption->TagIndex + 1);
                   MenuOption->Tags[Value].Operand != EFI_IFR_END_ONE_OF_OP;
                   Value++
                  ) {
                if (MenuOption->Tags[Value].Value == ((UINT8 *) NvRamMap)[Index - MenuOption->TagIndex - 1]) {
                  StringPtr = GetToken (MenuOption->Tags[Value].Text, MenuOption->Handle);
                  break;
                }
              }

              if (MenuOption->Tags[Value].Operand == EFI_IFR_END_ONE_OF_OP) {
                Skip = TRUE;
                continue;
              }
            }

            Skip = FALSE;
            NewStrCat (OptionString[0], StringPtr);
            Character[0] = RIGHT_ONEOF_DELIMITER;
            NewStrCat (OptionString[0], Character);
            Character[0] = CHAR_CARRIAGE_RETURN;
            NewStrCat (OptionString[0], Character);

            //
            // Remove Buffer allocated for StringPtr after it has been used.
            //
            gBS->FreePool (StringPtr);
          } else {
            //
            // The option value is the same as what is stored in NV store.  Print this.
            //
            if (!EfiCompareMem (&(MenuOption->Tags[Index].Value), NvRamMap, MenuOption->ThisTag->StorageWidth)) {
              StringPtr = GetToken (MenuOption->Tags[Index].Text, MenuOption->Handle);
              NewStrCat (OptionString[0], StringPtr);
              Character[0] = RIGHT_ONEOF_DELIMITER;
              NewStrCat (OptionString[0], Character);
              //
              // Remove Buffer allocated for StringPtr after it has been used.
              //
              gBS->FreePool (StringPtr);
              Default = 0;
              break;
            }

            if ((MenuOption->Tags[Index].Flags & EFI_IFR_FLAG_DEFAULT) == 1) {
              Default = MenuOption->Tags[Index].Text;
              Value   = MenuOption->Tags[Index].Value;
            };
          }
        }
      }
      //
      // We didn't find a value that matched a setting in the NVRAM Map - display default - set default
      //
      if (Default != 0) {
        //
        // Since the value can be one byte long or two bytes long, do a CopyMem based on StorageWidth
        //
        EfiCopyMem (NvRamMap, &Value, MenuOption->ThisTag->StorageWidth);

        StringPtr = GetToken ((UINT16) Default, MenuOption->Handle);
        NewStrCat (OptionString[0], StringPtr);
        Character[0] = RIGHT_ONEOF_DELIMITER;
        NewStrCat (OptionString[0], Character);
        //
        // Remove Buffer allocated for StringPtr after it has been used.
        //
        gBS->FreePool (StringPtr);
      }
    }
    break;

  case EFI_IFR_CHECKBOX_OP:
    //
    // If the op-code we are looking at is larger than the latest created NvMap - we likely encountered a dynamically
    // created entry which has an expanded NvMap requirement.  We won't save this information - but we need to adjust
    // the NvMap so that we can properly display the information
    //
    if ((UINTN) (Tag->StorageStart + Tag->StorageWidth) > VariableDefinition->VariableFakeSize) {
      AdjustNvMap (FileFormTags, MenuOption);
      NvRamMap = (UINT16 *) &VariableDefinition->NvRamMap[Tag->StorageStart];
    }

    Default = Tag->Flags & 1;
    //
    // If hit spacebar, set or unset Tag[TagIndex].Flags based on it's previous value - BOOLEAN
    //
    *OptionString = EfiLibAllocateZeroPool ((gOptionBlockWidth + 1) * 2 * gScreenDimensions.BottomRow);
    ASSERT (*OptionString);

    //
    // Since Checkboxes are BOOLEAN values, bit 0 of the Flags bit defines the default option, therefore, if
    // the default option (only one option for checkboxes) is on, then the default value is on.  Tag.Default is not
    // an active field for Checkboxes.
    //
    StrnCpy (OptionString[0], LEFT_CHECKBOX_DELIMITER, 1);

    //
    // Since this is a BOOLEAN operation, flip bit 0 upon selection
    //
    if (Selected) {
      Tag->Value          = (UINT16) (Tag->Value ^ 1);
      *(UINT8 *) NvRamMap = (UINT8) (Tag->Value & 1);
      UpdateStatusBar (NV_UPDATE_REQUIRED, Tag->Flags, TRUE);
    }

    if ((*(UINT8 *) NvRamMap & 1) == 0x01) {
      NewStrCat (OptionString[0], CHECK_ON);
      //
      // If someone reset default variables - we may need to reload from our NvMapping....
      //
      Tag->Value = *(UINT8 *) NvRamMap;
    } else {
      //
      // If someone reset default variables - we may need to reload from our NvMapping....
      //
      NewStrCat (OptionString[0], CHECK_OFF);
      Tag->Value = *(UINT8 *) NvRamMap;
    }

    NewStrCat (OptionString[0], RIGHT_CHECKBOX_DELIMITER);
    NewStrCat (OptionString[0], StringPtr);
    break;

  case EFI_IFR_NUMERIC_OP:
    //
    // If the op-code we are looking at is larger than the latest created NvMap - we likely encountered a dynamically
    // created entry which has an expanded NvMap requirement.  We won't save this information - but we need to adjust
    // the NvMap so that we can properly display the information
    //
    if ((UINTN) (Tag->StorageStart + Tag->StorageWidth) > VariableDefinition->VariableFakeSize) {
      AdjustNvMap (FileFormTags, MenuOption);
      NvRamMap = (UINT16 *) &VariableDefinition->NvRamMap[Tag->StorageStart];
    }

    *OptionString = EfiLibAllocateZeroPool ((gOptionBlockWidth + 1) * 2 * gScreenDimensions.BottomRow);
    ASSERT (*OptionString);

    //
    // Add left delimeter to string
    //
    *OptionString[0] = LEFT_NUMERIC_DELIMITER;

    //
    // Retrieve the current numeric value
    //
    if (Selected) {
      //
      // Go ask for input
      //
      if (Tag->Step == 0) {
        //
        // Manual Input
        //
        Status = GetNumericInput (MenuOption, FileFormTagsHead, TRUE, Tag, REGULAR_NUMERIC, &Number);
        if (!EFI_ERROR (Status)) {
          EfiCopyMem (gPreviousValue, NvRamMap, MenuOption->ThisTag->StorageWidth);
          UpdateStatusBar (NV_UPDATE_REQUIRED, Tag->Flags, TRUE);

          //
          // Since the value can be one byte long or two bytes long, do a CopyMem based on StorageWidth
          //
          EfiCopyMem (NvRamMap, &Number, MenuOption->ThisTag->StorageWidth);
        } else {
          return EFI_SUCCESS;
        }
      } else {
        //
        // Auto selection from list
        //
        if (((Tag->StorageWidth == 1) && (UINT8) (*NvRamMap) > Tag->Maximum || (UINT8) (*NvRamMap) < Tag->Minimum) ||
            ((Tag->StorageWidth == 2) && *NvRamMap > Tag->Maximum || *NvRamMap < Tag->Minimum)
            ) {
          //
          // Seed Number with valid value if currently invalid
          //
          Number = Tag->Default;
        } else {
          if (Tag->StorageWidth == 1) {
            Number = (UINT8) (*NvRamMap);
          } else {
            Number = *NvRamMap;
          }
        }

        Status = GetNumericInput (MenuOption, FileFormTagsHead, FALSE, Tag, REGULAR_NUMERIC, &Number);
        if (!EFI_ERROR (Status)) {
          EfiCopyMem (gPreviousValue, NvRamMap, MenuOption->ThisTag->StorageWidth);
          UpdateStatusBar (NV_UPDATE_REQUIRED, Tag->Flags, TRUE);

          //
          // Since the value can be one byte long or two bytes long, do a CopyMem based on StorageWidth
          //
          EfiCopyMem (NvRamMap, &Number, MenuOption->ThisTag->StorageWidth);
        } else {
          return EFI_SUCCESS;
        }
      }
    } else {
      if (((Tag->StorageWidth == 1) && (UINT8) (*NvRamMap) <= Tag->Maximum && (UINT8) (*NvRamMap) >= Tag->Minimum) ||
          ((Tag->StorageWidth == 2) && *NvRamMap <= Tag->Maximum && *NvRamMap >= Tag->Minimum)
          ) {
        if (Tag->StorageWidth == 1) {
          Number = (UINT8) (*NvRamMap);
        } else {
          Number = *NvRamMap;
        }

        ValueToString (FormattedNumber, FALSE, (UINT64) Number);
        Number = (UINT16) GetStringWidth (FormattedNumber);
        StrnCpy (OptionString[0] + 1, FormattedNumber, Number);
      } else {
        //
        // If *NvRamMap isn't within parameters, set it to within parameters
        //
        //
        // Since the value can be one byte long or two bytes long, do a CopyMem based on StorageWidth
        //
        EfiCopyMem (NvRamMap, &Tag->Default, MenuOption->ThisTag->StorageWidth);
        Number = Tag->Default;

        ValueToString (FormattedNumber, FALSE, (UINT64) Number);
        Number = (UINT16) GetStringWidth (FormattedNumber);
        StrnCpy (OptionString[0] + 1, FormattedNumber, Number);
      }

      *(OptionString[0] + Number / 2) = RIGHT_NUMERIC_DELIMITER;
      NewStrCat (OptionString[0] + (Number / 2) + 1, StringPtr);
    }
    break;

  case EFI_IFR_DATE_OP:
    //
    // If the op-code we are looking at is larger than the latest created NvMap - we likely encountered a dynamically
    // created entry which has an expanded NvMap requirement.  We won't save this information - but we need to adjust
    // the NvMap so that we can properly display the information
    //
    if ((UINTN) (Tag->StorageStart + Tag->StorageWidth) > VariableDefinition->VariableFakeSize) {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?