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