]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.c
ShellPkg\Library\UefiShellCEntryLib\UefiShellCEntryLib.c:
[mirror_edk2.git] / ShellPkg / Library / UefiShellCEntryLib / UefiShellCEntryLib.c
CommitLineData
b1f95a06 1/** @file\r
1e6e84c7 2 Provides application point extension for "C" style main funciton\r
b1f95a06 3\r
e643951b 4 Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>\r
1e6e84c7 5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
b1f95a06 9\r
1e6e84c7 10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
b1f95a06 12\r
13**/\r
14\r
15#include <Base.h>\r
16\r
17#include <Protocol/SimpleFileSystem.h>\r
b3011f40 18#include <Protocol/LoadedImage.h>\r
b1f95a06 19#include <Protocol/EfiShellInterface.h>\r
20#include <Protocol/EfiShellParameters.h>\r
21\r
322016e5 22#include <Library/ShellCEntryLib.h>\r
b1f95a06 23#include <Library/DebugLib.h>\r
24\r
39157531 25/**\r
322016e5 26 UEFI entry point for an application that will in turn call the\r
27 ShellAppMain function which has parameters similar to a standard C\r
28 main function.\r
39157531 29\r
322016e5 30 An application that uses UefiShellCEntryLib must have a ShellAppMain\r
31 function as prototyped in Include/Library/ShellCEntryLib.h.\r
32\r
e643951b 33 Note that the Shell uses POSITIVE integers for error values, while UEFI\r
34 uses NEGATIVE values. If the application is to be used within a script,\r
35 it needs to return one of the SHELL_STATUS values defined in ShellBase.h.\r
36\r
322016e5 37 @param ImageHandle The image handle of the UEFI Application.\r
38 @param SystemTable A pointer to the EFI System Table.\r
39\r
40 @retval EFI_SUCCESS The application exited normally.\r
41 @retval Other An error occurred.\r
39157531 42\r
39157531 43**/\r
b1f95a06 44EFI_STATUS\r
45EFIAPI\r
39157531 46ShellCEntryLib (\r
b1f95a06 47 IN EFI_HANDLE ImageHandle,\r
48 IN EFI_SYSTEM_TABLE *SystemTable\r
39157531 49 )\r
50{\r
9eb53ac3 51 INTN ReturnFromMain;\r
b1f95a06 52 EFI_SHELL_PARAMETERS_PROTOCOL *EfiShellParametersProtocol;\r
53 EFI_SHELL_INTERFACE *EfiShellInterface;\r
54 EFI_STATUS Status;\r
55\r
56 ReturnFromMain = -1;\r
57 EfiShellParametersProtocol = NULL;\r
58 EfiShellInterface = NULL;\r
59\r
1e6e84c7 60 Status = SystemTable->BootServices->OpenProtocol(ImageHandle,\r
b1f95a06 61 &gEfiShellParametersProtocolGuid,\r
62 (VOID **)&EfiShellParametersProtocol,\r
63 ImageHandle,\r
64 NULL,\r
65 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
a405b86d 66 );\r
b1f95a06 67 if (!EFI_ERROR(Status)) {\r
68 //\r
69 // use shell 2.0 interface\r
70 //\r
39157531 71 ReturnFromMain = ShellAppMain (\r
92fbbb5d 72 EfiShellParametersProtocol->Argc,\r
73 EfiShellParametersProtocol->Argv\r
a405b86d 74 );\r
b1f95a06 75 } else {\r
76 //\r
77 // try to get shell 1.0 interface instead.\r
78 //\r
1e6e84c7 79 Status = SystemTable->BootServices->OpenProtocol(ImageHandle,\r
b1f95a06 80 &gEfiShellInterfaceGuid,\r
81 (VOID **)&EfiShellInterface,\r
82 ImageHandle,\r
83 NULL,\r
84 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
a405b86d 85 );\r
b1f95a06 86 if (!EFI_ERROR(Status)) {\r
87 //\r
88 // use shell 1.0 interface\r
1e6e84c7 89 //\r
39157531 90 ReturnFromMain = ShellAppMain (\r
92fbbb5d 91 EfiShellInterface->Argc,\r
92 EfiShellInterface->Argv\r
a405b86d 93 );\r
b1f95a06 94 } else {\r
95 ASSERT(FALSE);\r
96 }\r
97 }\r
e643951b 98 return ReturnFromMain;\r
b1f95a06 99}\r