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