]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Application/Shell/ConsoleWrappers.c
Add a new line to initialize the variable “PassThruProtocol” in ConsoleWrapers.c...
[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
6f05676d
SQ
258 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *PassThruProtocol;\r
259 \r
260 PassThruProtocol = ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)This)->OriginalSimpleTextOut;\r
dcf9b428
CP
261 \r
262 // Pass the QueryMode call thru to the original SimpleTextOutProtocol\r
263 return (PassThruProtocol->QueryMode(\r
264 PassThruProtocol,\r
265 ModeNumber,\r
266 Columns,\r
267 Rows));\r
8be0ba36 268}\r
269\r
270/**\r
271 Sets the output device(s) to a specified mode.\r
272\r
273 @param[in] This Protocol instance pointer.\r
274 @param[in] ModeNumber The mode number to set.\r
275\r
276 @retval EFI_UNSUPPORTED The mode number was not valid.\r
277**/\r
278EFI_STATUS\r
279EFIAPI\r
280FileBasedSimpleTextOutSetMode (\r
281 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
282 IN UINTN ModeNumber\r
283 )\r
284{\r
285 return (EFI_UNSUPPORTED);\r
286}\r
287\r
288/**\r
289 Sets the background and foreground colors for the OutputString () and\r
290 ClearScreen () functions.\r
291\r
292 @param[in] This Protocol instance pointer.\r
293 @param[in] Attribute The attribute to set. Bits 0..3 are the foreground color, and\r
294 bits 4..6 are the background color. All other bits are undefined\r
295 and must be zero. The valid Attributes are defined in this file.\r
296\r
297 @retval EFI_SUCCESS The attribute was set.\r
298**/\r
299EFI_STATUS\r
300EFIAPI\r
301FileBasedSimpleTextOutSetAttribute (\r
302 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
303 IN UINTN Attribute\r
304 )\r
305{\r
306 return (EFI_SUCCESS);\r
307}\r
308\r
309/**\r
310 Clears the output device(s) display to the currently selected background\r
311 color.\r
312\r
313 @param[in] This Protocol instance pointer.\r
314\r
315 @retval EFI_UNSUPPORTED The output device is not in a valid text mode.\r
316**/\r
317EFI_STATUS\r
318EFIAPI\r
319FileBasedSimpleTextOutClearScreen (\r
320 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This\r
321 )\r
322{\r
323 return (EFI_SUCCESS);\r
324}\r
325\r
326/**\r
327 Sets the current coordinates of the cursor position\r
328\r
329 @param[in] This Protocol instance pointer.\r
330 @param[in] Column Column to put the cursor in. Must be between zero and Column returned from QueryMode\r
331 @param[in] Row Row to put the cursor in. Must be between zero and Row returned from QueryMode\r
332\r
333 @retval EFI_SUCCESS The operation completed successfully.\r
334**/\r
335EFI_STATUS\r
336EFIAPI\r
337FileBasedSimpleTextOutSetCursorPosition (\r
338 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
339 IN UINTN Column,\r
340 IN UINTN Row\r
341 )\r
342{\r
343 return (EFI_SUCCESS);\r
344}\r
345\r
346/**\r
347 Makes the cursor visible or invisible\r
348\r
349 @param[in] This Protocol instance pointer.\r
350 @param[in] Visible If TRUE, the cursor is set to be visible. If FALSE, the cursor is\r
351 set to be invisible.\r
352\r
353 @retval EFI_SUCCESS The operation completed successfully.\r
354**/\r
355EFI_STATUS\r
356EFIAPI\r
357FileBasedSimpleTextOutEnableCursor (\r
358 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
359 IN BOOLEAN Visible\r
360 )\r
361{\r
362 return (EFI_SUCCESS);\r
363}\r
364\r
365/**\r
366 Write a Unicode string to the output device.\r
367\r
368 @param[in] This Protocol instance pointer.\r
369 @param[in] WString The NULL-terminated Unicode string to be displayed on the output\r
370 device(s). All output devices must also support the Unicode\r
371 drawing defined in this file.\r
372 @retval EFI_SUCCESS The string was output to the device.\r
373 @retval EFI_DEVICE_ERROR The device reported an error while attempting to output\r
374 the text.\r
375 @retval EFI_UNSUPPORTED The output device's mode is not currently in a\r
376 defined text mode.\r
377 @retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the\r
378 characters in the Unicode string could not be\r
379 rendered and were skipped.\r
380**/\r
381EFI_STATUS\r
382EFIAPI\r
383FileBasedSimpleTextOutOutputString (\r
384 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
385 IN CHAR16 *WString\r
386 )\r
387{\r
388 UINTN Size;\r
389 Size = StrLen(WString) * sizeof(CHAR16);\r
390 return (ShellInfoObject.NewEfiShellProtocol->WriteFile(\r
391 ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)This)->FileHandle,\r
392 &Size,\r
393 WString));\r
394}\r
395\r
396/**\r
397 Function to create a EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL on top of a \r
398 SHELL_FILE_HANDLE to support redirecting output from a file.\r
399\r
dcf9b428
CP
400 @param[in] FileHandleToUse The pointer to the SHELL_FILE_HANDLE to use.\r
401 @param[in] HandleLocation The pointer of a location to copy handle with protocol to.\r
402 @param[in] OriginalProtocol The pointer to the original output protocol for pass thru of functions.\r
8be0ba36 403\r
404 @retval NULL There was insufficient memory available.\r
405 @return A pointer to the allocated protocol structure;\r
406**/\r
407EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL*\r
408EFIAPI\r
409CreateSimpleTextOutOnFile(\r
dcf9b428
CP
410 IN SHELL_FILE_HANDLE FileHandleToUse,\r
411 IN EFI_HANDLE *HandleLocation,\r
412 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *OriginalProtocol\r
8be0ba36 413 )\r
414{\r
415 SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ProtocolToReturn;\r
416 EFI_STATUS Status;\r
417\r
418 if (HandleLocation == NULL || FileHandleToUse == NULL) {\r
419 return (NULL);\r
420 }\r
421\r
422 ProtocolToReturn = AllocateZeroPool(sizeof(SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL));\r
423 if (ProtocolToReturn == NULL) {\r
424 return (NULL);\r
425 }\r
426 ProtocolToReturn->FileHandle = FileHandleToUse;\r
dcf9b428 427 ProtocolToReturn->OriginalSimpleTextOut = OriginalProtocol;\r
8be0ba36 428 ProtocolToReturn->SimpleTextOut.Reset = FileBasedSimpleTextOutReset;\r
429 ProtocolToReturn->SimpleTextOut.TestString = FileBasedSimpleTextOutTestString;\r
430 ProtocolToReturn->SimpleTextOut.QueryMode = FileBasedSimpleTextOutQueryMode;\r
431 ProtocolToReturn->SimpleTextOut.SetMode = FileBasedSimpleTextOutSetMode;\r
432 ProtocolToReturn->SimpleTextOut.SetAttribute = FileBasedSimpleTextOutSetAttribute;\r
433 ProtocolToReturn->SimpleTextOut.ClearScreen = FileBasedSimpleTextOutClearScreen;\r
434 ProtocolToReturn->SimpleTextOut.SetCursorPosition = FileBasedSimpleTextOutSetCursorPosition;\r
435 ProtocolToReturn->SimpleTextOut.EnableCursor = FileBasedSimpleTextOutEnableCursor;\r
436 ProtocolToReturn->SimpleTextOut.OutputString = FileBasedSimpleTextOutOutputString;\r
437 ProtocolToReturn->SimpleTextOut.Mode = AllocateZeroPool(sizeof(EFI_SIMPLE_TEXT_OUTPUT_MODE));\r
438 if (ProtocolToReturn->SimpleTextOut.Mode == NULL) {\r
439 FreePool(ProtocolToReturn);\r
440 return (NULL);\r
441 }\r
dcf9b428
CP
442 ProtocolToReturn->SimpleTextOut.Mode->MaxMode = OriginalProtocol->Mode->MaxMode;\r
443 ProtocolToReturn->SimpleTextOut.Mode->Mode = OriginalProtocol->Mode->Mode;\r
444 ProtocolToReturn->SimpleTextOut.Mode->Attribute = OriginalProtocol->Mode->Attribute;\r
445 ProtocolToReturn->SimpleTextOut.Mode->CursorColumn = OriginalProtocol->Mode->CursorColumn;\r
446 ProtocolToReturn->SimpleTextOut.Mode->CursorRow = OriginalProtocol->Mode->CursorRow;\r
447 ProtocolToReturn->SimpleTextOut.Mode->CursorVisible = OriginalProtocol->Mode->CursorVisible;\r
8be0ba36 448\r
449 Status = gBS->InstallProtocolInterface(\r
450 &(ProtocolToReturn->TheHandle), \r
451 &gEfiSimpleTextOutProtocolGuid, \r
452 EFI_NATIVE_INTERFACE, \r
453 &(ProtocolToReturn->SimpleTextOut));\r
454 if (!EFI_ERROR(Status)) {\r
455 *HandleLocation = ProtocolToReturn->TheHandle;\r
456 return ((EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL*)ProtocolToReturn);\r
457 } else {\r
458 FreePool(ProtocolToReturn);\r
459 return (NULL);\r
460 }\r
461}\r
462\r
463/**\r
464 Function to close a EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL on top of a \r
465 SHELL_FILE_HANDLE to support redirecting output from a file.\r
466\r
733f138d 467 @param[in] SimpleTextOut The pointer to the SimpleTextOUT to close.\r
8be0ba36 468\r
469 @retval EFI_SUCCESS The object was closed.\r
470**/\r
471EFI_STATUS\r
472EFIAPI\r
473CloseSimpleTextOutOnFile(\r
733f138d 474 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut\r
8be0ba36 475 )\r
476{\r
477 EFI_STATUS Status;\r
478 if (SimpleTextOut == NULL) {\r
479 return (EFI_INVALID_PARAMETER);\r
480 }\r
481 Status = gBS->UninstallProtocolInterface(\r
482 ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL*)SimpleTextOut)->TheHandle, \r
483 &gEfiSimpleTextOutProtocolGuid, \r
484 &(((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL*)SimpleTextOut)->SimpleTextOut));\r
485 FreePool(SimpleTextOut);\r
486 return (Status);\r
487}\r