Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

150 lines
3.9 KiB

  1. /*++
  2. Copyright (c) 1998 Intel Corporation
  3. Module Name:
  4. init.c
  5. Abstract:
  6. Intialize the shell library
  7. Revision History
  8. --*/
  9. #include "shelllib.h"
  10. /*
  11. *
  12. */
  13. EFI_STATUS
  14. InitializeShellApplication (
  15. IN EFI_HANDLE ImageHandle,
  16. IN EFI_SYSTEM_TABLE *SystemTable
  17. )
  18. {
  19. EFI_STATUS Status;
  20. EFI_HANDLE Handle;
  21. UINTN BufferSize;
  22. /*
  23. * Shell app lib is a super set of the default lib.
  24. * Initialize the default lib first
  25. */
  26. InitializeLib (ImageHandle, SystemTable);
  27. ST = SystemTable;
  28. /*
  29. * Connect to the shell interface
  30. */
  31. Status = BS->HandleProtocol(ImageHandle, &ShellInterfaceProtocol, (VOID*)&SI);
  32. if (EFI_ERROR(Status)) {
  33. DEBUG((D_ERROR, "InitShellApp: Application not started from Shell\n"));
  34. Print (L"%EInitShellApp: Application not started from Shell%N\n");
  35. BS->Exit (ImageHandle, Status, 0, NULL);
  36. }
  37. /*
  38. * Connect to the shell environment
  39. */
  40. BufferSize = sizeof(Handle);
  41. Status = BS->LocateHandle(ByProtocol, &ShellEnvProtocol, NULL, &BufferSize, &Handle);
  42. if (EFI_ERROR(Status)) {
  43. DEBUG((D_ERROR, "InitShellApp: Shell environment interfaces not found\n"));
  44. Print (L"%EInitShellApp: Shell environment interfaces not found%N\n");
  45. BS->Exit (ImageHandle, Status, 0, NULL);
  46. }
  47. Status = BS->HandleProtocol(Handle, &ShellEnvProtocol, (VOID*)&SE);
  48. ASSERT (!EFI_ERROR(Status));
  49. /*
  50. * Done with init
  51. */
  52. return Status;
  53. }
  54. VOID
  55. InstallInternalShellCommand (
  56. IN EFI_HANDLE ImageHandle,
  57. IN EFI_SYSTEM_TABLE *SystemTable,
  58. IN SHELLENV_INTERNAL_COMMAND Dispatch,
  59. IN CHAR16 *Cmd,
  60. IN CHAR16 *CmdFormat,
  61. IN CHAR16 *CmdHelpLine,
  62. IN VOID *CmdVerboseHelp
  63. )
  64. {
  65. VOID *Junk;
  66. UINTN BufferSize;
  67. EFI_HANDLE Handle;
  68. EFI_LOADED_IMAGE *ImageInfo;
  69. EFI_STATUS Status;
  70. /*
  71. * Initialize lib functions
  72. */
  73. InitializeLib (ImageHandle, SystemTable);
  74. /*
  75. * If this app has a ShellInterface, then we are not installing as an
  76. * internal command
  77. */
  78. Status = BS->HandleProtocol(ImageHandle, &ShellInterfaceProtocol, &Junk);
  79. if (!EFI_ERROR(Status)) {
  80. return ;
  81. }
  82. /*
  83. * Check to make sure we are loaded as a boot service driver. if not
  84. * we are not installing as an internal command
  85. */
  86. Status = BS->HandleProtocol(ImageHandle, &LoadedImageProtocol, (VOID*)&ImageInfo);
  87. if (EFI_ERROR(Status) || ImageInfo->ImageCodeType != EfiBootServicesCode) {
  88. return ;
  89. }
  90. /*
  91. * OK - we are to install this tool as an internal command.
  92. */
  93. BufferSize = sizeof(Handle);
  94. Status = BS->LocateHandle(ByProtocol, &ShellEnvProtocol, NULL, &BufferSize, &Handle);
  95. if (EFI_ERROR(Status)) {
  96. DEBUG((D_INIT|D_ERROR, "InstallInternalCommand: could not find shell environment\n"));
  97. BS->Exit (ImageHandle, Status, 0, NULL);
  98. }
  99. Status = BS->HandleProtocol(Handle, &ShellEnvProtocol, (VOID*)&SE);
  100. ASSERT (!EFI_ERROR(Status));
  101. /*
  102. * Add it to the environment
  103. */
  104. Status = SE->AddCmd (Dispatch, Cmd, CmdFormat, CmdHelpLine, CmdVerboseHelp);
  105. DEBUG((D_INIT, "InstallInternalCommand: %hs - %r\n", Cmd, Status));
  106. /*
  107. * Since we're only installing not (and not running), and we've done the install
  108. * call exit. The nshell app's entry point will be invoked again when it's
  109. * run from "execute commandline"
  110. */
  111. BS->Exit (ImageHandle, Status, 0, NULL);
  112. }