]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / ShellPkg / Library / UefiShellCEntryLib / UefiShellCEntryLib.c
1 /** @file
2 Provides application point extension for "C" style main function
3
4 Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include <Base.h>
10
11 #include <Protocol/SimpleFileSystem.h>
12 #include <Protocol/LoadedImage.h>
13 #include <Protocol/EfiShellInterface.h>
14 #include <Protocol/ShellParameters.h>
15
16 #include <Library/ShellCEntryLib.h>
17 #include <Library/DebugLib.h>
18
19 /**
20 UEFI entry point for an application that will in turn call the
21 ShellAppMain function which has parameters similar to a standard C
22 main function.
23
24 An application that uses UefiShellCEntryLib must have a ShellAppMain
25 function as prototyped in Include/Library/ShellCEntryLib.h.
26
27 Note that the Shell uses POSITIVE integers for error values, while UEFI
28 uses NEGATIVE values. If the application is to be used within a script,
29 it needs to return one of the SHELL_STATUS values defined in Protocol/Shell.h.
30
31 @param ImageHandle The image handle of the UEFI Application.
32 @param SystemTable A pointer to the EFI System Table.
33
34 @retval EFI_SUCCESS The application exited normally.
35 @retval Other An error occurred.
36
37 **/
38 EFI_STATUS
39 EFIAPI
40 ShellCEntryLib (
41 IN EFI_HANDLE ImageHandle,
42 IN EFI_SYSTEM_TABLE *SystemTable
43 )
44 {
45 INTN ReturnFromMain;
46 EFI_SHELL_PARAMETERS_PROTOCOL *EfiShellParametersProtocol;
47 EFI_SHELL_INTERFACE *EfiShellInterface;
48 EFI_STATUS Status;
49
50 ReturnFromMain = -1;
51 EfiShellParametersProtocol = NULL;
52 EfiShellInterface = NULL;
53
54 Status = SystemTable->BootServices->OpenProtocol (
55 ImageHandle,
56 &gEfiShellParametersProtocolGuid,
57 (VOID **)&EfiShellParametersProtocol,
58 ImageHandle,
59 NULL,
60 EFI_OPEN_PROTOCOL_GET_PROTOCOL
61 );
62 if (!EFI_ERROR (Status)) {
63 //
64 // use shell 2.0 interface
65 //
66 ReturnFromMain = ShellAppMain (
67 EfiShellParametersProtocol->Argc,
68 EfiShellParametersProtocol->Argv
69 );
70 } else {
71 //
72 // try to get shell 1.0 interface instead.
73 //
74 Status = SystemTable->BootServices->OpenProtocol (
75 ImageHandle,
76 &gEfiShellInterfaceGuid,
77 (VOID **)&EfiShellInterface,
78 ImageHandle,
79 NULL,
80 EFI_OPEN_PROTOCOL_GET_PROTOCOL
81 );
82 if (!EFI_ERROR (Status)) {
83 //
84 // use shell 1.0 interface
85 //
86 ReturnFromMain = ShellAppMain (
87 EfiShellInterface->Argc,
88 EfiShellInterface->Argv
89 );
90 } else {
91 ASSERT (FALSE);
92 }
93 }
94
95 return ReturnFromMain;
96 }