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