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
);
104 // Decrement the amount of free space by Size or set to zero (for odd length files)
106 if (((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)This
)->RemainingBytesOfInputFile
> CharSize
) {
107 ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)This
)->RemainingBytesOfInputFile
-= CharSize
;
109 ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)This
)->RemainingBytesOfInputFile
= 0;
113 return (ShellInfoObject
.NewEfiShellProtocol
->ReadFile(
114 ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)This
)->FileHandle
,
120 Function to create a EFI_SIMPLE_TEXT_INPUT_PROTOCOL on top of a
121 SHELL_FILE_HANDLE to support redirecting input from a file.
123 @param[in] FileHandleToUse The pointer to the SHELL_FILE_HANDLE to use.
124 @param[in] HandleLocation The pointer of a location to copy handle with protocol to.
126 @retval NULL There was insufficient memory available.
127 @return A pointer to the allocated protocol structure;
129 EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*
130 CreateSimpleTextInOnFile(
131 IN SHELL_FILE_HANDLE FileHandleToUse
,
132 IN EFI_HANDLE
*HandleLocation
135 SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*ProtocolToReturn
;
137 UINT64 CurrentPosition
;
140 if (HandleLocation
== NULL
|| FileHandleToUse
== NULL
) {
144 ProtocolToReturn
= AllocateZeroPool(sizeof(SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
));
145 if (ProtocolToReturn
== NULL
) {
149 ShellGetFileSize (FileHandleToUse
, &FileSize
);
150 ShellGetFilePosition(FileHandleToUse
, &CurrentPosition
);
153 // Initialize the protocol members
155 ProtocolToReturn
->RemainingBytesOfInputFile
= FileSize
- CurrentPosition
;
156 ProtocolToReturn
->FileHandle
= FileHandleToUse
;
157 ProtocolToReturn
->SimpleTextIn
.Reset
= FileBasedSimpleTextInReset
;
158 ProtocolToReturn
->SimpleTextIn
.ReadKeyStroke
= FileBasedSimpleTextInReadKeyStroke
;
160 Status
= gBS
->CreateEvent (
164 &ProtocolToReturn
->SimpleTextIn
,
165 &ProtocolToReturn
->SimpleTextIn
.WaitForKey
168 if (EFI_ERROR(Status
)) {
169 FreePool(ProtocolToReturn
);
172 ///@todo possibly also install SimpleTextInputEx on the handle at this point.
173 Status
= gBS
->InstallProtocolInterface(
174 &(ProtocolToReturn
->TheHandle
),
175 &gEfiSimpleTextInProtocolGuid
,
176 EFI_NATIVE_INTERFACE
,
177 &(ProtocolToReturn
->SimpleTextIn
));
178 if (!EFI_ERROR(Status
)) {
179 *HandleLocation
= ProtocolToReturn
->TheHandle
;
180 return ((EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)ProtocolToReturn
);
182 FreePool(ProtocolToReturn
);
188 Function to close a EFI_SIMPLE_TEXT_INPUT_PROTOCOL on top of a
189 SHELL_FILE_HANDLE to support redirecting input from a file.
191 @param[in] SimpleTextIn The pointer to the SimpleTextIn to close.
193 @retval EFI_SUCCESS The object was closed.
196 CloseSimpleTextInOnFile(
197 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*SimpleTextIn
203 if (SimpleTextIn
== NULL
) {
204 return (EFI_INVALID_PARAMETER
);
207 Status
= gBS
->CloseEvent(((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)SimpleTextIn
)->SimpleTextIn
.WaitForKey
);
209 Status1
= gBS
->UninstallProtocolInterface(
210 ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)SimpleTextIn
)->TheHandle
,
211 &gEfiSimpleTextInProtocolGuid
,
212 &(((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)SimpleTextIn
)->SimpleTextIn
));
214 FreePool(SimpleTextIn
);
215 if (!EFI_ERROR(Status
)) {
223 Reset the text output device hardware and optionaly run diagnostics.
225 @param This pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
226 @param ExtendedVerification Indicates that a more extensive test may be performed
228 @retval EFI_SUCCESS The text output device was reset.
232 FileBasedSimpleTextOutReset (
233 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
234 IN BOOLEAN ExtendedVerification
237 return (EFI_SUCCESS
);
241 Verifies that all characters in a Unicode string can be output to the
244 @param[in] This Protocol instance pointer.
245 @param[in] WString The NULL-terminated Unicode string to be examined.
247 @retval EFI_SUCCESS The device(s) are capable of rendering the output string.
251 FileBasedSimpleTextOutTestString (
252 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
256 return (EFI_SUCCESS
);
260 Returns information for an available text mode that the output device(s)
263 @param[in] This Protocol instance pointer.
264 @param[in] ModeNumber The mode number to return information on.
265 @param[out] Columns Upon return, the number of columns in the selected geometry
266 @param[out] Rows Upon return, the number of rows in the selected geometry
268 @retval EFI_UNSUPPORTED The mode number was not valid.
272 FileBasedSimpleTextOutQueryMode (
273 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
279 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*PassThruProtocol
;
281 PassThruProtocol
= ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*)This
)->OriginalSimpleTextOut
;
283 // Pass the QueryMode call thru to the original SimpleTextOutProtocol
284 return (PassThruProtocol
->QueryMode(
292 Sets the output device(s) to a specified mode.
294 @param[in] This Protocol instance pointer.
295 @param[in] ModeNumber The mode number to set.
297 @retval EFI_UNSUPPORTED The mode number was not valid.
301 FileBasedSimpleTextOutSetMode (
302 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
306 return (EFI_UNSUPPORTED
);
310 Sets the background and foreground colors for the OutputString () and
311 ClearScreen () functions.
313 @param[in] This Protocol instance pointer.
314 @param[in] Attribute The attribute to set. Bits 0..3 are the foreground color, and
315 bits 4..6 are the background color. All other bits are undefined
316 and must be zero. The valid Attributes are defined in this file.
318 @retval EFI_SUCCESS The attribute was set.
322 FileBasedSimpleTextOutSetAttribute (
323 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
327 return (EFI_SUCCESS
);
331 Clears the output device(s) display to the currently selected background
334 @param[in] This Protocol instance pointer.
336 @retval EFI_UNSUPPORTED The output device is not in a valid text mode.
340 FileBasedSimpleTextOutClearScreen (
341 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
344 return (EFI_SUCCESS
);
348 Sets the current coordinates of the cursor position
350 @param[in] This Protocol instance pointer.
351 @param[in] Column Column to put the cursor in. Must be between zero and Column returned from QueryMode
352 @param[in] Row Row to put the cursor in. Must be between zero and Row returned from QueryMode
354 @retval EFI_SUCCESS The operation completed successfully.
358 FileBasedSimpleTextOutSetCursorPosition (
359 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
364 return (EFI_SUCCESS
);
368 Makes the cursor visible or invisible
370 @param[in] This Protocol instance pointer.
371 @param[in] Visible If TRUE, the cursor is set to be visible. If FALSE, the cursor is
374 @retval EFI_SUCCESS The operation completed successfully.
378 FileBasedSimpleTextOutEnableCursor (
379 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
383 return (EFI_SUCCESS
);
387 Write a Unicode string to the output device.
389 @param[in] This Protocol instance pointer.
390 @param[in] WString The NULL-terminated Unicode string to be displayed on the output
391 device(s). All output devices must also support the Unicode
392 drawing defined in this file.
393 @retval EFI_SUCCESS The string was output to the device.
394 @retval EFI_DEVICE_ERROR The device reported an error while attempting to output
396 @retval EFI_UNSUPPORTED The output device's mode is not currently in a
398 @retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the
399 characters in the Unicode string could not be
400 rendered and were skipped.
404 FileBasedSimpleTextOutOutputString (
405 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
410 Size
= StrLen(WString
) * sizeof(CHAR16
);
411 return (ShellInfoObject
.NewEfiShellProtocol
->WriteFile(
412 ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*)This
)->FileHandle
,
418 Function to create a EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL on top of a
419 SHELL_FILE_HANDLE to support redirecting output from a file.
421 @param[in] FileHandleToUse The pointer to the SHELL_FILE_HANDLE to use.
422 @param[in] HandleLocation The pointer of a location to copy handle with protocol to.
423 @param[in] OriginalProtocol The pointer to the original output protocol for pass thru of functions.
425 @retval NULL There was insufficient memory available.
426 @return A pointer to the allocated protocol structure;
428 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*
429 CreateSimpleTextOutOnFile(
430 IN SHELL_FILE_HANDLE FileHandleToUse
,
431 IN EFI_HANDLE
*HandleLocation
,
432 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*OriginalProtocol
435 SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*ProtocolToReturn
;
438 if (HandleLocation
== NULL
|| FileHandleToUse
== NULL
) {
442 ProtocolToReturn
= AllocateZeroPool(sizeof(SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
));
443 if (ProtocolToReturn
== NULL
) {
446 ProtocolToReturn
->FileHandle
= FileHandleToUse
;
447 ProtocolToReturn
->OriginalSimpleTextOut
= OriginalProtocol
;
448 ProtocolToReturn
->SimpleTextOut
.Reset
= FileBasedSimpleTextOutReset
;
449 ProtocolToReturn
->SimpleTextOut
.TestString
= FileBasedSimpleTextOutTestString
;
450 ProtocolToReturn
->SimpleTextOut
.QueryMode
= FileBasedSimpleTextOutQueryMode
;
451 ProtocolToReturn
->SimpleTextOut
.SetMode
= FileBasedSimpleTextOutSetMode
;
452 ProtocolToReturn
->SimpleTextOut
.SetAttribute
= FileBasedSimpleTextOutSetAttribute
;
453 ProtocolToReturn
->SimpleTextOut
.ClearScreen
= FileBasedSimpleTextOutClearScreen
;
454 ProtocolToReturn
->SimpleTextOut
.SetCursorPosition
= FileBasedSimpleTextOutSetCursorPosition
;
455 ProtocolToReturn
->SimpleTextOut
.EnableCursor
= FileBasedSimpleTextOutEnableCursor
;
456 ProtocolToReturn
->SimpleTextOut
.OutputString
= FileBasedSimpleTextOutOutputString
;
457 ProtocolToReturn
->SimpleTextOut
.Mode
= AllocateZeroPool(sizeof(EFI_SIMPLE_TEXT_OUTPUT_MODE
));
458 if (ProtocolToReturn
->SimpleTextOut
.Mode
== NULL
) {
459 FreePool(ProtocolToReturn
);
462 ProtocolToReturn
->SimpleTextOut
.Mode
->MaxMode
= OriginalProtocol
->Mode
->MaxMode
;
463 ProtocolToReturn
->SimpleTextOut
.Mode
->Mode
= OriginalProtocol
->Mode
->Mode
;
464 ProtocolToReturn
->SimpleTextOut
.Mode
->Attribute
= OriginalProtocol
->Mode
->Attribute
;
465 ProtocolToReturn
->SimpleTextOut
.Mode
->CursorColumn
= OriginalProtocol
->Mode
->CursorColumn
;
466 ProtocolToReturn
->SimpleTextOut
.Mode
->CursorRow
= OriginalProtocol
->Mode
->CursorRow
;
467 ProtocolToReturn
->SimpleTextOut
.Mode
->CursorVisible
= OriginalProtocol
->Mode
->CursorVisible
;
469 Status
= gBS
->InstallProtocolInterface(
470 &(ProtocolToReturn
->TheHandle
),
471 &gEfiSimpleTextOutProtocolGuid
,
472 EFI_NATIVE_INTERFACE
,
473 &(ProtocolToReturn
->SimpleTextOut
));
474 if (!EFI_ERROR(Status
)) {
475 *HandleLocation
= ProtocolToReturn
->TheHandle
;
476 return ((EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*)ProtocolToReturn
);
478 SHELL_FREE_NON_NULL(ProtocolToReturn
->SimpleTextOut
.Mode
);
479 SHELL_FREE_NON_NULL(ProtocolToReturn
);
485 Function to close a EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL on top of a
486 SHELL_FILE_HANDLE to support redirecting output from a file.
488 @param[in] SimpleTextOut The pointer to the SimpleTextOUT to close.
490 @retval EFI_SUCCESS The object was closed.
493 CloseSimpleTextOutOnFile(
494 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
498 if (SimpleTextOut
== NULL
) {
499 return (EFI_INVALID_PARAMETER
);
501 Status
= gBS
->UninstallProtocolInterface(
502 ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*)SimpleTextOut
)->TheHandle
,
503 &gEfiSimpleTextOutProtocolGuid
,
504 &(((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*)SimpleTextOut
)->SimpleTextOut
));
505 FreePool(SimpleTextOut
->Mode
);
506 FreePool(SimpleTextOut
);