2 Function definitions for shell simple text in and out on top of file handles.
4 (C) Copyright 2013 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
12 extern BOOLEAN AsciiRedirection
;
15 EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleTextIn
;
16 SHELL_FILE_HANDLE FileHandle
;
18 UINT64 RemainingBytesOfInputFile
;
19 } SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
;
22 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL SimpleTextOut
;
23 SHELL_FILE_HANDLE FileHandle
;
25 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*OriginalSimpleTextOut
;
26 } SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
;
29 Event notification function for EFI_SIMPLE_TEXT_INPUT_PROTOCOL.WaitForKey event
30 Signal the event if there is key available
32 @param Event Indicates the event that invoke this function.
33 @param Context Indicates the calling context.
43 gBS
->SignalEvent (Event
);
47 Reset function for the fake simple text input.
49 @param[in] This A pointer to the SimpleTextIn structure.
50 @param[in] ExtendedVerification TRUE for extra validation, FALSE otherwise.
52 @retval EFI_SUCCESS The reset was successful.
56 FileBasedSimpleTextInReset (
57 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
58 IN BOOLEAN ExtendedVerification
65 ReadKeyStroke function for the fake simple text input.
67 @param[in] This A pointer to the SimpleTextIn structure.
68 @param[in, out] Key A pointer to the Key structure to fill.
70 @retval EFI_SUCCESS The read was successful.
74 FileBasedSimpleTextInReadKeyStroke (
75 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
76 IN OUT EFI_INPUT_KEY
*Key
83 // Verify the parameters
85 if ((Key
== NULL
) || (This
== NULL
)) {
86 return (EFI_INVALID_PARAMETER
);
90 // Check if we have any characters left in the stream.
92 if (((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)This
)->RemainingBytesOfInputFile
== 0) {
93 return (EFI_NOT_READY
);
96 Size
= sizeof (CHAR16
);
98 if (!AsciiRedirection
) {
99 CharSize
= sizeof (CHAR16
);
101 CharSize
= sizeof (CHAR8
);
105 // Decrement the amount of free space by Size or set to zero (for odd length files)
107 if (((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)This
)->RemainingBytesOfInputFile
> CharSize
) {
108 ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)This
)->RemainingBytesOfInputFile
-= CharSize
;
110 ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)This
)->RemainingBytesOfInputFile
= 0;
114 return (ShellInfoObject
.NewEfiShellProtocol
->ReadFile (
115 ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)This
)->FileHandle
,
122 Function to create a EFI_SIMPLE_TEXT_INPUT_PROTOCOL on top of a
123 SHELL_FILE_HANDLE to support redirecting input from a file.
125 @param[in] FileHandleToUse The pointer to the SHELL_FILE_HANDLE to use.
126 @param[in] HandleLocation The pointer of a location to copy handle with protocol to.
128 @retval NULL There was insufficient memory available.
129 @return A pointer to the allocated protocol structure;
131 EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*
132 CreateSimpleTextInOnFile (
133 IN SHELL_FILE_HANDLE FileHandleToUse
,
134 IN EFI_HANDLE
*HandleLocation
137 SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*ProtocolToReturn
;
139 UINT64 CurrentPosition
;
142 if ((HandleLocation
== NULL
) || (FileHandleToUse
== NULL
)) {
146 ProtocolToReturn
= AllocateZeroPool (sizeof (SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
));
147 if (ProtocolToReturn
== NULL
) {
151 ShellGetFileSize (FileHandleToUse
, &FileSize
);
152 ShellGetFilePosition (FileHandleToUse
, &CurrentPosition
);
155 // Initialize the protocol members
157 ProtocolToReturn
->RemainingBytesOfInputFile
= FileSize
- CurrentPosition
;
158 ProtocolToReturn
->FileHandle
= FileHandleToUse
;
159 ProtocolToReturn
->SimpleTextIn
.Reset
= FileBasedSimpleTextInReset
;
160 ProtocolToReturn
->SimpleTextIn
.ReadKeyStroke
= FileBasedSimpleTextInReadKeyStroke
;
162 Status
= gBS
->CreateEvent (
166 &ProtocolToReturn
->SimpleTextIn
,
167 &ProtocolToReturn
->SimpleTextIn
.WaitForKey
170 if (EFI_ERROR (Status
)) {
171 FreePool (ProtocolToReturn
);
175 /// @todo possibly also install SimpleTextInputEx on the handle at this point.
176 Status
= gBS
->InstallProtocolInterface (
177 &(ProtocolToReturn
->TheHandle
),
178 &gEfiSimpleTextInProtocolGuid
,
179 EFI_NATIVE_INTERFACE
,
180 &(ProtocolToReturn
->SimpleTextIn
)
182 if (!EFI_ERROR (Status
)) {
183 *HandleLocation
= ProtocolToReturn
->TheHandle
;
184 return ((EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)ProtocolToReturn
);
186 FreePool (ProtocolToReturn
);
192 Function to close a EFI_SIMPLE_TEXT_INPUT_PROTOCOL on top of a
193 SHELL_FILE_HANDLE to support redirecting input from a file.
195 @param[in] SimpleTextIn The pointer to the SimpleTextIn to close.
197 @retval EFI_SUCCESS The object was closed.
200 CloseSimpleTextInOnFile (
201 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*SimpleTextIn
207 if (SimpleTextIn
== NULL
) {
208 return (EFI_INVALID_PARAMETER
);
211 Status
= gBS
->CloseEvent (((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)SimpleTextIn
)->SimpleTextIn
.WaitForKey
);
213 Status1
= gBS
->UninstallProtocolInterface (
214 ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)SimpleTextIn
)->TheHandle
,
215 &gEfiSimpleTextInProtocolGuid
,
216 &(((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)SimpleTextIn
)->SimpleTextIn
)
219 FreePool (SimpleTextIn
);
220 if (!EFI_ERROR (Status
)) {
228 Reset the text output device hardware and optionally run diagnostics.
230 @param This pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
231 @param ExtendedVerification Indicates that a more extensive test may be performed
233 @retval EFI_SUCCESS The text output device was reset.
237 FileBasedSimpleTextOutReset (
238 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
239 IN BOOLEAN ExtendedVerification
242 return (EFI_SUCCESS
);
246 Verifies that all characters in a Unicode string can be output to the
249 @param[in] This Protocol instance pointer.
250 @param[in] WString The NULL-terminated Unicode string to be examined.
252 @retval EFI_SUCCESS The device(s) are capable of rendering the output string.
256 FileBasedSimpleTextOutTestString (
257 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
261 return (EFI_SUCCESS
);
265 Returns information for an available text mode that the output device(s)
268 @param[in] This Protocol instance pointer.
269 @param[in] ModeNumber The mode number to return information on.
270 @param[out] Columns Upon return, the number of columns in the selected geometry
271 @param[out] Rows Upon return, the number of rows in the selected geometry
273 @retval EFI_UNSUPPORTED The mode number was not valid.
277 FileBasedSimpleTextOutQueryMode (
278 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
284 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*PassThruProtocol
;
286 PassThruProtocol
= ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*)This
)->OriginalSimpleTextOut
;
288 // Pass the QueryMode call thru to the original SimpleTextOutProtocol
289 return (PassThruProtocol
->QueryMode (
298 Sets the output device(s) to a specified mode.
300 @param[in] This Protocol instance pointer.
301 @param[in] ModeNumber The mode number to set.
303 @retval EFI_UNSUPPORTED The mode number was not valid.
307 FileBasedSimpleTextOutSetMode (
308 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
312 return (EFI_UNSUPPORTED
);
316 Sets the background and foreground colors for the OutputString () and
317 ClearScreen () functions.
319 @param[in] This Protocol instance pointer.
320 @param[in] Attribute The attribute to set. Bits 0..3 are the foreground color, and
321 bits 4..6 are the background color. All other bits are undefined
322 and must be zero. The valid Attributes are defined in this file.
324 @retval EFI_SUCCESS The attribute was set.
328 FileBasedSimpleTextOutSetAttribute (
329 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
333 return (EFI_SUCCESS
);
337 Clears the output device(s) display to the currently selected background
340 @param[in] This Protocol instance pointer.
342 @retval EFI_UNSUPPORTED The output device is not in a valid text mode.
346 FileBasedSimpleTextOutClearScreen (
347 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
350 return (EFI_SUCCESS
);
354 Sets the current coordinates of the cursor position
356 @param[in] This Protocol instance pointer.
357 @param[in] Column Column to put the cursor in. Must be between zero and Column returned from QueryMode
358 @param[in] Row Row to put the cursor in. Must be between zero and Row returned from QueryMode
360 @retval EFI_SUCCESS The operation completed successfully.
364 FileBasedSimpleTextOutSetCursorPosition (
365 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
370 return (EFI_SUCCESS
);
374 Makes the cursor visible or invisible
376 @param[in] This Protocol instance pointer.
377 @param[in] Visible If TRUE, the cursor is set to be visible. If FALSE, the cursor is
380 @retval EFI_SUCCESS The operation completed successfully.
384 FileBasedSimpleTextOutEnableCursor (
385 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
389 return (EFI_SUCCESS
);
393 Write a Unicode string to the output device.
395 @param[in] This Protocol instance pointer.
396 @param[in] WString The NULL-terminated Unicode string to be displayed on the output
397 device(s). All output devices must also support the Unicode
398 drawing defined in this file.
399 @retval EFI_SUCCESS The string was output to the device.
400 @retval EFI_DEVICE_ERROR The device reported an error while attempting to output
402 @retval EFI_UNSUPPORTED The output device's mode is not currently in a
404 @retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the
405 characters in the Unicode string could not be
406 rendered and were skipped.
410 FileBasedSimpleTextOutOutputString (
411 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
417 Size
= StrLen (WString
) * sizeof (CHAR16
);
418 return (ShellInfoObject
.NewEfiShellProtocol
->WriteFile (
419 ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*)This
)->FileHandle
,
426 Function to create a EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL on top of a
427 SHELL_FILE_HANDLE to support redirecting output from a file.
429 @param[in] FileHandleToUse The pointer to the SHELL_FILE_HANDLE to use.
430 @param[in] HandleLocation The pointer of a location to copy handle with protocol to.
431 @param[in] OriginalProtocol The pointer to the original output protocol for pass thru of functions.
433 @retval NULL There was insufficient memory available.
434 @return A pointer to the allocated protocol structure;
436 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*
437 CreateSimpleTextOutOnFile (
438 IN SHELL_FILE_HANDLE FileHandleToUse
,
439 IN EFI_HANDLE
*HandleLocation
,
440 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*OriginalProtocol
443 SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*ProtocolToReturn
;
446 if ((HandleLocation
== NULL
) || (FileHandleToUse
== NULL
)) {
450 ProtocolToReturn
= AllocateZeroPool (sizeof (SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
));
451 if (ProtocolToReturn
== NULL
) {
455 ProtocolToReturn
->FileHandle
= FileHandleToUse
;
456 ProtocolToReturn
->OriginalSimpleTextOut
= OriginalProtocol
;
457 ProtocolToReturn
->SimpleTextOut
.Reset
= FileBasedSimpleTextOutReset
;
458 ProtocolToReturn
->SimpleTextOut
.TestString
= FileBasedSimpleTextOutTestString
;
459 ProtocolToReturn
->SimpleTextOut
.QueryMode
= FileBasedSimpleTextOutQueryMode
;
460 ProtocolToReturn
->SimpleTextOut
.SetMode
= FileBasedSimpleTextOutSetMode
;
461 ProtocolToReturn
->SimpleTextOut
.SetAttribute
= FileBasedSimpleTextOutSetAttribute
;
462 ProtocolToReturn
->SimpleTextOut
.ClearScreen
= FileBasedSimpleTextOutClearScreen
;
463 ProtocolToReturn
->SimpleTextOut
.SetCursorPosition
= FileBasedSimpleTextOutSetCursorPosition
;
464 ProtocolToReturn
->SimpleTextOut
.EnableCursor
= FileBasedSimpleTextOutEnableCursor
;
465 ProtocolToReturn
->SimpleTextOut
.OutputString
= FileBasedSimpleTextOutOutputString
;
466 ProtocolToReturn
->SimpleTextOut
.Mode
= AllocateZeroPool (sizeof (EFI_SIMPLE_TEXT_OUTPUT_MODE
));
467 if (ProtocolToReturn
->SimpleTextOut
.Mode
== NULL
) {
468 FreePool (ProtocolToReturn
);
472 ProtocolToReturn
->SimpleTextOut
.Mode
->MaxMode
= OriginalProtocol
->Mode
->MaxMode
;
473 ProtocolToReturn
->SimpleTextOut
.Mode
->Mode
= OriginalProtocol
->Mode
->Mode
;
474 ProtocolToReturn
->SimpleTextOut
.Mode
->Attribute
= OriginalProtocol
->Mode
->Attribute
;
475 ProtocolToReturn
->SimpleTextOut
.Mode
->CursorColumn
= OriginalProtocol
->Mode
->CursorColumn
;
476 ProtocolToReturn
->SimpleTextOut
.Mode
->CursorRow
= OriginalProtocol
->Mode
->CursorRow
;
477 ProtocolToReturn
->SimpleTextOut
.Mode
->CursorVisible
= OriginalProtocol
->Mode
->CursorVisible
;
479 Status
= gBS
->InstallProtocolInterface (
480 &(ProtocolToReturn
->TheHandle
),
481 &gEfiSimpleTextOutProtocolGuid
,
482 EFI_NATIVE_INTERFACE
,
483 &(ProtocolToReturn
->SimpleTextOut
)
485 if (!EFI_ERROR (Status
)) {
486 *HandleLocation
= ProtocolToReturn
->TheHandle
;
487 return ((EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*)ProtocolToReturn
);
489 SHELL_FREE_NON_NULL (ProtocolToReturn
->SimpleTextOut
.Mode
);
490 SHELL_FREE_NON_NULL (ProtocolToReturn
);
496 Function to close a EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL on top of a
497 SHELL_FILE_HANDLE to support redirecting output from a file.
499 @param[in] SimpleTextOut The pointer to the SimpleTextOUT to close.
501 @retval EFI_SUCCESS The object was closed.
504 CloseSimpleTextOutOnFile (
505 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
510 if (SimpleTextOut
== NULL
) {
511 return (EFI_INVALID_PARAMETER
);
514 Status
= gBS
->UninstallProtocolInterface (
515 ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*)SimpleTextOut
)->TheHandle
,
516 &gEfiSimpleTextOutProtocolGuid
,
517 &(((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*)SimpleTextOut
)->SimpleTextOut
)
519 FreePool (SimpleTextOut
->Mode
);
520 FreePool (SimpleTextOut
);