]>
Commit | Line | Data |
---|---|---|
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 | 38 | EFI_STATUS\r |
39 | EFIAPI\r | |
39157531 | 40 | ShellCEntryLib (\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 |
47d20b54 MK |
46 | EFI_SHELL_PARAMETERS_PROTOCOL *EfiShellParametersProtocol;\r |
47 | EFI_SHELL_INTERFACE *EfiShellInterface;\r | |
48 | EFI_STATUS Status;\r | |
b1f95a06 | 49 | \r |
47d20b54 | 50 | ReturnFromMain = -1;\r |
b1f95a06 | 51 | EfiShellParametersProtocol = NULL;\r |
47d20b54 | 52 | EfiShellInterface = NULL;\r |
b1f95a06 | 53 | \r |
47d20b54 MK |
54 | Status = SystemTable->BootServices->OpenProtocol (\r |
55 | ImageHandle,\r | |
56 | &gEfiShellParametersProtocolGuid,\r | |
57 | (VOID **)&EfiShellParametersProtocol,\r | |
58 | ImageHandle,\r | |
59 | NULL,\r | |
60 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
61 | );\r | |
62 | if (!EFI_ERROR (Status)) {\r | |
b1f95a06 | 63 | //\r |
64 | // use shell 2.0 interface\r | |
65 | //\r | |
39157531 | 66 | ReturnFromMain = ShellAppMain (\r |
92fbbb5d | 67 | EfiShellParametersProtocol->Argc,\r |
68 | EfiShellParametersProtocol->Argv\r | |
47d20b54 | 69 | );\r |
b1f95a06 | 70 | } else {\r |
71 | //\r | |
72 | // try to get shell 1.0 interface instead.\r | |
73 | //\r | |
47d20b54 MK |
74 | Status = SystemTable->BootServices->OpenProtocol (\r |
75 | ImageHandle,\r | |
76 | &gEfiShellInterfaceGuid,\r | |
77 | (VOID **)&EfiShellInterface,\r | |
78 | ImageHandle,\r | |
79 | NULL,\r | |
80 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
81 | );\r | |
82 | if (!EFI_ERROR (Status)) {\r | |
b1f95a06 | 83 | //\r |
84 | // use shell 1.0 interface\r | |
1e6e84c7 | 85 | //\r |
39157531 | 86 | ReturnFromMain = ShellAppMain (\r |
92fbbb5d | 87 | EfiShellInterface->Argc,\r |
88 | EfiShellInterface->Argv\r | |
47d20b54 | 89 | );\r |
b1f95a06 | 90 | } else {\r |
47d20b54 | 91 | ASSERT (FALSE);\r |
b1f95a06 | 92 | }\r |
93 | }\r | |
47d20b54 | 94 | \r |
e643951b | 95 | return ReturnFromMain;\r |
b1f95a06 | 96 | }\r |