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 - 2018, Intel Corporation. All rights reserved.<BR>
|
---|
6 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
7 |
|
---|
8 | **/
|
---|
9 |
|
---|
10 | #include "UefiShellDebug1CommandsLib.h"
|
---|
11 |
|
---|
12 | /**
|
---|
13 | Function for 'mode' command.
|
---|
14 |
|
---|
15 | @param[in] ImageHandle Handle to the Image (NULL if Internal).
|
---|
16 | @param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
---|
17 | **/
|
---|
18 | SHELL_STATUS
|
---|
19 | EFIAPI
|
---|
20 | ShellCommandRunMode (
|
---|
21 | IN EFI_HANDLE ImageHandle,
|
---|
22 | IN EFI_SYSTEM_TABLE *SystemTable
|
---|
23 | )
|
---|
24 | {
|
---|
25 | EFI_STATUS Status;
|
---|
26 | LIST_ENTRY *Package;
|
---|
27 | CHAR16 *ProblemParam;
|
---|
28 | SHELL_STATUS ShellStatus;
|
---|
29 | UINTN NewCol;
|
---|
30 | UINTN NewRow;
|
---|
31 | UINTN Col;
|
---|
32 | UINTN Row;
|
---|
33 | CONST CHAR16 *Temp;
|
---|
34 | BOOLEAN Done;
|
---|
35 | INT32 LoopVar;
|
---|
36 |
|
---|
37 | ShellStatus = SHELL_SUCCESS;
|
---|
38 | Status = EFI_SUCCESS;
|
---|
39 |
|
---|
40 | //
|
---|
41 | // initialize the shell lib (we must be in non-auto-init...)
|
---|
42 | //
|
---|
43 | Status = ShellInitialize ();
|
---|
44 | ASSERT_EFI_ERROR (Status);
|
---|
45 |
|
---|
46 | Status = CommandInit ();
|
---|
47 | ASSERT_EFI_ERROR (Status);
|
---|
48 |
|
---|
49 | //
|
---|
50 | // parse the command line
|
---|
51 | //
|
---|
52 | Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
|
---|
53 | if (EFI_ERROR (Status)) {
|
---|
54 | if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
|
---|
55 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"mode", ProblemParam);
|
---|
56 | FreePool (ProblemParam);
|
---|
57 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
58 | } else {
|
---|
59 | ASSERT (FALSE);
|
---|
60 | }
|
---|
61 | } else {
|
---|
62 | if (ShellCommandLineGetCount (Package) > 3) {
|
---|
63 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"mode");
|
---|
64 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
65 | } else if (ShellCommandLineGetCount (Package) == 2) {
|
---|
66 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"mode");
|
---|
67 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
68 | } else if (ShellCommandLineGetCount (Package) == 3) {
|
---|
69 | Temp = ShellCommandLineGetRawValue (Package, 1);
|
---|
70 | if (!ShellIsHexOrDecimalNumber (Temp, FALSE, FALSE)) {
|
---|
71 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mode", Temp);
|
---|
72 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
73 | }
|
---|
74 |
|
---|
75 | NewCol = ShellStrToUintn (Temp);
|
---|
76 | Temp = ShellCommandLineGetRawValue (Package, 2);
|
---|
77 | if (!ShellIsHexOrDecimalNumber (Temp, FALSE, FALSE)) {
|
---|
78 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mode", Temp);
|
---|
79 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
80 | }
|
---|
81 |
|
---|
82 | NewRow = ShellStrToUintn (Temp);
|
---|
83 |
|
---|
84 | for (LoopVar = 0, Done = FALSE; LoopVar < gST->ConOut->Mode->MaxMode && ShellStatus == SHELL_SUCCESS; LoopVar++) {
|
---|
85 | Status = gST->ConOut->QueryMode (gST->ConOut, LoopVar, &Col, &Row);
|
---|
86 | if (EFI_ERROR (Status)) {
|
---|
87 | continue;
|
---|
88 | }
|
---|
89 |
|
---|
90 | if ((Col == NewCol) && (Row == NewRow)) {
|
---|
91 | Status = gST->ConOut->SetMode (gST->ConOut, LoopVar);
|
---|
92 | if (EFI_ERROR (Status)) {
|
---|
93 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_MODE_SET_FAIL), gShellDebug1HiiHandle, L"mode");
|
---|
94 | ShellStatus = SHELL_DEVICE_ERROR;
|
---|
95 | } else {
|
---|
96 | // worked fine...
|
---|
97 | Done = TRUE;
|
---|
98 | }
|
---|
99 |
|
---|
100 | break;
|
---|
101 | }
|
---|
102 | }
|
---|
103 |
|
---|
104 | if (!Done) {
|
---|
105 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_MODE_NO_MATCH), gShellDebug1HiiHandle, L"mode");
|
---|
106 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
107 | }
|
---|
108 | } else if (ShellCommandLineGetCount (Package) == 1) {
|
---|
109 | //
|
---|
110 | // print out valid
|
---|
111 | //
|
---|
112 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_MODE_LIST_HEAD), gShellDebug1HiiHandle);
|
---|
113 | for (LoopVar = 0, Done = FALSE; LoopVar < gST->ConOut->Mode->MaxMode && ShellStatus == SHELL_SUCCESS; LoopVar++) {
|
---|
114 | Status = gST->ConOut->QueryMode (gST->ConOut, LoopVar, &Col, &Row);
|
---|
115 | if (EFI_ERROR (Status)) {
|
---|
116 | continue;
|
---|
117 | }
|
---|
118 |
|
---|
119 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_MODE_LIST_ITEM), gShellDebug1HiiHandle, Col, Row, LoopVar == gST->ConOut->Mode->Mode ? L'*' : L' ');
|
---|
120 | }
|
---|
121 | }
|
---|
122 |
|
---|
123 | ShellCommandLineFreeVarList (Package);
|
---|
124 | }
|
---|
125 |
|
---|
126 | return (ShellStatus);
|
---|
127 | }
|
---|