]> git.proxmox.com Git - mirror_edk2.git/blobdiff - 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
diff --git a/ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.c b/ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.c
new file mode 100644 (file)
index 0000000..0ce5271
--- /dev/null
@@ -0,0 +1,82 @@
+/** @file\r
+  Provides application point extension for "C" style main funciton \r
+\r
+Copyright (c) 2009, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Base.h>\r
+\r
+#include <Protocol/SimpleFileSystem.h>\r
+#include <Protocol/EfiShellInterface.h>\r
+#include <Protocol/EfiShellParameters.h>\r
+\r
+#include <Library/DebugLib.h>\r
+\r
+INT32 \r
+EFIAPI \r
+main(\r
+  UINTN Argc, \r
+  CHAR16 **Argv\r
+);\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ShellCEntryLib(\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  ){\r
+  INT32                         ReturnFromMain;\r
+  EFI_SHELL_PARAMETERS_PROTOCOL *EfiShellParametersProtocol;\r
+  EFI_SHELL_INTERFACE           *EfiShellInterface;\r
+  EFI_STATUS                    Status;\r
+\r
+  ReturnFromMain = -1;\r
+  EfiShellParametersProtocol = NULL;\r
+  EfiShellInterface = NULL;\r
+\r
+  Status = SystemTable->BootServices->OpenProtocol(ImageHandle, \r
+                             &gEfiShellParametersProtocolGuid,\r
+                             (VOID **)&EfiShellParametersProtocol,\r
+                             ImageHandle,\r
+                             NULL,\r
+                             EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                             );\r
+  if (!EFI_ERROR(Status)) {\r
+    //\r
+    // use shell 2.0 interface\r
+    //\r
+    ReturnFromMain = main(EfiShellInterface->Argc, EfiShellInterface->Argv);\r
+  } else {\r
+    //\r
+    // try to get shell 1.0 interface instead.\r
+    //\r
+    Status = SystemTable->BootServices->OpenProtocol(ImageHandle, \r
+                               &gEfiShellInterfaceGuid,\r
+                               (VOID **)&EfiShellInterface,\r
+                               ImageHandle,\r
+                               NULL,\r
+                               EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                               );\r
+    if (!EFI_ERROR(Status)) {\r
+      //\r
+      // use shell 1.0 interface\r
+      // \r
+      ReturnFromMain = main(EfiShellParametersProtocol->Argc, EfiShellParametersProtocol->Argv);\r
+    } else {\r
+      ASSERT(FALSE);\r
+    }\r
+  }\r
+  if (ReturnFromMain == 0) {\r
+    return (EFI_SUCCESS);\r
+  } else {\r
+    return (EFI_UNSUPPORTED);\r
+  }\r
+}\r