]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellLevel1CommandsLib/Exit.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel1CommandsLib / Exit.c
1 /** @file
2 Main file for exit shell level 1 function.
3
4 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include "UefiShellLevel1CommandsLib.h"
11
12 STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
13 { L"/b", TypeFlag },
14 { NULL, TypeMax }
15 };
16
17 /**
18 Function for 'exit' command.
19
20 @param[in] ImageHandle Handle to the Image (NULL if Internal).
21 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
22 **/
23 SHELL_STATUS
24 EFIAPI
25 ShellCommandRunExit (
26 IN EFI_HANDLE ImageHandle,
27 IN EFI_SYSTEM_TABLE *SystemTable
28 )
29 {
30 EFI_STATUS Status;
31 LIST_ENTRY *Package;
32 CHAR16 *ProblemParam;
33 SHELL_STATUS ShellStatus;
34 UINT64 RetVal;
35 CONST CHAR16 *Return;
36
37 ShellStatus = SHELL_SUCCESS;
38
39 //
40 // initialize the shell lib (we must be in non-auto-init...)
41 //
42 Status = ShellInitialize ();
43 ASSERT_EFI_ERROR (Status);
44
45 Status = CommandInit ();
46 ASSERT_EFI_ERROR (Status);
47
48 //
49 // parse the command line
50 //
51 Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
52 if (EFI_ERROR (Status)) {
53 if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
54 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel1HiiHandle, L"exit", ProblemParam);
55 FreePool (ProblemParam);
56 ShellStatus = SHELL_INVALID_PARAMETER;
57 } else {
58 ASSERT (FALSE);
59 }
60 } else {
61 //
62 // return the specified error code
63 //
64 Return = ShellCommandLineGetRawValue (Package, 1);
65 if (Return != NULL) {
66 Status = ShellConvertStringToUint64 (Return, &RetVal, FALSE, FALSE);
67 if (EFI_ERROR (Status)) {
68 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel1HiiHandle, L"exit", Return);
69 ShellStatus = SHELL_INVALID_PARAMETER;
70 } else {
71 //
72 // If we are in a batch file and /b then pass TRUE otherwise false...
73 //
74 ShellCommandRegisterExit ((BOOLEAN)(gEfiShellProtocol->BatchIsActive () && ShellCommandLineGetFlag (Package, L"/b")), RetVal);
75
76 ShellStatus = SHELL_SUCCESS;
77 }
78 } else {
79 // If we are in a batch file and /b then pass TRUE otherwise false...
80 //
81 ShellCommandRegisterExit ((BOOLEAN)(gEfiShellProtocol->BatchIsActive () && ShellCommandLineGetFlag (Package, L"/b")), 0);
82
83 ShellStatus = SHELL_SUCCESS;
84 }
85
86 ShellCommandLineFreeVarList (Package);
87 }
88
89 return (ShellStatus);
90 }