TianoCore EDK2 master
Loading...
Searching...
No Matches
ConsoleWrappers.c
Go to the documentation of this file.
1
10#include "Shell.h"
11
12extern BOOLEAN AsciiRedirection;
13
14typedef struct {
16 SHELL_FILE_HANDLE FileHandle;
17 EFI_HANDLE TheHandle;
18 UINT64 RemainingBytesOfInputFile;
20
21typedef struct {
23 SHELL_FILE_HANDLE FileHandle;
24 EFI_HANDLE TheHandle;
25 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *OriginalSimpleTextOut;
27
36VOID
37EFIAPI
39 IN EFI_EVENT Event,
40 IN VOID *Context
41 )
42{
43 gBS->SignalEvent (Event);
44}
45
55EFIAPI
58 IN BOOLEAN ExtendedVerification
59 )
60{
61 return (EFI_SUCCESS);
62}
63
75EFIAPI
79 )
80{
81 UINTN Size;
82 UINTN CharSize;
83
84 //
85 // Verify the parameters
86 //
87 if ((Key == NULL) || (This == NULL)) {
88 return (EFI_INVALID_PARAMETER);
89 }
90
91 //
92 // Check if we have any characters left in the stream.
93 //
94 if (((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->RemainingBytesOfInputFile == 0) {
95 return (EFI_NOT_READY);
96 }
97
98 Size = sizeof (CHAR16);
99
100 if (!AsciiRedirection) {
101 CharSize = sizeof (CHAR16);
102 } else {
103 CharSize = sizeof (CHAR8);
104 }
105
106 //
107 // Decrement the amount of free space by Size or set to zero (for odd length files)
108 //
109 if (((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->RemainingBytesOfInputFile > CharSize) {
110 ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->RemainingBytesOfInputFile -= CharSize;
111 } else {
112 ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->RemainingBytesOfInputFile = 0;
113 }
114
115 Key->ScanCode = 0;
116 return (ShellInfoObject.NewEfiShellProtocol->ReadFile (
117 ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->FileHandle,
118 &Size,
119 &Key->UnicodeChar
120 ));
121}
122
135 IN SHELL_FILE_HANDLE FileHandleToUse,
136 IN EFI_HANDLE *HandleLocation
137 )
138{
139 SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *ProtocolToReturn;
140 EFI_STATUS Status;
141 UINT64 CurrentPosition;
142 UINT64 FileSize;
143
144 if ((HandleLocation == NULL) || (FileHandleToUse == NULL)) {
145 return (NULL);
146 }
147
148 ProtocolToReturn = AllocateZeroPool (sizeof (SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL));
149 if (ProtocolToReturn == NULL) {
150 return (NULL);
151 }
152
153 ShellGetFileSize (FileHandleToUse, &FileSize);
154 ShellGetFilePosition (FileHandleToUse, &CurrentPosition);
155
156 //
157 // Initialize the protocol members
158 //
159 ProtocolToReturn->RemainingBytesOfInputFile = FileSize - CurrentPosition;
160 ProtocolToReturn->FileHandle = FileHandleToUse;
161 ProtocolToReturn->SimpleTextIn.Reset = FileBasedSimpleTextInReset;
162 ProtocolToReturn->SimpleTextIn.ReadKeyStroke = FileBasedSimpleTextInReadKeyStroke;
163
164 Status = gBS->CreateEvent (
165 EVT_NOTIFY_WAIT,
166 TPL_NOTIFY,
168 &ProtocolToReturn->SimpleTextIn,
169 &ProtocolToReturn->SimpleTextIn.WaitForKey
170 );
171
172 if (EFI_ERROR (Status)) {
173 FreePool (ProtocolToReturn);
174 return (NULL);
175 }
176
178 Status = gBS->InstallProtocolInterface (
179 &(ProtocolToReturn->TheHandle),
180 &gEfiSimpleTextInProtocolGuid,
182 &(ProtocolToReturn->SimpleTextIn)
183 );
184 if (!EFI_ERROR (Status)) {
185 *HandleLocation = ProtocolToReturn->TheHandle;
186 return ((EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)ProtocolToReturn);
187 } else {
188 FreePool (ProtocolToReturn);
189 return (NULL);
190 }
191}
192
204 )
205{
206 EFI_STATUS Status;
207 EFI_STATUS Status1;
208
209 if (SimpleTextIn == NULL) {
210 return (EFI_INVALID_PARAMETER);
211 }
212
213 Status = gBS->CloseEvent (((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)SimpleTextIn)->SimpleTextIn.WaitForKey);
214
215 Status1 = gBS->UninstallProtocolInterface (
216 ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)SimpleTextIn)->TheHandle,
217 &gEfiSimpleTextInProtocolGuid,
218 &(((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)SimpleTextIn)->SimpleTextIn)
219 );
220
221 FreePool (SimpleTextIn);
222 if (!EFI_ERROR (Status)) {
223 return (Status1);
224 } else {
225 return (Status);
226 }
227}
228
238EFIAPI
241 IN BOOLEAN ExtendedVerification
242 )
243{
244 return (EFI_SUCCESS);
245}
246
257EFIAPI
260 IN CHAR16 *WString
261 )
262{
263 return (EFI_SUCCESS);
264}
265
278EFIAPI
281 IN UINTN ModeNumber,
282 OUT UINTN *Columns,
283 OUT UINTN *Rows
284 )
285{
286 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *PassThruProtocol;
287
288 PassThruProtocol = ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)This)->OriginalSimpleTextOut;
289
290 // Pass the QueryMode call thru to the original SimpleTextOutProtocol
291 return (PassThruProtocol->QueryMode (
292 PassThruProtocol,
293 ModeNumber,
294 Columns,
295 Rows
296 ));
297}
298
308EFIAPI
311 IN UINTN ModeNumber
312 )
313{
314 return (EFI_UNSUPPORTED);
315}
316
329EFIAPI
332 IN UINTN Attribute
333 )
334{
335 return (EFI_SUCCESS);
336}
337
347EFIAPI
350 )
351{
352 return (EFI_SUCCESS);
353}
354
365EFIAPI
368 IN UINTN Column,
369 IN UINTN Row
370 )
371{
372 return (EFI_SUCCESS);
373}
374
385EFIAPI
388 IN BOOLEAN Visible
389 )
390{
391 return (EFI_SUCCESS);
392}
393
411EFIAPI
414 IN CHAR16 *WString
415 )
416{
417 UINTN Size;
418
419 Size = StrLen (WString) * sizeof (CHAR16);
420 return (ShellInfoObject.NewEfiShellProtocol->WriteFile (
421 ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)This)->FileHandle,
422 &Size,
423 WString
424 ));
425}
426
440 IN SHELL_FILE_HANDLE FileHandleToUse,
441 IN EFI_HANDLE *HandleLocation,
442 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *OriginalProtocol
443 )
444{
446 EFI_STATUS Status;
447
448 if ((HandleLocation == NULL) || (FileHandleToUse == NULL)) {
449 return (NULL);
450 }
451
452 ProtocolToReturn = AllocateZeroPool (sizeof (SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL));
453 if (ProtocolToReturn == NULL) {
454 return (NULL);
455 }
456
457 ProtocolToReturn->FileHandle = FileHandleToUse;
458 ProtocolToReturn->OriginalSimpleTextOut = OriginalProtocol;
459 ProtocolToReturn->SimpleTextOut.Reset = FileBasedSimpleTextOutReset;
460 ProtocolToReturn->SimpleTextOut.TestString = FileBasedSimpleTextOutTestString;
461 ProtocolToReturn->SimpleTextOut.QueryMode = FileBasedSimpleTextOutQueryMode;
462 ProtocolToReturn->SimpleTextOut.SetMode = FileBasedSimpleTextOutSetMode;
463 ProtocolToReturn->SimpleTextOut.SetAttribute = FileBasedSimpleTextOutSetAttribute;
464 ProtocolToReturn->SimpleTextOut.ClearScreen = FileBasedSimpleTextOutClearScreen;
465 ProtocolToReturn->SimpleTextOut.SetCursorPosition = FileBasedSimpleTextOutSetCursorPosition;
466 ProtocolToReturn->SimpleTextOut.EnableCursor = FileBasedSimpleTextOutEnableCursor;
467 ProtocolToReturn->SimpleTextOut.OutputString = FileBasedSimpleTextOutOutputString;
468 ProtocolToReturn->SimpleTextOut.Mode = AllocateZeroPool (sizeof (EFI_SIMPLE_TEXT_OUTPUT_MODE));
469 if (ProtocolToReturn->SimpleTextOut.Mode == NULL) {
470 FreePool (ProtocolToReturn);
471 return (NULL);
472 }
473
474 ProtocolToReturn->SimpleTextOut.Mode->MaxMode = OriginalProtocol->Mode->MaxMode;
475 ProtocolToReturn->SimpleTextOut.Mode->Mode = OriginalProtocol->Mode->Mode;
476 ProtocolToReturn->SimpleTextOut.Mode->Attribute = OriginalProtocol->Mode->Attribute;
477 ProtocolToReturn->SimpleTextOut.Mode->CursorColumn = OriginalProtocol->Mode->CursorColumn;
478 ProtocolToReturn->SimpleTextOut.Mode->CursorRow = OriginalProtocol->Mode->CursorRow;
479 ProtocolToReturn->SimpleTextOut.Mode->CursorVisible = OriginalProtocol->Mode->CursorVisible;
480
481 Status = gBS->InstallProtocolInterface (
482 &(ProtocolToReturn->TheHandle),
483 &gEfiSimpleTextOutProtocolGuid,
485 &(ProtocolToReturn->SimpleTextOut)
486 );
487 if (!EFI_ERROR (Status)) {
488 *HandleLocation = ProtocolToReturn->TheHandle;
489 return ((EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)ProtocolToReturn);
490 } else {
491 SHELL_FREE_NON_NULL (ProtocolToReturn->SimpleTextOut.Mode);
492 SHELL_FREE_NON_NULL (ProtocolToReturn);
493 return (NULL);
494 }
495}
496
508 )
509{
510 EFI_STATUS Status;
511
512 if (SimpleTextOut == NULL) {
513 return (EFI_INVALID_PARAMETER);
514 }
515
516 Status = gBS->UninstallProtocolInterface (
517 ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)SimpleTextOut)->TheHandle,
518 &gEfiSimpleTextOutProtocolGuid,
519 &(((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)SimpleTextOut)->SimpleTextOut)
520 );
521 FreePool (SimpleTextOut->Mode);
522 FreePool (SimpleTextOut);
523 return (Status);
524}
UINT64 UINTN
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
Definition: String.c:30
EFI_STATUS EFIAPI FileBasedSimpleTextOutSetCursorPosition(IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, IN UINTN Column, IN UINTN Row)
EFI_STATUS EFIAPI FileBasedSimpleTextOutSetMode(IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, IN UINTN ModeNumber)
EFI_STATUS EFIAPI FileBasedSimpleTextOutEnableCursor(IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, IN BOOLEAN Visible)
EFI_STATUS EFIAPI FileBasedSimpleTextInReset(IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, IN BOOLEAN ExtendedVerification)
EFI_STATUS EFIAPI FileBasedSimpleTextOutReset(IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, IN BOOLEAN ExtendedVerification)
VOID EFIAPI ConInWaitForKey(IN EFI_EVENT Event, IN VOID *Context)
EFI_STATUS EFIAPI FileBasedSimpleTextOutQueryMode(IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, IN UINTN ModeNumber, OUT UINTN *Columns, OUT UINTN *Rows)
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL * CreateSimpleTextOutOnFile(IN SHELL_FILE_HANDLE FileHandleToUse, IN EFI_HANDLE *HandleLocation, IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *OriginalProtocol)
EFI_STATUS EFIAPI FileBasedSimpleTextOutOutputString(IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, IN CHAR16 *WString)
EFI_STATUS EFIAPI FileBasedSimpleTextInReadKeyStroke(IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, IN OUT EFI_INPUT_KEY *Key)
EFI_STATUS EFIAPI FileBasedSimpleTextOutSetAttribute(IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, IN UINTN Attribute)
EFI_STATUS CloseSimpleTextOutOnFile(IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut)
EFI_STATUS CloseSimpleTextInOnFile(IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *SimpleTextIn)
EFI_SIMPLE_TEXT_INPUT_PROTOCOL * CreateSimpleTextInOnFile(IN SHELL_FILE_HANDLE FileHandleToUse, IN EFI_HANDLE *HandleLocation)
EFI_STATUS EFIAPI FileBasedSimpleTextOutClearScreen(IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This)
EFI_STATUS EFIAPI FileBasedSimpleTextOutTestString(IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, IN CHAR16 *WString)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
EFI_STATUS EFIAPI ShellGetFileSize(IN SHELL_FILE_HANDLE FileHandle, OUT UINT64 *Size)
EFI_STATUS EFIAPI ShellGetFilePosition(IN SHELL_FILE_HANDLE FileHandle, OUT UINT64 *Position)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_EVENT
Definition: UefiBaseType.h:37
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
@ EFI_NATIVE_INTERFACE
Definition: UefiSpec.h:1193
EFI_SIMPLE_TEXT_OUTPUT_MODE * Mode