]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Console/TerminalDxe/TerminalConOut.c
1. Sync the tracker for supporting the ModeNumber larger than 2.
[mirror_edk2.git] / MdeModulePkg / Universal / Console / TerminalDxe / TerminalConOut.c
1 /*++
2
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 TerminalConOut.c
15
16 Abstract:
17
18
19 Revision History
20 --*/
21
22 #include "Terminal.h"
23
24 //
25 // This list is used to define the valid extend chars.
26 // It also provides a mapping from Unicode to PCANSI or
27 // ASCII. The ASCII mapping we just made up.
28 //
29 //
30 STATIC UNICODE_TO_CHAR UnicodeToPcAnsiOrAscii[] = {
31 { BOXDRAW_HORIZONTAL, 0xc4, L'-' },
32 { BOXDRAW_VERTICAL, 0xb3, L'|' },
33 { BOXDRAW_DOWN_RIGHT, 0xda, L'/' },
34 { BOXDRAW_DOWN_LEFT, 0xbf, L'\\' },
35 { BOXDRAW_UP_RIGHT, 0xc0, L'\\' },
36 { BOXDRAW_UP_LEFT, 0xd9, L'/' },
37 { BOXDRAW_VERTICAL_RIGHT, 0xc3, L'|' },
38 { BOXDRAW_VERTICAL_LEFT, 0xb4, L'|' },
39 { BOXDRAW_DOWN_HORIZONTAL, 0xc2, L'+' },
40 { BOXDRAW_UP_HORIZONTAL, 0xc1, L'+' },
41 { BOXDRAW_VERTICAL_HORIZONTAL, 0xc5, L'+' },
42 { BOXDRAW_DOUBLE_HORIZONTAL, 0xcd, L'-' },
43 { BOXDRAW_DOUBLE_VERTICAL, 0xba, L'|' },
44 { BOXDRAW_DOWN_RIGHT_DOUBLE, 0xd5, L'/' },
45 { BOXDRAW_DOWN_DOUBLE_RIGHT, 0xd6, L'/' },
46 { BOXDRAW_DOUBLE_DOWN_RIGHT, 0xc9, L'/' },
47 { BOXDRAW_DOWN_LEFT_DOUBLE, 0xb8, L'\\' },
48 { BOXDRAW_DOWN_DOUBLE_LEFT, 0xb7, L'\\' },
49 { BOXDRAW_DOUBLE_DOWN_LEFT, 0xbb, L'\\' },
50 { BOXDRAW_UP_RIGHT_DOUBLE, 0xd4, L'\\' },
51 { BOXDRAW_UP_DOUBLE_RIGHT, 0xd3, L'\\' },
52 { BOXDRAW_DOUBLE_UP_RIGHT, 0xc8, L'\\' },
53 { BOXDRAW_UP_LEFT_DOUBLE, 0xbe, L'/' },
54 { BOXDRAW_UP_DOUBLE_LEFT, 0xbd, L'/' },
55 { BOXDRAW_DOUBLE_UP_LEFT, 0xbc, L'/' },
56 { BOXDRAW_VERTICAL_RIGHT_DOUBLE, 0xc6, L'|' },
57 { BOXDRAW_VERTICAL_DOUBLE_RIGHT, 0xc7, L'|' },
58 { BOXDRAW_DOUBLE_VERTICAL_RIGHT, 0xcc, L'|' },
59 { BOXDRAW_VERTICAL_LEFT_DOUBLE, 0xb5, L'|' },
60 { BOXDRAW_VERTICAL_DOUBLE_LEFT, 0xb6, L'|' },
61 { BOXDRAW_DOUBLE_VERTICAL_LEFT, 0xb9, L'|' },
62 { BOXDRAW_DOWN_HORIZONTAL_DOUBLE, 0xd1, L'+' },
63 { BOXDRAW_DOWN_DOUBLE_HORIZONTAL, 0xd2, L'+' },
64 { BOXDRAW_DOUBLE_DOWN_HORIZONTAL, 0xcb, L'+' },
65 { BOXDRAW_UP_HORIZONTAL_DOUBLE, 0xcf, L'+' },
66 { BOXDRAW_UP_DOUBLE_HORIZONTAL, 0xd0, L'+' },
67 { BOXDRAW_DOUBLE_UP_HORIZONTAL, 0xca, L'+' },
68 { BOXDRAW_VERTICAL_HORIZONTAL_DOUBLE, 0xd8, L'+' },
69 { BOXDRAW_VERTICAL_DOUBLE_HORIZONTAL, 0xd7, L'+' },
70 { BOXDRAW_DOUBLE_VERTICAL_HORIZONTAL, 0xce, L'+' },
71
72 { BLOCKELEMENT_FULL_BLOCK, 0xdb, L'*' },
73 { BLOCKELEMENT_LIGHT_SHADE, 0xb0, L'+' },
74
75 { GEOMETRICSHAPE_UP_TRIANGLE, 0x1e, L'^' },
76 { GEOMETRICSHAPE_RIGHT_TRIANGLE, 0x10, L'>' },
77 { GEOMETRICSHAPE_DOWN_TRIANGLE, 0x1f, L'v' },
78 { GEOMETRICSHAPE_LEFT_TRIANGLE, 0x11, L'<' },
79
80 { ARROW_LEFT, 0x3c, L'<' },
81 { ARROW_UP, 0x18, L'^' },
82 { ARROW_RIGHT, 0x3e, L'>' },
83 { ARROW_DOWN, 0x19, L'v' },
84
85 { 0x0000, 0x00, L'\0' }
86 };
87
88 CHAR16 mSetModeString[] = { ESC, '[', '=', '3', 'h', 0 };
89 CHAR16 mSetAttributeString[] = { ESC, '[', '0', 'm', ESC, '[', '4', '0', 'm', ESC, '[', '4', '0', 'm', 0 };
90 CHAR16 mClearScreenString[] = { ESC, '[', '2', 'J', 0 };
91 CHAR16 mSetCursorPositionString[] = { ESC, '[', '0', '0', ';', '0', '0', 'H', 0 };
92
93 //
94 // Body of the ConOut functions
95 //
96 EFI_STATUS
97 EFIAPI
98 TerminalConOutReset (
99 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
100 IN BOOLEAN ExtendedVerification
101 )
102 /*++
103 Routine Description:
104
105 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset().
106 If ExtendeVerification is TRUE, then perform dependent serial device reset,
107 and set display mode to mode 0.
108 If ExtendedVerification is FALSE, only set display mode to mode 0.
109
110 Arguments:
111
112 This - Indicates the calling context.
113
114 ExtendedVerification - Indicates that the driver may perform a more exhaustive
115 verification operation of the device during reset.
116
117 Returns:
118
119 EFI_SUCCESS
120 The reset operation succeeds.
121
122 EFI_DEVICE_ERROR
123 The terminal is not functioning correctly or the serial port reset fails.
124
125 --*/
126 {
127 EFI_STATUS Status;
128 TERMINAL_DEV *TerminalDevice;
129
130 TerminalDevice = TERMINAL_CON_OUT_DEV_FROM_THIS (This);
131
132 //
133 // Perform a more exhaustive reset by resetting the serial port.
134 //
135 if (ExtendedVerification) {
136 //
137 // Report progress code here
138 //
139 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
140 EFI_PROGRESS_CODE,
141 PcdGet32 (PcdStatusCodeValueRemoteConsoleReset),
142 TerminalDevice->DevicePath
143 );
144
145 Status = TerminalDevice->SerialIo->Reset (TerminalDevice->SerialIo);
146 if (EFI_ERROR (Status)) {
147 //
148 // Report error code here
149 //
150 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
151 EFI_ERROR_CODE | EFI_ERROR_MINOR,
152 PcdGet32 (PcdStatusCodeValueRemoteConsoleError),
153 TerminalDevice->DevicePath
154 );
155
156 return Status;
157 }
158 }
159
160 This->SetAttribute (This, EFI_TEXT_ATTR (This->Mode->Attribute & 0x0F, EFI_BACKGROUND_BLACK));
161
162 Status = This->SetMode (This, 0);
163
164 return Status;
165 }
166
167 EFI_STATUS
168 EFIAPI
169 TerminalConOutOutputString (
170 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
171 IN CHAR16 *WString
172 )
173 /*++
174 Routine Description:
175
176 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString().
177 The Unicode string will be converted to terminal expressible data stream
178 and send to terminal via serial port.
179
180
181 Arguments:
182
183 This - Indicates the calling context.
184
185 WString - The Null-terminated Unicode string to be displayed on
186 the terminal screen.
187
188 Returns:
189
190 EFI_SUCCESS
191 The string is output successfully.
192
193 EFI_DEVICE_ERROR
194 The serial port fails to send the string out.
195
196 EFI_WARN_UNKNOWN_GLYPH
197 Indicates that some of the characters in the Unicode string could not
198 be rendered and are skipped.
199
200 EFI_UNSUPPORTED
201
202 --*/
203 {
204 TERMINAL_DEV *TerminalDevice;
205 EFI_SIMPLE_TEXT_OUTPUT_MODE *Mode;
206 UINTN MaxColumn;
207 UINTN MaxRow;
208 UINTN Length;
209 UTF8_CHAR Utf8Char;
210 CHAR8 GraphicChar;
211 CHAR8 AsciiChar;
212 EFI_STATUS Status;
213 UINT8 ValidBytes;
214 //
215 // flag used to indicate whether condition happens which will cause
216 // return EFI_WARN_UNKNOWN_GLYPH
217 //
218 BOOLEAN Warning;
219
220 ValidBytes = 0;
221 Warning = FALSE;
222
223 //
224 // get Terminal device data structure pointer.
225 //
226 TerminalDevice = TERMINAL_CON_OUT_DEV_FROM_THIS (This);
227
228 //
229 // Get current display mode
230 //
231 Mode = This->Mode;
232
233 if (Mode->Mode > 2) {
234 return EFI_UNSUPPORTED;
235 }
236
237 This->QueryMode (
238 This,
239 Mode->Mode,
240 &MaxColumn,
241 &MaxRow
242 );
243
244 for (; *WString != CHAR_NULL; WString++) {
245
246 switch (TerminalDevice->TerminalType) {
247
248 case PcAnsiType:
249 case VT100Type:
250 case VT100PlusType:
251
252 if (!TerminalIsValidTextGraphics (*WString, &GraphicChar, &AsciiChar)) {
253 //
254 // If it's not a graphic character convert Unicode to ASCII.
255 //
256 GraphicChar = (CHAR8) *WString;
257
258 if (!(TerminalIsValidAscii (GraphicChar) || TerminalIsValidEfiCntlChar (GraphicChar))) {
259 //
260 // when this driver use the OutputString to output control string,
261 // TerminalDevice->OutputEscChar is set to let the Esc char
262 // to be output to the terminal emulation software.
263 //
264 if ((GraphicChar == 27) && TerminalDevice->OutputEscChar) {
265 GraphicChar = 27;
266 } else {
267 GraphicChar = '?';
268 Warning = TRUE;
269 }
270 }
271
272 AsciiChar = GraphicChar;
273
274 }
275
276 if (TerminalDevice->TerminalType != PcAnsiType) {
277 GraphicChar = AsciiChar;
278 }
279
280 Length = 1;
281
282 Status = TerminalDevice->SerialIo->Write (
283 TerminalDevice->SerialIo,
284 &Length,
285 &GraphicChar
286 );
287
288 if (EFI_ERROR (Status)) {
289 goto OutputError;
290 }
291
292 break;
293
294 case VTUTF8Type:
295 UnicodeToUtf8 (*WString, &Utf8Char, &ValidBytes);
296 Length = ValidBytes;
297 Status = TerminalDevice->SerialIo->Write (
298 TerminalDevice->SerialIo,
299 &Length,
300 (UINT8 *) &Utf8Char
301 );
302 if (EFI_ERROR (Status)) {
303 goto OutputError;
304 }
305 break;
306 }
307 //
308 // Update cursor position.
309 //
310 switch (*WString) {
311
312 case CHAR_BACKSPACE:
313 if (Mode->CursorColumn > 0) {
314 Mode->CursorColumn--;
315 }
316 break;
317
318 case CHAR_LINEFEED:
319 if (Mode->CursorRow < (INT32) (MaxRow - 1)) {
320 Mode->CursorRow++;
321 }
322 break;
323
324 case CHAR_CARRIAGE_RETURN:
325 Mode->CursorColumn = 0;
326 break;
327
328 default:
329 if (Mode->CursorColumn < (INT32) (MaxColumn - 1)) {
330
331 Mode->CursorColumn++;
332
333 } else {
334
335 Mode->CursorColumn = 0;
336 if (Mode->CursorRow < (INT32) (MaxRow - 1)) {
337 Mode->CursorRow++;
338 }
339
340 }
341 break;
342
343 };
344
345 }
346
347 if (Warning) {
348 return EFI_WARN_UNKNOWN_GLYPH;
349 }
350
351 return EFI_SUCCESS;
352
353 OutputError:
354 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
355 EFI_ERROR_CODE | EFI_ERROR_MINOR,
356 PcdGet32 (PcdStatusCodeValueRemoteConsoleOutputError),
357 TerminalDevice->DevicePath
358 );
359
360 return EFI_DEVICE_ERROR;
361 }
362
363 EFI_STATUS
364 EFIAPI
365 TerminalConOutTestString (
366 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
367 IN CHAR16 *WString
368 )
369 /*++
370 Routine Description:
371
372 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.TestString().
373 If one of the characters in the *Wstring is
374 neither valid Unicode drawing characters,
375 not ASCII code, then this function will return
376 EFI_UNSUPPORTED.
377
378
379 Arguments:
380
381 This - Indicates the calling context.
382
383 WString - The Null-terminated Unicode string to be tested.
384
385 Returns:
386
387 EFI_SUCCESS
388 The terminal is capable of rendering the output string.
389
390 EFI_UNSUPPORTED
391 Some of the characters in the Unicode string cannot be rendered.
392
393 --*/
394 {
395 TERMINAL_DEV *TerminalDevice;
396 EFI_STATUS Status;
397
398 //
399 // get Terminal device data structure pointer.
400 //
401 TerminalDevice = TERMINAL_CON_OUT_DEV_FROM_THIS (This);
402
403 switch (TerminalDevice->TerminalType) {
404
405 case PcAnsiType:
406 case VT100Type:
407 case VT100PlusType:
408 Status = AnsiTestString (TerminalDevice, WString);
409 break;
410
411 case VTUTF8Type:
412 Status = VTUTF8TestString (TerminalDevice, WString);
413 break;
414
415 default:
416 Status = EFI_UNSUPPORTED;
417 break;
418 }
419
420 return Status;
421 }
422
423 EFI_STATUS
424 EFIAPI
425 TerminalConOutQueryMode (
426 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
427 IN UINTN ModeNumber,
428 OUT UINTN *Columns,
429 OUT UINTN *Rows
430 )
431 /*++
432 Routine Description:
433
434 Implements EFI_SIMPLE_TEXT_OUT_PROTOCOL.QueryMode().
435 It returns information for an available text mode
436 that the terminal supports.
437 In this driver, we support text mode 80x25 (mode 0),
438 80x50 (mode 1), 100x31 (mode 2).
439
440
441 Arguments:
442
443 *This
444 Indicates the calling context.
445
446 ModeNumber
447 The mode number to return information on.
448
449 Columns
450 The returned columns of the requested mode.
451
452 Rows
453 The returned rows of the requested mode.
454
455 Returns:
456
457 EFI_SUCCESS
458 The requested mode information is returned.
459
460 EFI_UNSUPPORTED
461 The mode number is not valid.
462
463 EFI_DEVICE_ERROR
464
465 --*/
466 {
467 if (This->Mode->MaxMode > 3) {
468 return EFI_DEVICE_ERROR;
469 }
470
471 if (ModeNumber == 0) {
472 *Columns = MODE0_COLUMN_COUNT;
473 *Rows = MODE0_ROW_COUNT;
474 return EFI_SUCCESS;
475 } else if (ModeNumber == 1) {
476 *Columns = MODE1_COLUMN_COUNT;
477 *Rows = MODE1_ROW_COUNT;
478 return EFI_SUCCESS;
479 } else if (ModeNumber == 2) {
480 *Columns = MODE2_COLUMN_COUNT;
481 *Rows = MODE2_ROW_COUNT;
482 return EFI_SUCCESS;
483 }
484
485 return EFI_UNSUPPORTED;
486 }
487
488 EFI_STATUS
489 EFIAPI
490 TerminalConOutSetMode (
491 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
492 IN UINTN ModeNumber
493 )
494 /*++
495 Routine Description:
496
497 Implements EFI_SIMPLE_TEXT_OUT.SetMode().
498 Set the terminal to a specified display mode.
499 In this driver, we only support mode 0.
500
501 Arguments:
502
503 This
504 Indicates the calling context.
505
506 ModeNumber
507 The text mode to set.
508
509 Returns:
510
511 EFI_SUCCESS
512 The requested text mode is set.
513
514 EFI_DEVICE_ERROR
515 The requested text mode cannot be set because of serial device error.
516
517 EFI_UNSUPPORTED
518 The text mode number is not valid.
519
520 --*/
521 {
522 EFI_STATUS Status;
523 TERMINAL_DEV *TerminalDevice;
524
525 //
526 // get Terminal device data structure pointer.
527 //
528 TerminalDevice = TERMINAL_CON_OUT_DEV_FROM_THIS (This);
529
530 if (ModeNumber > 2) {
531 return EFI_UNSUPPORTED;
532 }
533
534 //
535 // Set the current mode
536 //
537 This->Mode->Mode = (INT32) ModeNumber;
538
539 This->ClearScreen (This);
540
541 TerminalDevice->OutputEscChar = TRUE;
542 Status = This->OutputString (This, mSetModeString);
543 TerminalDevice->OutputEscChar = FALSE;
544
545 if (EFI_ERROR (Status)) {
546 return EFI_DEVICE_ERROR;
547 }
548
549 This->Mode->Mode = (INT32) ModeNumber;
550
551 Status = This->ClearScreen (This);
552 if (EFI_ERROR (Status)) {
553 return EFI_DEVICE_ERROR;
554 }
555
556 return EFI_SUCCESS;
557
558 }
559
560 EFI_STATUS
561 EFIAPI
562 TerminalConOutSetAttribute (
563 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
564 IN UINTN Attribute
565 )
566 /*++
567 Routine Description:
568
569 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetAttribute().
570
571 Arguments:
572
573 This
574 Indicates the calling context.
575
576 Attribute
577 The attribute to set. Only bit0..6 are valid, all other bits
578 are undefined and must be zero.
579
580 Returns:
581
582 EFI_SUCCESS
583 The requested attribute is set.
584
585 EFI_DEVICE_ERROR
586 The requested attribute cannot be set due to serial port error.
587
588 EFI_UNSUPPORTED
589 The attribute requested is not defined by EFI spec.
590
591 --*/
592 {
593 UINT8 ForegroundControl;
594 UINT8 BackgroundControl;
595 UINT8 BrightControl;
596 INT32 SavedColumn;
597 INT32 SavedRow;
598 EFI_STATUS Status;
599 TERMINAL_DEV *TerminalDevice;
600
601 SavedColumn = 0;
602 SavedRow = 0;
603
604 //
605 // get Terminal device data structure pointer.
606 //
607 TerminalDevice = TERMINAL_CON_OUT_DEV_FROM_THIS (This);
608
609 //
610 // only the bit0..6 of the Attribute is valid
611 //
612 if ((Attribute | 0x7f) != 0x7f) {
613 return EFI_UNSUPPORTED;
614 }
615 //
616 // convert Attribute value to terminal emulator
617 // understandable foreground color
618 //
619 switch (Attribute & 0x07) {
620
621 case EFI_BLACK:
622 ForegroundControl = 30;
623 break;
624
625 case EFI_BLUE:
626 ForegroundControl = 34;
627 break;
628
629 case EFI_GREEN:
630 ForegroundControl = 32;
631 break;
632
633 case EFI_CYAN:
634 ForegroundControl = 36;
635 break;
636
637 case EFI_RED:
638 ForegroundControl = 31;
639 break;
640
641 case EFI_MAGENTA:
642 ForegroundControl = 35;
643 break;
644
645 case EFI_BROWN:
646 ForegroundControl = 33;
647 break;
648
649 default:
650
651 case EFI_LIGHTGRAY:
652 ForegroundControl = 37;
653 break;
654
655 }
656 //
657 // bit4 of the Attribute indicates bright control
658 // of terminal emulator.
659 //
660 BrightControl = (UINT8) ((Attribute >> 3) & 1);
661
662 //
663 // convert Attribute value to terminal emulator
664 // understandable background color.
665 //
666 switch ((Attribute >> 4) & 0x07) {
667
668 case EFI_BLACK:
669 BackgroundControl = 40;
670 break;
671
672 case EFI_BLUE:
673 BackgroundControl = 44;
674 break;
675
676 case EFI_GREEN:
677 BackgroundControl = 42;
678 break;
679
680 case EFI_CYAN:
681 BackgroundControl = 46;
682 break;
683
684 case EFI_RED:
685 BackgroundControl = 41;
686 break;
687
688 case EFI_MAGENTA:
689 BackgroundControl = 45;
690 break;
691
692 case EFI_BROWN:
693 BackgroundControl = 43;
694 break;
695
696 default:
697
698 case EFI_LIGHTGRAY:
699 BackgroundControl = 47;
700 break;
701 }
702 //
703 // terminal emulator's control sequence to set attributes
704 //
705 mSetAttributeString[BRIGHT_CONTROL_OFFSET] = (CHAR16) ('0' + BrightControl);
706 mSetAttributeString[FOREGROUND_CONTROL_OFFSET + 0] = (CHAR16) ('0' + (ForegroundControl / 10));
707 mSetAttributeString[FOREGROUND_CONTROL_OFFSET + 1] = (CHAR16) ('0' + (ForegroundControl % 10));
708 mSetAttributeString[BACKGROUND_CONTROL_OFFSET + 0] = (CHAR16) ('0' + (BackgroundControl / 10));
709 mSetAttributeString[BACKGROUND_CONTROL_OFFSET + 1] = (CHAR16) ('0' + (BackgroundControl % 10));
710
711 //
712 // save current column and row
713 // for future scrolling back use.
714 //
715 SavedColumn = This->Mode->CursorColumn;
716 SavedRow = This->Mode->CursorRow;
717
718 TerminalDevice->OutputEscChar = TRUE;
719 Status = This->OutputString (This, mSetAttributeString);
720 TerminalDevice->OutputEscChar = FALSE;
721
722 if (EFI_ERROR (Status)) {
723 return EFI_DEVICE_ERROR;
724 }
725 //
726 // scroll back to saved cursor position.
727 //
728 This->Mode->CursorColumn = SavedColumn;
729 This->Mode->CursorRow = SavedRow;
730
731 This->Mode->Attribute = (INT32) Attribute;
732
733 return EFI_SUCCESS;
734
735 }
736
737 EFI_STATUS
738 EFIAPI
739 TerminalConOutClearScreen (
740 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This
741 )
742 /*++
743 Routine Description:
744
745 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.ClearScreen().
746 It clears the ANSI terminal's display to the
747 currently selected background color.
748
749
750 Arguments:
751
752 This
753 Indicates the calling context.
754
755 Returns:
756
757 EFI_SUCCESS
758 The operation completed successfully.
759
760 EFI_DEVICE_ERROR
761 The terminal screen cannot be cleared due to serial port error.
762
763 EFI_UNSUPPORTED
764 The terminal is not in a valid display mode.
765
766 --*/
767 {
768 EFI_STATUS Status;
769 TERMINAL_DEV *TerminalDevice;
770
771 TerminalDevice = TERMINAL_CON_OUT_DEV_FROM_THIS (This);
772
773 //
774 // control sequence for clear screen request
775 //
776 TerminalDevice->OutputEscChar = TRUE;
777 Status = This->OutputString (This, mClearScreenString);
778 TerminalDevice->OutputEscChar = FALSE;
779
780 if (EFI_ERROR (Status)) {
781 return EFI_DEVICE_ERROR;
782 }
783
784 Status = This->SetCursorPosition (This, 0, 0);
785
786 return Status;
787 }
788
789 EFI_STATUS
790 EFIAPI
791 TerminalConOutSetCursorPosition (
792 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
793 IN UINTN Column,
794 IN UINTN Row
795 )
796 /*++
797 Routine Description:
798
799 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetCursorPosition().
800
801 Arguments:
802
803 This
804 Indicates the calling context.
805
806 Column
807 The row to set cursor to.
808
809 Row
810 The column to set cursor to.
811
812 Returns:
813
814 EFI_SUCCESS
815 The operation completed successfully.
816
817 EFI_DEVICE_ERROR
818 The request fails due to serial port error.
819
820 EFI_UNSUPPORTED
821 The terminal is not in a valid text mode, or the cursor position
822 is invalid for current mode.
823
824 --*/
825 {
826 EFI_SIMPLE_TEXT_OUTPUT_MODE *Mode;
827 UINTN MaxColumn;
828 UINTN MaxRow;
829 EFI_STATUS Status;
830 TERMINAL_DEV *TerminalDevice;
831
832 TerminalDevice = TERMINAL_CON_OUT_DEV_FROM_THIS (This);
833
834 //
835 // get current mode
836 //
837 Mode = This->Mode;
838
839 //
840 // get geometry of current mode
841 //
842 Status = This->QueryMode (
843 This,
844 Mode->Mode,
845 &MaxColumn,
846 &MaxRow
847 );
848 if (EFI_ERROR (Status)) {
849 return EFI_UNSUPPORTED;
850 }
851
852 if (Column >= MaxColumn || Row >= MaxRow) {
853 return EFI_UNSUPPORTED;
854 }
855 //
856 // control sequence to move the cursor
857 //
858 mSetCursorPositionString[ROW_OFFSET + 0] = (CHAR16) ('0' + ((Row + 1) / 10));
859 mSetCursorPositionString[ROW_OFFSET + 1] = (CHAR16) ('0' + ((Row + 1) % 10));
860 mSetCursorPositionString[COLUMN_OFFSET + 0] = (CHAR16) ('0' + ((Column + 1) / 10));
861 mSetCursorPositionString[COLUMN_OFFSET + 1] = (CHAR16) ('0' + ((Column + 1) % 10));
862
863 TerminalDevice->OutputEscChar = TRUE;
864 Status = This->OutputString (This, mSetCursorPositionString);
865 TerminalDevice->OutputEscChar = FALSE;
866
867 if (EFI_ERROR (Status)) {
868 return EFI_DEVICE_ERROR;
869 }
870 //
871 // update current cursor position
872 // in the Mode data structure.
873 //
874 Mode->CursorColumn = (INT32) Column;
875 Mode->CursorRow = (INT32) Row;
876
877 return EFI_SUCCESS;
878 }
879
880 EFI_STATUS
881 EFIAPI
882 TerminalConOutEnableCursor (
883 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
884 IN BOOLEAN Visible
885 )
886 /*++
887 Routine Description:
888
889 Implements SIMPLE_TEXT_OUTPUT.EnableCursor().
890 In this driver, the cursor cannot be hidden.
891
892 Arguments:
893
894 This
895 Indicates the calling context.
896
897 Visible
898 If TRUE, the cursor is set to be visible,
899 If FALSE, the cursor is set to be invisible.
900
901 Returns:
902
903 EFI_SUCCESS
904 The request is valid.
905
906 EFI_UNSUPPORTED
907 The terminal does not support cursor hidden.
908
909 --*/
910 {
911 if (!Visible) {
912 return EFI_UNSUPPORTED;
913 }
914
915 return EFI_SUCCESS;
916 }
917
918 BOOLEAN
919 TerminalIsValidTextGraphics (
920 IN CHAR16 Graphic,
921 OUT CHAR8 *PcAnsi, OPTIONAL
922 OUT CHAR8 *Ascii OPTIONAL
923 )
924 /*++
925
926 Routine Description:
927
928 Detects if a Unicode char is for Box Drawing text graphics.
929
930 Arguments:
931
932 Graphic - Unicode char to test.
933
934 PcAnsi - Optional pointer to return PCANSI equivalent of Graphic.
935
936 Ascii - Optional pointer to return ASCII equivalent of Graphic.
937
938 Returns:
939
940 TRUE if Graphic is a supported Unicode Box Drawing character.
941
942 --*/
943 {
944 UNICODE_TO_CHAR *Table;
945
946 if ((((Graphic & 0xff00) != 0x2500) && ((Graphic & 0xff00) != 0x2100))) {
947 //
948 // Unicode drawing code charts are all in the 0x25xx range,
949 // arrows are 0x21xx
950 //
951 return FALSE;
952 }
953
954 for (Table = UnicodeToPcAnsiOrAscii; Table->Unicode != 0x0000; Table++) {
955 if (Graphic == Table->Unicode) {
956 if (PcAnsi != NULL) {
957 *PcAnsi = Table->PcAnsi;
958 }
959
960 if (Ascii != NULL) {
961 *Ascii = Table->Ascii;
962 }
963
964 return TRUE;
965 }
966 }
967
968 return FALSE;
969 }
970
971 BOOLEAN
972 TerminalIsValidAscii (
973 IN CHAR16 Ascii
974 )
975 {
976 //
977 // valid ascii code lies in the extent of 0x20 ~ 0x7f
978 //
979 if ((Ascii >= 0x20) && (Ascii <= 0x7f)) {
980 return TRUE;
981 }
982
983 return FALSE;
984 }
985
986 BOOLEAN
987 TerminalIsValidEfiCntlChar (
988 IN CHAR16 CharC
989 )
990 {
991 //
992 // only support four control characters.
993 //
994 if (CharC == CHAR_NULL ||
995 CharC == CHAR_BACKSPACE ||
996 CharC == CHAR_LINEFEED ||
997 CharC == CHAR_CARRIAGE_RETURN ||
998 CharC == CHAR_TAB
999 ) {
1000 return TRUE;
1001 }
1002
1003 return FALSE;
1004 }