]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.c
Updating with new functions and adding "C" style entrypoint library with example...
[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 INT32
24 EFIAPI
25 main(
26 UINTN Argc,
27 CHAR16 **Argv
28 );
29
30 EFI_STATUS
31 EFIAPI
32 ShellCEntryLib(
33 IN EFI_HANDLE ImageHandle,
34 IN EFI_SYSTEM_TABLE *SystemTable
35 ){
36 INT32 ReturnFromMain;
37 EFI_SHELL_PARAMETERS_PROTOCOL *EfiShellParametersProtocol;
38 EFI_SHELL_INTERFACE *EfiShellInterface;
39 EFI_STATUS Status;
40
41 ReturnFromMain = -1;
42 EfiShellParametersProtocol = NULL;
43 EfiShellInterface = NULL;
44
45 Status = SystemTable->BootServices->OpenProtocol(ImageHandle,
46 &gEfiShellParametersProtocolGuid,
47 (VOID **)&EfiShellParametersProtocol,
48 ImageHandle,
49 NULL,
50 EFI_OPEN_PROTOCOL_GET_PROTOCOL
51 );
52 if (!EFI_ERROR(Status)) {
53 //
54 // use shell 2.0 interface
55 //
56 ReturnFromMain = main(EfiShellInterface->Argc, EfiShellInterface->Argv);
57 } else {
58 //
59 // try to get shell 1.0 interface instead.
60 //
61 Status = SystemTable->BootServices->OpenProtocol(ImageHandle,
62 &gEfiShellInterfaceGuid,
63 (VOID **)&EfiShellInterface,
64 ImageHandle,
65 NULL,
66 EFI_OPEN_PROTOCOL_GET_PROTOCOL
67 );
68 if (!EFI_ERROR(Status)) {
69 //
70 // use shell 1.0 interface
71 //
72 ReturnFromMain = main(EfiShellParametersProtocol->Argc, EfiShellParametersProtocol->Argv);
73 } else {
74 ASSERT(FALSE);
75 }
76 }
77 if (ReturnFromMain == 0) {
78 return (EFI_SUCCESS);
79 } else {
80 return (EFI_UNSUPPORTED);
81 }
82 }