UefiShellCEntryLib.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /** @file
  2. Provides application point extension for "C" style main function
  3. Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <Base.h>
  7. #include <Protocol/SimpleFileSystem.h>
  8. #include <Protocol/LoadedImage.h>
  9. #include <Protocol/EfiShellInterface.h>
  10. #include <Protocol/ShellParameters.h>
  11. #include <Library/ShellCEntryLib.h>
  12. #include <Library/DebugLib.h>
  13. /**
  14. UEFI entry point for an application that will in turn call the
  15. ShellAppMain function which has parameters similar to a standard C
  16. main function.
  17. An application that uses UefiShellCEntryLib must have a ShellAppMain
  18. function as prototyped in Include/Library/ShellCEntryLib.h.
  19. Note that the Shell uses POSITIVE integers for error values, while UEFI
  20. uses NEGATIVE values. If the application is to be used within a script,
  21. it needs to return one of the SHELL_STATUS values defined in Protocol/Shell.h.
  22. @param ImageHandle The image handle of the UEFI Application.
  23. @param SystemTable A pointer to the EFI System Table.
  24. @retval EFI_SUCCESS The application exited normally.
  25. @retval Other An error occurred.
  26. **/
  27. EFI_STATUS
  28. EFIAPI
  29. ShellCEntryLib (
  30. IN EFI_HANDLE ImageHandle,
  31. IN EFI_SYSTEM_TABLE *SystemTable
  32. )
  33. {
  34. INTN ReturnFromMain;
  35. EFI_SHELL_PARAMETERS_PROTOCOL *EfiShellParametersProtocol;
  36. EFI_SHELL_INTERFACE *EfiShellInterface;
  37. EFI_STATUS Status;
  38. ReturnFromMain = -1;
  39. EfiShellParametersProtocol = NULL;
  40. EfiShellInterface = NULL;
  41. Status = SystemTable->BootServices->OpenProtocol (
  42. ImageHandle,
  43. &gEfiShellParametersProtocolGuid,
  44. (VOID **)&EfiShellParametersProtocol,
  45. ImageHandle,
  46. NULL,
  47. EFI_OPEN_PROTOCOL_GET_PROTOCOL
  48. );
  49. if (!EFI_ERROR (Status)) {
  50. //
  51. // use shell 2.0 interface
  52. //
  53. ReturnFromMain = ShellAppMain (
  54. EfiShellParametersProtocol->Argc,
  55. EfiShellParametersProtocol->Argv
  56. );
  57. } else {
  58. //
  59. // try to get shell 1.0 interface instead.
  60. //
  61. Status = SystemTable->BootServices->OpenProtocol (
  62. ImageHandle,
  63. &gEfiShellInterfaceGuid,
  64. (VOID **)&EfiShellInterface,
  65. ImageHandle,
  66. NULL,
  67. EFI_OPEN_PROTOCOL_GET_PROTOCOL
  68. );
  69. if (!EFI_ERROR (Status)) {
  70. //
  71. // use shell 1.0 interface
  72. //
  73. ReturnFromMain = ShellAppMain (
  74. EfiShellInterface->Argc,
  75. EfiShellInterface->Argv
  76. );
  77. } else {
  78. ASSERT (FALSE);
  79. }
  80. }
  81. return ReturnFromMain;
  82. }