• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2   Provides application point extension for "C" style main funciton
3 
4   Copyright (c) 2009 - 2013, 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   Note that the Shell uses POSITIVE integers for error values, while UEFI
34   uses NEGATIVE values.  If the application is to be used within a script,
35   it needs to return one of the SHELL_STATUS values defined in ShellBase.h.
36 
37   @param  ImageHandle  The image handle of the UEFI Application.
38   @param  SystemTable  A pointer to the EFI System Table.
39 
40   @retval  EFI_SUCCESS               The application exited normally.
41   @retval  Other                     An error occurred.
42 
43 **/
44 EFI_STATUS
45 EFIAPI
ShellCEntryLib(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE * SystemTable)46 ShellCEntryLib (
47   IN EFI_HANDLE        ImageHandle,
48   IN EFI_SYSTEM_TABLE  *SystemTable
49   )
50 {
51   INTN                           ReturnFromMain;
52   EFI_SHELL_PARAMETERS_PROTOCOL *EfiShellParametersProtocol;
53   EFI_SHELL_INTERFACE           *EfiShellInterface;
54   EFI_STATUS                    Status;
55 
56   ReturnFromMain = -1;
57   EfiShellParametersProtocol = NULL;
58   EfiShellInterface = NULL;
59 
60   Status = SystemTable->BootServices->OpenProtocol(ImageHandle,
61                              &gEfiShellParametersProtocolGuid,
62                              (VOID **)&EfiShellParametersProtocol,
63                              ImageHandle,
64                              NULL,
65                              EFI_OPEN_PROTOCOL_GET_PROTOCOL
66                             );
67   if (!EFI_ERROR(Status)) {
68     //
69     // use shell 2.0 interface
70     //
71     ReturnFromMain = ShellAppMain (
72                        EfiShellParametersProtocol->Argc,
73                        EfiShellParametersProtocol->Argv
74                       );
75   } else {
76     //
77     // try to get shell 1.0 interface instead.
78     //
79     Status = SystemTable->BootServices->OpenProtocol(ImageHandle,
80                                &gEfiShellInterfaceGuid,
81                                (VOID **)&EfiShellInterface,
82                                ImageHandle,
83                                NULL,
84                                EFI_OPEN_PROTOCOL_GET_PROTOCOL
85                               );
86     if (!EFI_ERROR(Status)) {
87       //
88       // use shell 1.0 interface
89       //
90       ReturnFromMain = ShellAppMain (
91                          EfiShellInterface->Argc,
92                          EfiShellInterface->Argv
93                         );
94     } else {
95       ASSERT(FALSE);
96     }
97   }
98   return ReturnFromMain;
99 }
100