]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.c
19ade44563b9aa4930a29be00a5084cedf238fc8
[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, Intel Corporation
5 All rights reserved. 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/EfiShellInterface.h>
19 #include <Protocol/EfiShellParameters.h>
20
21 #include <Library/DebugLib.h>
22
23 INTN
24 EFIAPI
25 ShellAppMain (
26 IN INTN Argc,
27 IN CHAR16 **Argv
28 );
29
30 /**
31 UEFI entry point for an application that will in turn call a C
32 style ShellAppMain function.
33
34 This application must have a function defined as follows:
35
36 INTN
37 EFIAPI
38 ShellAppMain (
39 IN INTN Argc,
40 IN CHAR16 **Argv
41 );
42 **/
43 EFI_STATUS
44 EFIAPI
45 ShellCEntryLib (
46 IN EFI_HANDLE ImageHandle,
47 IN EFI_SYSTEM_TABLE *SystemTable
48 )
49 {
50 INT32 ReturnFromMain;
51 EFI_SHELL_PARAMETERS_PROTOCOL *EfiShellParametersProtocol;
52 EFI_SHELL_INTERFACE *EfiShellInterface;
53 EFI_STATUS Status;
54
55 ReturnFromMain = -1;
56 EfiShellParametersProtocol = NULL;
57 EfiShellInterface = NULL;
58
59 Status = SystemTable->BootServices->OpenProtocol(ImageHandle,
60 &gEfiShellParametersProtocolGuid,
61 (VOID **)&EfiShellParametersProtocol,
62 ImageHandle,
63 NULL,
64 EFI_OPEN_PROTOCOL_GET_PROTOCOL
65 );
66 if (!EFI_ERROR(Status)) {
67 //
68 // use shell 2.0 interface
69 //
70 ReturnFromMain = ShellAppMain (
71 EfiShellInterface->Argc,
72 EfiShellInterface->Argv
73 );
74 } else {
75 //
76 // try to get shell 1.0 interface instead.
77 //
78 Status = SystemTable->BootServices->OpenProtocol(ImageHandle,
79 &gEfiShellInterfaceGuid,
80 (VOID **)&EfiShellInterface,
81 ImageHandle,
82 NULL,
83 EFI_OPEN_PROTOCOL_GET_PROTOCOL
84 );
85 if (!EFI_ERROR(Status)) {
86 //
87 // use shell 1.0 interface
88 //
89 ReturnFromMain = ShellAppMain (
90 EfiShellParametersProtocol->Argc,
91 EfiShellParametersProtocol->Argv
92 );
93 } else {
94 ASSERT(FALSE);
95 }
96 }
97 if (ReturnFromMain == 0) {
98 return (EFI_SUCCESS);
99 } else {
100 return (EFI_UNSUPPORTED);
101 }
102 }