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 - 2015, 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.
18 extern BOOLEAN AsciiRedirection
;
21 EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleTextIn
;
22 SHELL_FILE_HANDLE FileHandle
;
24 UINT64 RemainingBytesOfInputFile
;
25 } SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
;
28 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL SimpleTextOut
;
29 SHELL_FILE_HANDLE FileHandle
;
31 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*OriginalSimpleTextOut
;
32 } SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
;
35 Event notification function for EFI_SIMPLE_TEXT_INPUT_PROTOCOL.WaitForKey event
36 Signal the event if there is key available
38 @param Event Indicates the event that invoke this function.
39 @param Context Indicates the calling context.
49 gBS
->SignalEvent (Event
);
53 Reset function for the fake simple text input.
55 @param[in] This A pointer to the SimpleTextIn structure.
56 @param[in] ExtendedVerification TRUE for extra validation, FALSE otherwise.
58 @retval EFI_SUCCESS The reset was successful.
62 FileBasedSimpleTextInReset(
63 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
64 IN BOOLEAN ExtendedVerification
71 ReadKeyStroke function for the fake simple text input.
73 @param[in] This A pointer to the SimpleTextIn structure.
74 @param[in, out] Key A pointer to the Key structure to fill.
76 @retval EFI_SUCCESS The read was successful.
80 FileBasedSimpleTextInReadKeyStroke(
81 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
82 IN OUT EFI_INPUT_KEY
*Key
89 // Verify the parameters
91 if (Key
== NULL
|| This
== NULL
) {
92 return (EFI_INVALID_PARAMETER
);
96 // Check if we have any characters left in the stream.
98 if (((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)This
)->RemainingBytesOfInputFile
== 0) {
99 return (EFI_NOT_READY
);
102 Size
= sizeof(CHAR16
);
104 if(!AsciiRedirection
) {
105 CharSize
= sizeof(CHAR16
);
107 CharSize
= sizeof(CHAR8
);
110 // Decrement the amount of free space by Size or set to zero (for odd length files)
112 if (((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)This
)->RemainingBytesOfInputFile
> CharSize
) {
113 ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)This
)->RemainingBytesOfInputFile
-= CharSize
;
115 ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)This
)->RemainingBytesOfInputFile
= 0;
119 return (ShellInfoObject
.NewEfiShellProtocol
->ReadFile(
120 ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)This
)->FileHandle
,
126 Function to create a EFI_SIMPLE_TEXT_INPUT_PROTOCOL on top of a
127 SHELL_FILE_HANDLE to support redirecting input from a file.
129 @param[in] FileHandleToUse The pointer to the SHELL_FILE_HANDLE to use.
130 @param[in] HandleLocation The pointer of a location to copy handle with protocol to.
132 @retval NULL There was insufficient memory available.
133 @return A pointer to the allocated protocol structure;
135 EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*
136 CreateSimpleTextInOnFile(
137 IN SHELL_FILE_HANDLE FileHandleToUse
,
138 IN EFI_HANDLE
*HandleLocation
141 SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*ProtocolToReturn
;
143 UINT64 CurrentPosition
;
146 if (HandleLocation
== NULL
|| FileHandleToUse
== NULL
) {
150 ProtocolToReturn
= AllocateZeroPool(sizeof(SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
));
151 if (ProtocolToReturn
== NULL
) {
155 ShellGetFileSize (FileHandleToUse
, &FileSize
);
156 ShellGetFilePosition(FileHandleToUse
, &CurrentPosition
);
159 // Initialize the protocol members
161 ProtocolToReturn
->RemainingBytesOfInputFile
= FileSize
- CurrentPosition
;
162 ProtocolToReturn
->FileHandle
= FileHandleToUse
;
163 ProtocolToReturn
->SimpleTextIn
.Reset
= FileBasedSimpleTextInReset
;
164 ProtocolToReturn
->SimpleTextIn
.ReadKeyStroke
= FileBasedSimpleTextInReadKeyStroke
;
166 Status
= gBS
->CreateEvent (
170 &ProtocolToReturn
->SimpleTextIn
,
171 &ProtocolToReturn
->SimpleTextIn
.WaitForKey
174 if (EFI_ERROR(Status
)) {
175 FreePool(ProtocolToReturn
);
178 ///@todo possibly also install SimpleTextInputEx on the handle at this point.
179 Status
= gBS
->InstallProtocolInterface(
180 &(ProtocolToReturn
->TheHandle
),
181 &gEfiSimpleTextInProtocolGuid
,
182 EFI_NATIVE_INTERFACE
,
183 &(ProtocolToReturn
->SimpleTextIn
));
184 if (!EFI_ERROR(Status
)) {
185 *HandleLocation
= ProtocolToReturn
->TheHandle
;
186 return ((EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)ProtocolToReturn
);
188 FreePool(ProtocolToReturn
);
194 Function to close a EFI_SIMPLE_TEXT_INPUT_PROTOCOL on top of a
195 SHELL_FILE_HANDLE to support redirecting input from a file.
197 @param[in] SimpleTextIn The pointer to the SimpleTextIn to close.
199 @retval EFI_SUCCESS The object was closed.
202 CloseSimpleTextInOnFile(
203 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*SimpleTextIn
209 if (SimpleTextIn
== NULL
) {
210 return (EFI_INVALID_PARAMETER
);
213 Status
= gBS
->CloseEvent(((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)SimpleTextIn
)->SimpleTextIn
.WaitForKey
);
215 Status1
= gBS
->UninstallProtocolInterface(
216 ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)SimpleTextIn
)->TheHandle
,
217 &gEfiSimpleTextInProtocolGuid
,
218 &(((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*)SimpleTextIn
)->SimpleTextIn
));
220 FreePool(SimpleTextIn
);
221 if (!EFI_ERROR(Status
)) {
229 Reset the text output device hardware and optionaly run diagnostics.
231 @param This pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
232 @param ExtendedVerification Indicates that a more extensive test may be performed
234 @retval EFI_SUCCESS The text output device was reset.
238 FileBasedSimpleTextOutReset (
239 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
240 IN BOOLEAN ExtendedVerification
243 return (EFI_SUCCESS
);
247 Verifies that all characters in a Unicode string can be output to the
250 @param[in] This Protocol instance pointer.
251 @param[in] WString The NULL-terminated Unicode string to be examined.
253 @retval EFI_SUCCESS The device(s) are capable of rendering the output string.
257 FileBasedSimpleTextOutTestString (
258 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
262 return (EFI_SUCCESS
);
266 Returns information for an available text mode that the output device(s)
269 @param[in] This Protocol instance pointer.
270 @param[in] ModeNumber The mode number to return information on.
271 @param[out] Columns Upon return, the number of columns in the selected geometry
272 @param[out] Rows Upon return, the number of rows in the selected geometry
274 @retval EFI_UNSUPPORTED The mode number was not valid.
278 FileBasedSimpleTextOutQueryMode (
279 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
285 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*PassThruProtocol
;
287 PassThruProtocol
= ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*)This
)->OriginalSimpleTextOut
;
289 // Pass the QueryMode call thru to the original SimpleTextOutProtocol
290 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
,
416 Size
= StrLen(WString
) * sizeof(CHAR16
);
417 return (ShellInfoObject
.NewEfiShellProtocol
->WriteFile(
418 ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*)This
)->FileHandle
,
424 Function to create a EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL on top of a
425 SHELL_FILE_HANDLE to support redirecting output from a file.
427 @param[in] FileHandleToUse The pointer to the SHELL_FILE_HANDLE to use.
428 @param[in] HandleLocation The pointer of a location to copy handle with protocol to.
429 @param[in] OriginalProtocol The pointer to the original output protocol for pass thru of functions.
431 @retval NULL There was insufficient memory available.
432 @return A pointer to the allocated protocol structure;
434 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*
435 CreateSimpleTextOutOnFile(
436 IN SHELL_FILE_HANDLE FileHandleToUse
,
437 IN EFI_HANDLE
*HandleLocation
,
438 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*OriginalProtocol
441 SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*ProtocolToReturn
;
444 if (HandleLocation
== NULL
|| FileHandleToUse
== NULL
) {
448 ProtocolToReturn
= AllocateZeroPool(sizeof(SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
));
449 if (ProtocolToReturn
== NULL
) {
452 ProtocolToReturn
->FileHandle
= FileHandleToUse
;
453 ProtocolToReturn
->OriginalSimpleTextOut
= OriginalProtocol
;
454 ProtocolToReturn
->SimpleTextOut
.Reset
= FileBasedSimpleTextOutReset
;
455 ProtocolToReturn
->SimpleTextOut
.TestString
= FileBasedSimpleTextOutTestString
;
456 ProtocolToReturn
->SimpleTextOut
.QueryMode
= FileBasedSimpleTextOutQueryMode
;
457 ProtocolToReturn
->SimpleTextOut
.SetMode
= FileBasedSimpleTextOutSetMode
;
458 ProtocolToReturn
->SimpleTextOut
.SetAttribute
= FileBasedSimpleTextOutSetAttribute
;
459 ProtocolToReturn
->SimpleTextOut
.ClearScreen
= FileBasedSimpleTextOutClearScreen
;
460 ProtocolToReturn
->SimpleTextOut
.SetCursorPosition
= FileBasedSimpleTextOutSetCursorPosition
;
461 ProtocolToReturn
->SimpleTextOut
.EnableCursor
= FileBasedSimpleTextOutEnableCursor
;
462 ProtocolToReturn
->SimpleTextOut
.OutputString
= FileBasedSimpleTextOutOutputString
;
463 ProtocolToReturn
->SimpleTextOut
.Mode
= AllocateZeroPool(sizeof(EFI_SIMPLE_TEXT_OUTPUT_MODE
));
464 if (ProtocolToReturn
->SimpleTextOut
.Mode
== NULL
) {
465 FreePool(ProtocolToReturn
);
468 ProtocolToReturn
->SimpleTextOut
.Mode
->MaxMode
= OriginalProtocol
->Mode
->MaxMode
;
469 ProtocolToReturn
->SimpleTextOut
.Mode
->Mode
= OriginalProtocol
->Mode
->Mode
;
470 ProtocolToReturn
->SimpleTextOut
.Mode
->Attribute
= OriginalProtocol
->Mode
->Attribute
;
471 ProtocolToReturn
->SimpleTextOut
.Mode
->CursorColumn
= OriginalProtocol
->Mode
->CursorColumn
;
472 ProtocolToReturn
->SimpleTextOut
.Mode
->CursorRow
= OriginalProtocol
->Mode
->CursorRow
;
473 ProtocolToReturn
->SimpleTextOut
.Mode
->CursorVisible
= OriginalProtocol
->Mode
->CursorVisible
;
475 Status
= gBS
->InstallProtocolInterface(
476 &(ProtocolToReturn
->TheHandle
),
477 &gEfiSimpleTextOutProtocolGuid
,
478 EFI_NATIVE_INTERFACE
,
479 &(ProtocolToReturn
->SimpleTextOut
));
480 if (!EFI_ERROR(Status
)) {
481 *HandleLocation
= ProtocolToReturn
->TheHandle
;
482 return ((EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*)ProtocolToReturn
);
484 SHELL_FREE_NON_NULL(ProtocolToReturn
->SimpleTextOut
.Mode
);
485 SHELL_FREE_NON_NULL(ProtocolToReturn
);
491 Function to close a EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL on top of a
492 SHELL_FILE_HANDLE to support redirecting output from a file.
494 @param[in] SimpleTextOut The pointer to the SimpleTextOUT to close.
496 @retval EFI_SUCCESS The object was closed.
499 CloseSimpleTextOutOnFile(
500 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
504 if (SimpleTextOut
== NULL
) {
505 return (EFI_INVALID_PARAMETER
);
507 Status
= gBS
->UninstallProtocolInterface(
508 ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*)SimpleTextOut
)->TheHandle
,
509 &gEfiSimpleTextOutProtocolGuid
,
510 &(((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*)SimpleTextOut
)->SimpleTextOut
));
511 FreePool(SimpleTextOut
->Mode
);
512 FreePool(SimpleTextOut
);