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 - 2014, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleTextIn
;
20 SHELL_FILE_HANDLE FileHandle
;
22 UINT64 RemainingBytesOfInputFile
;
23 } SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
;
26 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL SimpleTextOut
;
27 SHELL_FILE_HANDLE FileHandle
;
29 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*OriginalSimpleTextOut
;
30 } SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
;
33 Event notification function for EFI_SIMPLE_TEXT_INPUT_PROTOCOL.WaitForKey event
34 Signal the event if there is key available
36 @param Event Indicates the event that invoke this function.
37 @param Context Indicates the calling context.
47 gBS
->SignalEvent (Event
);
51 Reset function for the fake simple text input.
53 @param[in] This A pointer to the SimpleTextIn structure.
54 @param[in] ExtendedVerification TRUE for extra validation, FALSE otherwise.
56 @retval EFI_SUCCESS The reset was successful.
60 FileBasedSimpleTextInReset(
61 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
62 IN BOOLEAN ExtendedVerification
69 ReadKeyStroke function for the fake simple text input.
71 @param[in] This A pointer to the SimpleTextIn structure.
72 @param[in, out] Key A pointer to the Key structure to fill.
74 @retval EFI_SUCCESS The read was successful.
78 FileBasedSimpleTextInReadKeyStroke(
79 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
80 IN OUT EFI_INPUT_KEY
*Key
86 // Verify the parameters
88 if (Key
== NULL
|| This
== NULL
) {
89 return (EFI_INVALID_PARAMETER
);
93 // Check if we have any characters left in the stream.
95 if (((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)This
)->RemainingBytesOfInputFile
== 0) {
96 return (EFI_NOT_READY
);
99 Size
= sizeof(CHAR16
);
102 // Decrement the amount of free space by Size or set to zero (for odd length files)
104 if (((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)This
)->RemainingBytesOfInputFile
> Size
) {
105 ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)This
)->RemainingBytesOfInputFile
-= Size
;
107 ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)This
)->RemainingBytesOfInputFile
= 0;
111 return (ShellInfoObject
.NewEfiShellProtocol
->ReadFile(
112 ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)This
)->FileHandle
,
118 Function to create a EFI_SIMPLE_TEXT_INPUT_PROTOCOL on top of a
119 SHELL_FILE_HANDLE to support redirecting input from a file.
121 @param[in] FileHandleToUse The pointer to the SHELL_FILE_HANDLE to use.
122 @param[in] HandleLocation The pointer of a location to copy handle with protocol to.
124 @retval NULL There was insufficient memory available.
125 @return A pointer to the allocated protocol structure;
127 EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*
129 CreateSimpleTextInOnFile(
130 IN SHELL_FILE_HANDLE FileHandleToUse
,
131 IN EFI_HANDLE
*HandleLocation
134 SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*ProtocolToReturn
;
136 UINT64 CurrentPosition
;
139 if (HandleLocation
== NULL
|| FileHandleToUse
== NULL
) {
143 ProtocolToReturn
= AllocateZeroPool(sizeof(SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
));
144 if (ProtocolToReturn
== NULL
) {
148 ShellGetFileSize (FileHandleToUse
, &FileSize
);
149 ShellGetFilePosition(FileHandleToUse
, &CurrentPosition
);
152 // Initialize the protocol members
154 ProtocolToReturn
->RemainingBytesOfInputFile
= FileSize
- CurrentPosition
;
155 ProtocolToReturn
->FileHandle
= FileHandleToUse
;
156 ProtocolToReturn
->SimpleTextIn
.Reset
= FileBasedSimpleTextInReset
;
157 ProtocolToReturn
->SimpleTextIn
.ReadKeyStroke
= FileBasedSimpleTextInReadKeyStroke
;
159 Status
= gBS
->CreateEvent (
163 &ProtocolToReturn
->SimpleTextIn
,
164 &ProtocolToReturn
->SimpleTextIn
.WaitForKey
167 if (EFI_ERROR(Status
)) {
168 FreePool(ProtocolToReturn
);
171 ///@todo possibly also install SimpleTextInputEx on the handle at this point.
172 Status
= gBS
->InstallProtocolInterface(
173 &(ProtocolToReturn
->TheHandle
),
174 &gEfiSimpleTextInProtocolGuid
,
175 EFI_NATIVE_INTERFACE
,
176 &(ProtocolToReturn
->SimpleTextIn
));
177 if (!EFI_ERROR(Status
)) {
178 *HandleLocation
= ProtocolToReturn
->TheHandle
;
179 return ((EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)ProtocolToReturn
);
181 FreePool(ProtocolToReturn
);
187 Function to close a EFI_SIMPLE_TEXT_INPUT_PROTOCOL on top of a
188 SHELL_FILE_HANDLE to support redirecting input from a file.
190 @param[in] SimpleTextIn The pointer to the SimpleTextIn to close.
192 @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
*
430 CreateSimpleTextOutOnFile(
431 IN SHELL_FILE_HANDLE FileHandleToUse
,
432 IN EFI_HANDLE
*HandleLocation
,
433 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*OriginalProtocol
436 SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*ProtocolToReturn
;
439 if (HandleLocation
== NULL
|| FileHandleToUse
== NULL
) {
443 ProtocolToReturn
= AllocateZeroPool(sizeof(SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
));
444 if (ProtocolToReturn
== NULL
) {
447 ProtocolToReturn
->FileHandle
= FileHandleToUse
;
448 ProtocolToReturn
->OriginalSimpleTextOut
= OriginalProtocol
;
449 ProtocolToReturn
->SimpleTextOut
.Reset
= FileBasedSimpleTextOutReset
;
450 ProtocolToReturn
->SimpleTextOut
.TestString
= FileBasedSimpleTextOutTestString
;
451 ProtocolToReturn
->SimpleTextOut
.QueryMode
= FileBasedSimpleTextOutQueryMode
;
452 ProtocolToReturn
->SimpleTextOut
.SetMode
= FileBasedSimpleTextOutSetMode
;
453 ProtocolToReturn
->SimpleTextOut
.SetAttribute
= FileBasedSimpleTextOutSetAttribute
;
454 ProtocolToReturn
->SimpleTextOut
.ClearScreen
= FileBasedSimpleTextOutClearScreen
;
455 ProtocolToReturn
->SimpleTextOut
.SetCursorPosition
= FileBasedSimpleTextOutSetCursorPosition
;
456 ProtocolToReturn
->SimpleTextOut
.EnableCursor
= FileBasedSimpleTextOutEnableCursor
;
457 ProtocolToReturn
->SimpleTextOut
.OutputString
= FileBasedSimpleTextOutOutputString
;
458 ProtocolToReturn
->SimpleTextOut
.Mode
= AllocateZeroPool(sizeof(EFI_SIMPLE_TEXT_OUTPUT_MODE
));
459 if (ProtocolToReturn
->SimpleTextOut
.Mode
== NULL
) {
460 FreePool(ProtocolToReturn
);
463 ProtocolToReturn
->SimpleTextOut
.Mode
->MaxMode
= OriginalProtocol
->Mode
->MaxMode
;
464 ProtocolToReturn
->SimpleTextOut
.Mode
->Mode
= OriginalProtocol
->Mode
->Mode
;
465 ProtocolToReturn
->SimpleTextOut
.Mode
->Attribute
= OriginalProtocol
->Mode
->Attribute
;
466 ProtocolToReturn
->SimpleTextOut
.Mode
->CursorColumn
= OriginalProtocol
->Mode
->CursorColumn
;
467 ProtocolToReturn
->SimpleTextOut
.Mode
->CursorRow
= OriginalProtocol
->Mode
->CursorRow
;
468 ProtocolToReturn
->SimpleTextOut
.Mode
->CursorVisible
= OriginalProtocol
->Mode
->CursorVisible
;
470 Status
= gBS
->InstallProtocolInterface(
471 &(ProtocolToReturn
->TheHandle
),
472 &gEfiSimpleTextOutProtocolGuid
,
473 EFI_NATIVE_INTERFACE
,
474 &(ProtocolToReturn
->SimpleTextOut
));
475 if (!EFI_ERROR(Status
)) {
476 *HandleLocation
= ProtocolToReturn
->TheHandle
;
477 return ((EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*)ProtocolToReturn
);
479 FreePool(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.
494 CloseSimpleTextOutOnFile(
495 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
499 if (SimpleTextOut
== NULL
) {
500 return (EFI_INVALID_PARAMETER
);
502 Status
= gBS
->UninstallProtocolInterface(
503 ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*)SimpleTextOut
)->TheHandle
,
504 &gEfiSimpleTextOutProtocolGuid
,
505 &(((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*)SimpleTextOut
)->SimpleTextOut
));
506 FreePool(SimpleTextOut
);