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