]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.c
udk2010.up2.shell initial release.
[mirror_edk2.git] / ShellPkg / Library / UefiShellCEntryLib / UefiShellCEntryLib.c
1 /** @file
2 Provides application point extension for "C" style main funciton
3
4 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include <Base.h>
16
17 #include <Protocol/SimpleFileSystem.h>
18 #include <Protocol/LoadedImage.h>
19 #include <Protocol/EfiShellInterface.h>
20 #include <Protocol/EfiShellParameters.h>
21
22 #include <Library/ShellCEntryLib.h>
23 #include <Library/DebugLib.h>
24
25 /**
26 UEFI entry point for an application that will in turn call the
27 ShellAppMain function which has parameters similar to a standard C
28 main function.
29
30 An application that uses UefiShellCEntryLib must have a ShellAppMain
31 function as prototyped in Include/Library/ShellCEntryLib.h.
32
33 @param ImageHandle The image handle of the UEFI Application.
34 @param SystemTable A pointer to the EFI System Table.
35
36 @retval EFI_SUCCESS The application exited normally.
37 @retval Other An error occurred.
38
39 **/
40 EFI_STATUS
41 EFIAPI
42 ShellCEntryLib (
43 IN EFI_HANDLE ImageHandle,
44 IN EFI_SYSTEM_TABLE *SystemTable
45 )
46 {
47 INTN ReturnFromMain;
48 EFI_SHELL_PARAMETERS_PROTOCOL *EfiShellParametersProtocol;
49 EFI_SHELL_INTERFACE *EfiShellInterface;
50 EFI_STATUS Status;
51
52 ReturnFromMain = -1;
53 EfiShellParametersProtocol = NULL;
54 EfiShellInterface = NULL;
55
56 Status = SystemTable->BootServices->OpenProtocol(ImageHandle,
57 &gEfiShellParametersProtocolGuid,
58 (VOID **)&EfiShellParametersProtocol,
59 ImageHandle,
60 NULL,
61 EFI_OPEN_PROTOCOL_GET_PROTOCOL
62 );
63 if (!EFI_ERROR(Status)) {
64 //
65 // use shell 2.0 interface
66 //
67 ReturnFromMain = ShellAppMain (
68 EfiShellParametersProtocol->Argc,
69 EfiShellParametersProtocol->Argv
70 );
71 } else {
72 //
73 // try to get shell 1.0 interface instead.
74 //
75 Status = SystemTable->BootServices->OpenProtocol(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 if (ReturnFromMain == 0) {
95 return (EFI_SUCCESS);
96 } else {
97 return (EFI_UNSUPPORTED);
98 }
99 }