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