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