Vishal Bhoj | 82c8071 | 2015-12-15 21:13:33 +0530 | [diff] [blame^] | 1 | /** @file
|
| 2 | Main file for Mode shell Debug1 function.
|
| 3 |
|
| 4 | (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
|
| 5 | Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
|
| 6 | This program and the accompanying materials
|
| 7 | are licensed and made available under the terms and conditions of the BSD License
|
| 8 | which acModeanies this distribution. The full text of the license may be found at
|
| 9 | http://opensource.org/licenses/bsd-license.php
|
| 10 |
|
| 11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
| 12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
| 13 |
|
| 14 | **/
|
| 15 |
|
| 16 | #include "UefiShellDebug1CommandsLib.h"
|
| 17 |
|
| 18 | /**
|
| 19 | Function for 'mode' command.
|
| 20 |
|
| 21 | @param[in] ImageHandle Handle to the Image (NULL if Internal).
|
| 22 | @param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
| 23 | **/
|
| 24 | SHELL_STATUS
|
| 25 | EFIAPI
|
| 26 | ShellCommandRunMode (
|
| 27 | IN EFI_HANDLE ImageHandle,
|
| 28 | IN EFI_SYSTEM_TABLE *SystemTable
|
| 29 | )
|
| 30 | {
|
| 31 | EFI_STATUS Status;
|
| 32 | LIST_ENTRY *Package;
|
| 33 | CHAR16 *ProblemParam;
|
| 34 | SHELL_STATUS ShellStatus;
|
| 35 | UINTN NewCol;
|
| 36 | UINTN NewRow;
|
| 37 | UINTN Col;
|
| 38 | UINTN Row;
|
| 39 | CONST CHAR16 *Temp;
|
| 40 | BOOLEAN Done;
|
| 41 | INT32 LoopVar;
|
| 42 |
|
| 43 | ShellStatus = SHELL_SUCCESS;
|
| 44 | Status = EFI_SUCCESS;
|
| 45 |
|
| 46 | //
|
| 47 | // initialize the shell lib (we must be in non-auto-init...)
|
| 48 | //
|
| 49 | Status = ShellInitialize();
|
| 50 | ASSERT_EFI_ERROR(Status);
|
| 51 |
|
| 52 | Status = CommandInit();
|
| 53 | ASSERT_EFI_ERROR(Status);
|
| 54 |
|
| 55 | //
|
| 56 | // parse the command line
|
| 57 | //
|
| 58 | Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
|
| 59 | if (EFI_ERROR(Status)) {
|
| 60 | if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
| 61 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"mode", ProblemParam);
|
| 62 | FreePool(ProblemParam);
|
| 63 | ShellStatus = SHELL_INVALID_PARAMETER;
|
| 64 | } else {
|
| 65 | ASSERT(FALSE);
|
| 66 | }
|
| 67 | } else {
|
| 68 | if (ShellCommandLineGetCount(Package) > 3) {
|
| 69 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"mode");
|
| 70 | ShellStatus = SHELL_INVALID_PARAMETER;
|
| 71 | } else if (ShellCommandLineGetCount(Package) == 2) {
|
| 72 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"mode");
|
| 73 | ShellStatus = SHELL_INVALID_PARAMETER;
|
| 74 | } else if (ShellCommandLineGetCount(Package) == 3) {
|
| 75 | Temp = ShellCommandLineGetRawValue(Package, 1);
|
| 76 | if (!ShellIsHexOrDecimalNumber(Temp, FALSE, FALSE)) {
|
| 77 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mode", Temp);
|
| 78 | ShellStatus = SHELL_INVALID_PARAMETER;
|
| 79 | }
|
| 80 | NewCol = ShellStrToUintn(Temp);
|
| 81 | Temp = ShellCommandLineGetRawValue(Package, 2);
|
| 82 | if (!ShellIsHexOrDecimalNumber(Temp, FALSE, FALSE)) {
|
| 83 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mode", Temp);
|
| 84 | ShellStatus = SHELL_INVALID_PARAMETER;
|
| 85 | }
|
| 86 | NewRow = ShellStrToUintn(Temp);
|
| 87 |
|
| 88 | for (LoopVar = 0, Done = FALSE; LoopVar < gST->ConOut->Mode->MaxMode && ShellStatus == SHELL_SUCCESS ; LoopVar++) {
|
| 89 | Status = gST->ConOut->QueryMode(gST->ConOut, LoopVar, &Col, &Row);
|
| 90 | if (EFI_ERROR(Status)) {
|
| 91 | continue;
|
| 92 | }
|
| 93 | if (Col == NewCol && Row == NewRow) {
|
| 94 | Status = gST->ConOut->SetMode(gST->ConOut, LoopVar);
|
| 95 | if (EFI_ERROR(Status)) {
|
| 96 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MODE_SET_FAIL), gShellDebug1HiiHandle, L"mode");
|
| 97 | ShellStatus = SHELL_DEVICE_ERROR;
|
| 98 | } else {
|
| 99 | // worked fine...
|
| 100 | Done = TRUE;
|
| 101 | }
|
| 102 | break;
|
| 103 | }
|
| 104 | }
|
| 105 |
|
| 106 | if (!Done) {
|
| 107 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MODE_NO_MATCH), gShellDebug1HiiHandle, L"mode");
|
| 108 | ShellStatus = SHELL_INVALID_PARAMETER;
|
| 109 | }
|
| 110 |
|
| 111 | } else if (ShellCommandLineGetCount(Package) == 1) {
|
| 112 | //
|
| 113 | // print out valid
|
| 114 | //
|
| 115 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MODE_LIST_HEAD), gShellDebug1HiiHandle);
|
| 116 | for (LoopVar = 0, Done = FALSE; LoopVar < gST->ConOut->Mode->MaxMode && ShellStatus == SHELL_SUCCESS ; LoopVar++) {
|
| 117 | Status = gST->ConOut->QueryMode(gST->ConOut, LoopVar, &Col, &Row);
|
| 118 | if (EFI_ERROR(Status)) {
|
| 119 | continue;
|
| 120 | }
|
| 121 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MODE_LIST_ITEM), gShellDebug1HiiHandle, Col, Row, LoopVar == gST->ConOut->Mode->Mode?L'*':L' ');
|
| 122 | }
|
| 123 | }
|
| 124 | ShellCommandLineFreeVarList (Package);
|
| 125 | }
|
| 126 |
|
| 127 | return (ShellStatus);
|
| 128 | }
|