]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Application/Shell/ConsoleWrappers.c
MdeModulePkg CapsuleRuntimeDxe: Get PcdMaxSizeNonPopulateCapsule and PcdMaxSizePopula...
[mirror_edk2.git] / ShellPkg / Application / Shell / ConsoleWrappers.c
CommitLineData
8be0ba36 1/** @file\r
2 Function definitions for shell simple text in and out on top of file handles.\r
3\r
dcf9b428 4 Copyright (c) 2013 Hewlett-Packard Development Company, L.P.\r
733f138d 5 Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
8be0ba36 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
8be0ba36 16#include "Shell.h"\r
17\r
18typedef struct {\r
19 EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleTextIn;\r
20 SHELL_FILE_HANDLE FileHandle;\r
21 EFI_HANDLE TheHandle;\r
22} SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL;\r
23\r
24typedef struct {\r
25 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL SimpleTextOut;\r
26 SHELL_FILE_HANDLE FileHandle;\r
27 EFI_HANDLE TheHandle;\r
dcf9b428 28 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *OriginalSimpleTextOut;\r
8be0ba36 29} SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL;\r
30\r
31/**\r
32 Event notification function for EFI_SIMPLE_TEXT_INPUT_PROTOCOL.WaitForKey event\r
33 Signal the event if there is key available\r
34\r
35 @param Event Indicates the event that invoke this function.\r
36 @param Context Indicates the calling context.\r
37\r
38**/\r
39VOID\r
40EFIAPI\r
41ConInWaitForKey (\r
42 IN EFI_EVENT Event,\r
43 IN VOID *Context\r
44 )\r
45{\r
46 UINT64 Position;\r
47 UINT64 Size;\r
48 //\r
49 // Someone is waiting on the keystroke event, if there's\r
50 // a key pending, signal the event\r
51 //\r
52 // Context is the pointer to EFI_SIMPLE_TEXT_INPUT_PROTOCOL\r
53 //\r
54 ShellInfoObject.NewEfiShellProtocol->GetFilePosition(((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)Context)->FileHandle, &Position);\r
55 ShellInfoObject.NewEfiShellProtocol->GetFileSize (((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)Context)->FileHandle, &Size );\r
56 if (Position < Size) {\r
57 gBS->SignalEvent (Event);\r
58 }\r
59}\r
60\r
61/**\r
62 Reset function for the fake simple text input.\r
63\r
64 @param[in] This A pointer to the SimpleTextIn structure.\r
65 @param[in] ExtendedVerification TRUE for extra validation, FALSE otherwise.\r
66\r
67 @retval EFI_SUCCESS The reset was successful.\r
68**/\r
69EFI_STATUS\r
70EFIAPI\r
71FileBasedSimpleTextInReset(\r
72 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,\r
73 IN BOOLEAN ExtendedVerification\r
74 )\r
75{\r
76 return (EFI_SUCCESS);\r
77}\r
78\r
79/**\r
80 ReadKeyStroke function for the fake simple text input.\r
81\r
4ff7e37b
ED
82 @param[in] This A pointer to the SimpleTextIn structure.\r
83 @param[in, out] Key A pointer to the Key structure to fill.\r
8be0ba36 84\r
85 @retval EFI_SUCCESS The read was successful.\r
86**/\r
87EFI_STATUS\r
88EFIAPI\r
89FileBasedSimpleTextInReadKeyStroke(\r
733f138d 90 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,\r
91 IN OUT EFI_INPUT_KEY *Key\r
8be0ba36 92 )\r
93{\r
94 UINTN Size;\r
95 Size = sizeof(CHAR16);\r
96 if (Key == NULL || This == NULL) {\r
97 return (EFI_INVALID_PARAMETER);\r
98 }\r
99 Key->ScanCode = 0;\r
100 return (ShellInfoObject.NewEfiShellProtocol->ReadFile(\r
101 ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->FileHandle,\r
102 &Size,\r
103 &Key->UnicodeChar));\r
104}\r
105\r
106/**\r
107 Function to create a EFI_SIMPLE_TEXT_INPUT_PROTOCOL on top of a \r
108 SHELL_FILE_HANDLE to support redirecting input from a file.\r
109\r
110 @param[in] FileHandleToUse The pointer to the SHELL_FILE_HANDLE to use.\r
111 @param[in] HandleLocation The pointer of a location to copy handle with protocol to.\r
112\r
113 @retval NULL There was insufficient memory available.\r
114 @return A pointer to the allocated protocol structure;\r
115**/\r
116EFI_SIMPLE_TEXT_INPUT_PROTOCOL*\r
117EFIAPI\r
118CreateSimpleTextInOnFile(\r
119 IN SHELL_FILE_HANDLE FileHandleToUse,\r
120 IN EFI_HANDLE *HandleLocation\r
121 )\r
122{\r
123 SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *ProtocolToReturn;\r
124 EFI_STATUS Status;\r
125\r
126 if (HandleLocation == NULL || FileHandleToUse == NULL) {\r
127 return (NULL);\r
128 }\r
129\r
130 ProtocolToReturn = AllocateZeroPool(sizeof(SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL));\r
131 if (ProtocolToReturn == NULL) {\r
132 return (NULL);\r
133 }\r
134 ProtocolToReturn->FileHandle = FileHandleToUse;\r
135 ProtocolToReturn->SimpleTextIn.Reset = FileBasedSimpleTextInReset;\r
136 ProtocolToReturn->SimpleTextIn.ReadKeyStroke = FileBasedSimpleTextInReadKeyStroke;\r
137 \r
138 Status = gBS->CreateEvent (\r
139 EVT_NOTIFY_WAIT,\r
140 TPL_NOTIFY,\r
141 ConInWaitForKey,\r
142 &ProtocolToReturn->SimpleTextIn,\r
143 &ProtocolToReturn->SimpleTextIn.WaitForKey\r
144 );\r
145\r
146 if (EFI_ERROR(Status)) {\r
147 FreePool(ProtocolToReturn);\r
148 return (NULL);\r
149 }\r
150 ///@todo possibly also install SimpleTextInputEx on the handle at this point.\r
151 Status = gBS->InstallProtocolInterface(\r
152 &(ProtocolToReturn->TheHandle), \r
153 &gEfiSimpleTextInProtocolGuid, \r
154 EFI_NATIVE_INTERFACE, \r
155 &(ProtocolToReturn->SimpleTextIn));\r
156 if (!EFI_ERROR(Status)) {\r
157 *HandleLocation = ProtocolToReturn->TheHandle;\r
158 return ((EFI_SIMPLE_TEXT_INPUT_PROTOCOL*)ProtocolToReturn);\r
159 } else {\r
160 FreePool(ProtocolToReturn);\r
161 return (NULL);\r
162 }\r
163}\r
164\r
165/**\r
166 Function to close a EFI_SIMPLE_TEXT_INPUT_PROTOCOL on top of a \r
167 SHELL_FILE_HANDLE to support redirecting input from a file.\r
168\r
169 @param[in] SimpleTextIn The pointer to the SimpleTextIn to close.\r
170\r
171 @retval EFI_SUCCESS The object was closed.\r
172**/\r
173EFI_STATUS\r
174EFIAPI\r
175CloseSimpleTextInOnFile(\r
176 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *SimpleTextIn\r
177 )\r
178{\r
179 EFI_STATUS Status;\r
180 EFI_STATUS Status1;\r
181\r
182 if (SimpleTextIn == NULL) {\r
183 return (EFI_INVALID_PARAMETER);\r
184 }\r
185\r
186 Status = gBS->CloseEvent(((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)SimpleTextIn)->SimpleTextIn.WaitForKey);\r
187\r
188 Status1 = gBS->UninstallProtocolInterface(\r
189 ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL*)SimpleTextIn)->TheHandle, \r
190 &gEfiSimpleTextInProtocolGuid, \r
191 &(((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL*)SimpleTextIn)->SimpleTextIn));\r
192\r
193 FreePool(SimpleTextIn);\r
194 if (!EFI_ERROR(Status)) {\r
195 return (Status1);\r
196 } else {\r
197 return (Status);\r
198 }\r
199}\r
200\r
201/**\r
202 Reset the text output device hardware and optionaly run diagnostics.\r
203\r
204 @param This pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL\r
205 @param ExtendedVerification Indicates that a more extensive test may be performed\r
206\r
207 @retval EFI_SUCCESS The text output device was reset.\r
208**/\r
209EFI_STATUS\r
210EFIAPI\r
211FileBasedSimpleTextOutReset (\r
212 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
213 IN BOOLEAN ExtendedVerification\r
214 )\r
215{\r
216 return (EFI_SUCCESS);\r
217}\r
218\r
219/**\r
220 Verifies that all characters in a Unicode string can be output to the\r
221 target device.\r
222\r
223 @param[in] This Protocol instance pointer.\r
224 @param[in] WString The NULL-terminated Unicode string to be examined.\r
225\r
226 @retval EFI_SUCCESS The device(s) are capable of rendering the output string.\r
227**/\r
228EFI_STATUS\r
229EFIAPI\r
230FileBasedSimpleTextOutTestString (\r
231 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
232 IN CHAR16 *WString\r
233 )\r
234{\r
235 return (EFI_SUCCESS);\r
236}\r
237\r
238/**\r
239 Returns information for an available text mode that the output device(s)\r
240 supports.\r
241\r
242 @param[in] This Protocol instance pointer.\r
243 @param[in] ModeNumber The mode number to return information on.\r
244 @param[out] Columns Upon return, the number of columns in the selected geometry\r
245 @param[out] Rows Upon return, the number of rows in the selected geometry\r
246\r
247 @retval EFI_UNSUPPORTED The mode number was not valid.\r
248**/\r
249EFI_STATUS\r
250EFIAPI\r
251FileBasedSimpleTextOutQueryMode (\r
252 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
253 IN UINTN ModeNumber,\r
254 OUT UINTN *Columns,\r
255 OUT UINTN *Rows\r
256 )\r
257{\r
dcf9b428
CP
258 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *PassThruProtocol = ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)This)->OriginalSimpleTextOut;\r
259 \r
260 // Pass the QueryMode call thru to the original SimpleTextOutProtocol\r
261 return (PassThruProtocol->QueryMode(\r
262 PassThruProtocol,\r
263 ModeNumber,\r
264 Columns,\r
265 Rows));\r
8be0ba36 266}\r
267\r
268/**\r
269 Sets the output device(s) to a specified mode.\r
270\r
271 @param[in] This Protocol instance pointer.\r
272 @param[in] ModeNumber The mode number to set.\r
273\r
274 @retval EFI_UNSUPPORTED The mode number was not valid.\r
275**/\r
276EFI_STATUS\r
277EFIAPI\r
278FileBasedSimpleTextOutSetMode (\r
279 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
280 IN UINTN ModeNumber\r
281 )\r
282{\r
283 return (EFI_UNSUPPORTED);\r
284}\r
285\r
286/**\r
287 Sets the background and foreground colors for the OutputString () and\r
288 ClearScreen () functions.\r
289\r
290 @param[in] This Protocol instance pointer.\r
291 @param[in] Attribute The attribute to set. Bits 0..3 are the foreground color, and\r
292 bits 4..6 are the background color. All other bits are undefined\r
293 and must be zero. The valid Attributes are defined in this file.\r
294\r
295 @retval EFI_SUCCESS The attribute was set.\r
296**/\r
297EFI_STATUS\r
298EFIAPI\r
299FileBasedSimpleTextOutSetAttribute (\r
300 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
301 IN UINTN Attribute\r
302 )\r
303{\r
304 return (EFI_SUCCESS);\r
305}\r
306\r
307/**\r
308 Clears the output device(s) display to the currently selected background\r
309 color.\r
310\r
311 @param[in] This Protocol instance pointer.\r
312\r
313 @retval EFI_UNSUPPORTED The output device is not in a valid text mode.\r
314**/\r
315EFI_STATUS\r
316EFIAPI\r
317FileBasedSimpleTextOutClearScreen (\r
318 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This\r
319 )\r
320{\r
321 return (EFI_SUCCESS);\r
322}\r
323\r
324/**\r
325 Sets the current coordinates of the cursor position\r
326\r
327 @param[in] This Protocol instance pointer.\r
328 @param[in] Column Column to put the cursor in. Must be between zero and Column returned from QueryMode\r
329 @param[in] Row Row to put the cursor in. Must be between zero and Row returned from QueryMode\r
330\r
331 @retval EFI_SUCCESS The operation completed successfully.\r
332**/\r
333EFI_STATUS\r
334EFIAPI\r
335FileBasedSimpleTextOutSetCursorPosition (\r
336 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
337 IN UINTN Column,\r
338 IN UINTN Row\r
339 )\r
340{\r
341 return (EFI_SUCCESS);\r
342}\r
343\r
344/**\r
345 Makes the cursor visible or invisible\r
346\r
347 @param[in] This Protocol instance pointer.\r
348 @param[in] Visible If TRUE, the cursor is set to be visible. If FALSE, the cursor is\r
349 set to be invisible.\r
350\r
351 @retval EFI_SUCCESS The operation completed successfully.\r
352**/\r
353EFI_STATUS\r
354EFIAPI\r
355FileBasedSimpleTextOutEnableCursor (\r
356 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
357 IN BOOLEAN Visible\r
358 )\r
359{\r
360 return (EFI_SUCCESS);\r
361}\r
362\r
363/**\r
364 Write a Unicode string to the output device.\r
365\r
366 @param[in] This Protocol instance pointer.\r
367 @param[in] WString The NULL-terminated Unicode string to be displayed on the output\r
368 device(s). All output devices must also support the Unicode\r
369 drawing defined in this file.\r
370 @retval EFI_SUCCESS The string was output to the device.\r
371 @retval EFI_DEVICE_ERROR The device reported an error while attempting to output\r
372 the text.\r
373 @retval EFI_UNSUPPORTED The output device's mode is not currently in a\r
374 defined text mode.\r
375 @retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the\r
376 characters in the Unicode string could not be\r
377 rendered and were skipped.\r
378**/\r
379EFI_STATUS\r
380EFIAPI\r
381FileBasedSimpleTextOutOutputString (\r
382 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
383 IN CHAR16 *WString\r
384 )\r
385{\r
386 UINTN Size;\r
387 Size = StrLen(WString) * sizeof(CHAR16);\r
388 return (ShellInfoObject.NewEfiShellProtocol->WriteFile(\r
389 ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)This)->FileHandle,\r
390 &Size,\r
391 WString));\r
392}\r
393\r
394/**\r
395 Function to create a EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL on top of a \r
396 SHELL_FILE_HANDLE to support redirecting output from a file.\r
397\r
dcf9b428
CP
398 @param[in] FileHandleToUse The pointer to the SHELL_FILE_HANDLE to use.\r
399 @param[in] HandleLocation The pointer of a location to copy handle with protocol to.\r
400 @param[in] OriginalProtocol The pointer to the original output protocol for pass thru of functions.\r
8be0ba36 401\r
402 @retval NULL There was insufficient memory available.\r
403 @return A pointer to the allocated protocol structure;\r
404**/\r
405EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL*\r
406EFIAPI\r
407CreateSimpleTextOutOnFile(\r
dcf9b428
CP
408 IN SHELL_FILE_HANDLE FileHandleToUse,\r
409 IN EFI_HANDLE *HandleLocation,\r
410 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *OriginalProtocol\r
8be0ba36 411 )\r
412{\r
413 SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ProtocolToReturn;\r
414 EFI_STATUS Status;\r
415\r
416 if (HandleLocation == NULL || FileHandleToUse == NULL) {\r
417 return (NULL);\r
418 }\r
419\r
420 ProtocolToReturn = AllocateZeroPool(sizeof(SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL));\r
421 if (ProtocolToReturn == NULL) {\r
422 return (NULL);\r
423 }\r
424 ProtocolToReturn->FileHandle = FileHandleToUse;\r
dcf9b428 425 ProtocolToReturn->OriginalSimpleTextOut = OriginalProtocol;\r
8be0ba36 426 ProtocolToReturn->SimpleTextOut.Reset = FileBasedSimpleTextOutReset;\r
427 ProtocolToReturn->SimpleTextOut.TestString = FileBasedSimpleTextOutTestString;\r
428 ProtocolToReturn->SimpleTextOut.QueryMode = FileBasedSimpleTextOutQueryMode;\r
429 ProtocolToReturn->SimpleTextOut.SetMode = FileBasedSimpleTextOutSetMode;\r
430 ProtocolToReturn->SimpleTextOut.SetAttribute = FileBasedSimpleTextOutSetAttribute;\r
431 ProtocolToReturn->SimpleTextOut.ClearScreen = FileBasedSimpleTextOutClearScreen;\r
432 ProtocolToReturn->SimpleTextOut.SetCursorPosition = FileBasedSimpleTextOutSetCursorPosition;\r
433 ProtocolToReturn->SimpleTextOut.EnableCursor = FileBasedSimpleTextOutEnableCursor;\r
434 ProtocolToReturn->SimpleTextOut.OutputString = FileBasedSimpleTextOutOutputString;\r
435 ProtocolToReturn->SimpleTextOut.Mode = AllocateZeroPool(sizeof(EFI_SIMPLE_TEXT_OUTPUT_MODE));\r
436 if (ProtocolToReturn->SimpleTextOut.Mode == NULL) {\r
437 FreePool(ProtocolToReturn);\r
438 return (NULL);\r
439 }\r
dcf9b428
CP
440 ProtocolToReturn->SimpleTextOut.Mode->MaxMode = OriginalProtocol->Mode->MaxMode;\r
441 ProtocolToReturn->SimpleTextOut.Mode->Mode = OriginalProtocol->Mode->Mode;\r
442 ProtocolToReturn->SimpleTextOut.Mode->Attribute = OriginalProtocol->Mode->Attribute;\r
443 ProtocolToReturn->SimpleTextOut.Mode->CursorColumn = OriginalProtocol->Mode->CursorColumn;\r
444 ProtocolToReturn->SimpleTextOut.Mode->CursorRow = OriginalProtocol->Mode->CursorRow;\r
445 ProtocolToReturn->SimpleTextOut.Mode->CursorVisible = OriginalProtocol->Mode->CursorVisible;\r
8be0ba36 446\r
447 Status = gBS->InstallProtocolInterface(\r
448 &(ProtocolToReturn->TheHandle), \r
449 &gEfiSimpleTextOutProtocolGuid, \r
450 EFI_NATIVE_INTERFACE, \r
451 &(ProtocolToReturn->SimpleTextOut));\r
452 if (!EFI_ERROR(Status)) {\r
453 *HandleLocation = ProtocolToReturn->TheHandle;\r
454 return ((EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL*)ProtocolToReturn);\r
455 } else {\r
456 FreePool(ProtocolToReturn);\r
457 return (NULL);\r
458 }\r
459}\r
460\r
461/**\r
462 Function to close a EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL on top of a \r
463 SHELL_FILE_HANDLE to support redirecting output from a file.\r
464\r
733f138d 465 @param[in] SimpleTextOut The pointer to the SimpleTextOUT to close.\r
8be0ba36 466\r
467 @retval EFI_SUCCESS The object was closed.\r
468**/\r
469EFI_STATUS\r
470EFIAPI\r
471CloseSimpleTextOutOnFile(\r
733f138d 472 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut\r
8be0ba36 473 )\r
474{\r
475 EFI_STATUS Status;\r
476 if (SimpleTextOut == NULL) {\r
477 return (EFI_INVALID_PARAMETER);\r
478 }\r
479 Status = gBS->UninstallProtocolInterface(\r
480 ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL*)SimpleTextOut)->TheHandle, \r
481 &gEfiSimpleTextOutProtocolGuid, \r
482 &(((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL*)SimpleTextOut)->SimpleTextOut));\r
483 FreePool(SimpleTextOut);\r
484 return (Status);\r
485}\r