]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - ShellPkg/Application/Shell/Shell.h
Update PeiCore to follow PI spec to retrieve GUIDED section data when ExtractionPpi...
[mirror_edk2.git] / ShellPkg / Application / Shell / Shell.h
... / ...
CommitLineData
1/** @file\r
2 function definitions for internal to shell functions.\r
3\r
4 Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#ifndef _SHELL_INTERNAL_HEADER_\r
16#define _SHELL_INTERNAL_HEADER_\r
17\r
18#include <Uefi.h>\r
19#include <ShellBase.h>\r
20\r
21#include <Guid/ShellVariableGuid.h>\r
22#include <Guid/ShellAliasGuid.h>\r
23\r
24#include <Protocol/LoadedImage.h>\r
25#include <Protocol/SimpleTextOut.h>\r
26#include <Protocol/EfiShell.h>\r
27#include <Protocol/EfiShellInterface.h>\r
28#include <Protocol/EfiShellEnvironment2.h>\r
29#include <Protocol/EfiShellParameters.h>\r
30#include <Protocol/BlockIo.h>\r
31\r
32#include <Library/BaseLib.h>\r
33#include <Library/UefiApplicationEntryPoint.h>\r
34#include <Library/UefiLib.h>\r
35#include <Library/DebugLib.h>\r
36#include <Library/MemoryAllocationLib.h>\r
37#include <Library/ShellCommandLib.h>\r
38#include <Library/UefiRuntimeServicesTableLib.h>\r
39#include <Library/UefiBootServicesTableLib.h>\r
40#include <Library/DevicePathLib.h>\r
41#include <Library/BaseMemoryLib.h>\r
42#include <Library/PcdLib.h>\r
43#include <Library/ShellLib.h>\r
44#include <Library/SortLib.h>\r
45#include <Library/HiiLib.h>\r
46#include <Library/PrintLib.h>\r
47#include <Library/HandleParsingLib.h>\r
48#include <Library/PathLib.h>\r
49#include <Library/FileHandleLib.h>\r
50\r
51#include "ShellParametersProtocol.h"\r
52#include "ShellProtocol.h"\r
53#include "ShellEnvVar.h"\r
54#include "ConsoleLogger.h"\r
55#include "ShellManParser.h"\r
56#include "ConsoleWrappers.h"\r
57#include "FileHandleWrappers.h"\r
58\r
59typedef struct {\r
60 LIST_ENTRY Link; ///< Standard linked list handler.\r
61 SHELL_FILE_HANDLE *SplitStdOut; ///< ConsoleOut for use in the split.\r
62 SHELL_FILE_HANDLE *SplitStdIn; ///< ConsoleIn for use in the split.\r
63} SPLIT_LIST;\r
64\r
65typedef struct {\r
66 UINT32 Startup:1; ///< Was "-startup" found on command line.\r
67 UINT32 NoStartup:1; ///< Was "-nostartup" found on command line.\r
68 UINT32 NoConsoleOut:1; ///< Was "-noconsoleout" found on command line.\r
69 UINT32 NoConsoleIn:1; ///< Was "-noconsolein" found on command line.\r
70 UINT32 NoInterrupt:1; ///< Was "-nointerrupt" found on command line.\r
71 UINT32 NoMap:1; ///< Was "-nomap" found on command line.\r
72 UINT32 NoVersion:1; ///< Was "-noversion" found on command line.\r
73 UINT32 Delay:1; ///< Was "-delay[:n] found on command line\r
74 UINT32 Exit:1; ///< Was "-_exit" found on command line\r
75 UINT32 Reserved:7; ///< Extra bits\r
76} SHELL_BITS;\r
77\r
78typedef union {\r
79 SHELL_BITS Bits;\r
80 UINT16 AllBits;\r
81} SHELL_BIT_UNION;\r
82\r
83typedef struct {\r
84 SHELL_BIT_UNION BitUnion;\r
85 UINTN Delay; ///< Seconds of delay default:5.\r
86 CHAR16 *FileName; ///< Filename to run upon successful initialization.\r
87 CHAR16 *FileOptions; ///< Options to pass to FileName.\r
88} SHELL_INIT_SETTINGS;\r
89\r
90typedef struct {\r
91 BUFFER_LIST CommandHistory;\r
92 UINTN VisibleRowNumber;\r
93 UINTN OriginalVisibleRowNumber;\r
94 BOOLEAN InsertMode; ///< Is the current typing mode insert (FALSE = overwrite).\r
95} SHELL_VIEWING_SETTINGS;\r
96\r
97typedef struct {\r
98 EFI_SHELL_PARAMETERS_PROTOCOL *NewShellParametersProtocol;\r
99 EFI_SHELL_PROTOCOL21 *NewEfiShellProtocol;\r
100 BOOLEAN PageBreakEnabled;\r
101 BOOLEAN RootShellInstance;\r
102 SHELL_INIT_SETTINGS ShellInitSettings;\r
103 BUFFER_LIST BufferToFreeList; ///< List of buffers that were returned to the user to free.\r
104 SHELL_VIEWING_SETTINGS ViewingSettings;\r
105 EFI_HII_HANDLE HiiHandle; ///< Handle from HiiLib.\r
106 UINTN LogScreenCount; ///< How many screens of log information to save.\r
107 EFI_EVENT UserBreakTimer; ///< Timer event for polling for CTRL-C.\r
108 EFI_DEVICE_PATH_PROTOCOL *ImageDevPath; ///< DevicePath for ourselves.\r
109 EFI_DEVICE_PATH_PROTOCOL *FileDevPath; ///< DevicePath for ourselves.\r
110 CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo; ///< Pointer for ConsoleInformation.\r
111 EFI_SHELL_PARAMETERS_PROTOCOL *OldShellParameters; ///< old shell parameters to reinstall upon exiting.\r
112 SHELL_PROTOCOL_HANDLE_LIST OldShellList; ///< List of other instances to reinstall when closing.\r
113 SPLIT_LIST SplitList; ///< List of Splits in FILO stack.\r
114 VOID *CtrlCNotifyHandle1; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
115 VOID *CtrlCNotifyHandle2; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
116 VOID *CtrlCNotifyHandle3; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
117 VOID *CtrlCNotifyHandle4; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
118 VOID *CtrlSNotifyHandle1; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
119 VOID *CtrlSNotifyHandle2; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
120 VOID *CtrlSNotifyHandle3; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
121 VOID *CtrlSNotifyHandle4; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
122 BOOLEAN HaltOutput; ///< TRUE to start a CTRL-S halt.\r
123} SHELL_INFO;\r
124\r
125extern SHELL_INFO ShellInfoObject;\r
126\r
127typedef enum {\r
128 Internal_Command,\r
129 Script_File_Name,\r
130 Efi_Application,\r
131 File_Sys_Change,\r
132 Unknown_Invalid\r
133} SHELL_OPERATION_TYPES;\r
134\r
135/**\r
136 Converts the command line to it's post-processed form. this replaces variables and alias' per UEFI Shell spec.\r
137\r
138 @param[in,out] CmdLine pointer to the command line to update\r
139\r
140 @retval EFI_SUCCESS The operation was successful\r
141 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r
142 @return some other error occured\r
143**/\r
144EFI_STATUS\r
145EFIAPI\r
146ProcessCommandLineToFinal(\r
147 IN OUT CHAR16 **CmdLine\r
148 );\r
149\r
150/**\r
151 Function to update the shell variable "lasterror".\r
152\r
153 @param[in] ErrorCode the error code to put into lasterror\r
154**/\r
155EFI_STATUS\r
156EFIAPI\r
157SetLastError(\r
158 IN CONST SHELL_STATUS ErrorCode\r
159 );\r
160\r
161/**\r
162 Sets all the alias' that were registered with the ShellCommandLib library.\r
163\r
164 @retval EFI_SUCCESS all init commands were run sucessfully.\r
165**/\r
166EFI_STATUS\r
167EFIAPI\r
168SetBuiltInAlias(\r
169 VOID\r
170 );\r
171\r
172/**\r
173 This function will populate the 2 device path protocol parameters based on the\r
174 global gImageHandle. the DevPath will point to the device path for the handle that has\r
175 loaded image protocol installed on it. the FilePath will point to the device path\r
176 for the file that was loaded.\r
177\r
178 @param[in, out] DevPath on a sucessful return the device path to the loaded image\r
179 @param[in, out] FilePath on a sucessful return the device path to the file\r
180\r
181 @retval EFI_SUCCESS the 2 device paths were sucessfully returned.\r
182 @return other a error from gBS->HandleProtocol\r
183\r
184 @sa HandleProtocol\r
185**/\r
186EFI_STATUS\r
187EFIAPI\r
188GetDevicePathsForImageAndFile (\r
189 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevPath,\r
190 IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath\r
191 );\r
192\r
193/**\r
194 Process all Uefi Shell 2.0 command line options.\r
195\r
196 see Uefi Shell 2.0 section 3.2 for full details.\r
197\r
198 the command line should resemble the following:\r
199\r
200 shell.efi [ShellOpt-options] [options] [file-name [file-name-options]]\r
201\r
202 ShellOpt options Options which control the initialization behavior of the shell.\r
203 These options are read from the EFI global variable "ShellOpt"\r
204 and are processed before options or file-name.\r
205\r
206 options Options which control the initialization behavior of the shell.\r
207\r
208 file-name The name of a UEFI shell application or script to be executed\r
209 after initialization is complete. By default, if file-name is\r
210 specified, then -nostartup is implied. Scripts are not supported\r
211 by level 0.\r
212\r
213 file-nameoptions The command-line options that are passed to file-name when it\r
214 is invoked.\r
215\r
216 This will initialize the ShellInitSettings global variable.\r
217\r
218 @retval EFI_SUCCESS the variable is initialized.\r
219**/\r
220EFI_STATUS\r
221EFIAPI\r
222ProcessCommandLine(\r
223 VOID\r
224 );\r
225\r
226/**\r
227 Handles all interaction with the default startup script.\r
228\r
229 this will check that the correct command line parameters were passed, handle the delay, and then start running the script.\r
230\r
231 @param[in] ImagePath The path to the image for shell. The first place to look for the startup script.\r
232 @param[in] FilePath The path to the file for shell. The second place to look for the startup script.\r
233 @param[out] ExitStatus The exit code of the script. Ignored if NULL.\r
234 Invalid when this function returns an error.\r
235\r
236 @retval EFI_SUCCESS The variable is initialized.\r
237**/\r
238EFI_STATUS\r
239EFIAPI\r
240DoStartupScript(\r
241 IN EFI_DEVICE_PATH_PROTOCOL *ImagePath,\r
242 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,\r
243 OUT SHELL_STATUS *ExitStatus\r
244 );\r
245\r
246/**\r
247 Function to perform the shell prompt looping. It will do a single prompt,\r
248 dispatch the result, and then return. It is expected that the caller will\r
249 call this function in a loop many times.\r
250\r
251 @retval EFI_SUCCESS\r
252 @retval RETURN_ABORTED\r
253**/\r
254EFI_STATUS\r
255EFIAPI\r
256DoShellPrompt (\r
257 VOID\r
258 );\r
259\r
260/**\r
261 Add a buffer to the Buffer To Free List for safely returning buffers to other\r
262 places without risking letting them modify internal shell information.\r
263\r
264 @param Buffer Something to pass to FreePool when the shell is exiting.\r
265**/\r
266VOID*\r
267EFIAPI\r
268AddBufferToFreeList(\r
269 VOID *Buffer\r
270 );\r
271\r
272/**\r
273 Add a buffer to the Command History List.\r
274\r
275 @param Buffer[in] The line buffer to add.\r
276**/\r
277VOID\r
278EFIAPI\r
279AddLineToCommandHistory(\r
280 IN CONST CHAR16 *Buffer\r
281 );\r
282\r
283/**\r
284 Function will process and run a command line.\r
285\r
286 This will determine if the command line represents an internal shell command or dispatch an external application.\r
287\r
288 @param[in] CmdLine the command line to parse\r
289 @param[out] ExitStatus The exit status of the command. Ignored if NULL.\r
290\r
291 @retval EFI_SUCCESS the command was completed\r
292 @retval EFI_ABORTED the command's operation was aborted\r
293**/\r
294EFI_STATUS\r
295EFIAPI\r
296RunCommand(\r
297 IN CONST CHAR16 *CmdLine,\r
298 OUT SHELL_STATUS *ExitStatus\r
299 );\r
300\r
301/**\r
302 Function determins if the CommandName COULD be a valid command. It does not determine whether\r
303 this is a valid command. It only checks for invalid characters.\r
304\r
305 @param[in] CommandName The name to check\r
306\r
307 @retval TRUE CommandName could be a command name\r
308 @retval FALSE CommandName could not be a valid command name\r
309**/\r
310BOOLEAN\r
311EFIAPI\r
312IsValidCommandName(\r
313 IN CONST CHAR16 *CommandName\r
314 );\r
315\r
316/**\r
317 Function to process a NSH script file via SHELL_FILE_HANDLE.\r
318\r
319 @param[in] Handle The handle to the already opened file.\r
320 @param[in] Name The name of the script file.\r
321\r
322 @param[out] ExitStatus The exit code of the script. Ignored if NULL.\r
323 Invalid when this function returns an error.\r
324\r
325 @retval EFI_SUCCESS the script completed sucessfully\r
326**/\r
327EFI_STATUS\r
328EFIAPI\r
329RunScriptFileHandle (\r
330 IN SHELL_FILE_HANDLE Handle,\r
331 IN CONST CHAR16 *Name,\r
332 OUT SHELL_STATUS *ExitStatus\r
333 );\r
334\r
335/**\r
336 Function to process a NSH script file.\r
337\r
338 @param[in] ScriptPath Pointer to the script file name (including file system path).\r
339 @param[in] Handle the handle of the script file already opened.\r
340 @param[in] CmdLine the command line to run.\r
341 @param[in] ParamProtocol the shell parameters protocol pointer\r
342\r
343 @param[out] ExitStatus The exit code of the script. Ignored if NULL.\r
344 Invalid when this function returns an error.\r
345\r
346 @retval EFI_SUCCESS the script completed sucessfully\r
347**/\r
348EFI_STATUS\r
349EFIAPI\r
350RunScriptFile (\r
351 IN CONST CHAR16 *ScriptPath,\r
352 IN SHELL_FILE_HANDLE Handle OPTIONAL,\r
353 IN CONST CHAR16 *CmdLine,\r
354 IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol,\r
355 OUT SHELL_STATUS *ExitStatus\r
356 );\r
357\r
358#endif //_SHELL_INTERNAL_HEADER_\r
359\r