]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/Dxe/Graphics/Print.c
Add in the 1st version of ECP.
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / Dxe / Graphics / Print.c
1 /*++
2
3 Copyright (c) 2004 - 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 Print.c
15
16 Abstract:
17
18 Basic Ascii AvSPrintf() function named VSPrint(). VSPrint() enables very
19 simple implemenation of SPrint() and Print() to support debug.
20
21 You can not Print more than EFI_DRIVER_LIB_MAX_PRINT_BUFFER characters at a
22 time. This makes the implementation very simple.
23
24 VSPrint, Print, SPrint format specification has the follwoing form
25
26 %[flags][width]type
27
28 flags:
29 '-' - Left justify
30 '+' - Prefix a sign
31 ' ' - Prefix a blank
32 ',' - Place commas in numberss
33 '0' - Prefix for width with zeros
34 'l' - UINT64
35 'L' - UINT64
36
37 width:
38 '*' - Get width from a UINTN argumnet from the argument list
39 Decimal number that represents width of print
40
41 type:
42 'X' - argument is a UINTN hex number, prefix '0'
43 'x' - argument is a hex number
44 'd' - argument is a decimal number
45 'a' - argument is an ascii string
46 'S','s' - argument is an Unicode string
47 'g' - argument is a pointer to an EFI_GUID
48 't' - argument is a pointer to an EFI_TIME structure
49 'c' - argument is an ascii character
50 'r' - argument is EFI_STATUS
51 '%' - Print a %
52
53 --*/
54
55 #include "Tiano.h"
56 #include "EfiDriverLib.h"
57 #include "TianoCommon.h"
58 #include "EfiCommonLib.h"
59 #include "PrintWidth.h"
60 #include "EfiPrintLib.h"
61 #include "Print.h"
62 #include EFI_PROTOCOL_DEFINITION (Hii)
63
64 STATIC
65 CHAR_W *
66 GetFlagsAndWidth (
67 IN CHAR_W *Format,
68 OUT UINTN *Flags,
69 OUT UINTN *Width,
70 IN OUT VA_LIST *Marker
71 );
72
73 STATIC
74 UINTN
75 GuidToString (
76 IN EFI_GUID *Guid,
77 IN OUT CHAR_W *Buffer,
78 IN UINTN BufferSize
79 );
80
81 STATIC
82 UINTN
83 TimeToString (
84 IN EFI_TIME *Time,
85 IN OUT CHAR_W *Buffer,
86 IN UINTN BufferSize
87 );
88
89 STATIC
90 UINTN
91 EfiStatusToString (
92 IN EFI_STATUS Status,
93 OUT CHAR_W *Buffer,
94 IN UINTN BufferSize
95 );
96
97 static EFI_GRAPHICS_OUTPUT_BLT_PIXEL mEfiColors[16] = {
98 0x00, 0x00, 0x00, 0x00,
99 0x98, 0x00, 0x00, 0x00,
100 0x00, 0x98, 0x00, 0x00,
101 0x98, 0x98, 0x00, 0x00,
102 0x00, 0x00, 0x98, 0x00,
103 0x98, 0x00, 0x98, 0x00,
104 0x00, 0x98, 0x98, 0x00,
105 0x98, 0x98, 0x98, 0x00,
106 0x10, 0x10, 0x10, 0x00,
107 0xff, 0x10, 0x10, 0x00,
108 0x10, 0xff, 0x10, 0x00,
109 0xff, 0xff, 0x10, 0x00,
110 0x10, 0x10, 0xff, 0x00,
111 0xf0, 0x10, 0xff, 0x00,
112 0x10, 0xff, 0xff, 0x00,
113 0xff, 0xff, 0xff, 0x00,
114 };
115
116
117 UINTN
118 _IPrint (
119 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput,
120 IN EFI_UGA_DRAW_PROTOCOL *UgaDraw,
121 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *Sto,
122 IN UINTN X,
123 IN UINTN Y,
124 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Foreground,
125 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Background,
126 IN CHAR16 *fmt,
127 IN VA_LIST args
128 )
129 /*++
130
131 Routine Description:
132
133 Display string worker for: Print, PrintAt, IPrint, IPrintAt
134
135 Arguments:
136
137 GraphicsOutput - Graphics output protocol interface
138
139 UgaDraw - UGA draw protocol interface
140
141 Sto - Simple text out protocol interface
142
143 X - X coordinate to start printing
144
145 Y - Y coordinate to start printing
146
147 Foreground - Foreground color
148
149 Background - Background color
150
151 fmt - Format string
152
153 args - Print arguments
154
155 Returns:
156
157 EFI_SUCCESS - success
158 EFI_OUT_OF_RESOURCES - out of resources
159
160 --*/
161 {
162 VOID *Buffer;
163 EFI_STATUS Status;
164 UINT16 GlyphWidth;
165 UINT32 GlyphStatus;
166 UINT16 StringIndex;
167 UINTN Index;
168 CHAR16 *UnicodeWeight;
169 EFI_NARROW_GLYPH *Glyph;
170 EFI_HII_PROTOCOL *Hii;
171 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *LineBuffer;
172 UINT32 HorizontalResolution;
173 UINT32 VerticalResolution;
174 UINT32 ColorDepth;
175 UINT32 RefreshRate;
176 UINTN BufferLen;
177 UINTN LineBufferLen;
178
179 GlyphStatus = 0;
180
181 //
182 // For now, allocate an arbitrarily long buffer
183 //
184 Buffer = EfiLibAllocateZeroPool (0x10000);
185 if (Buffer == NULL) {
186 return EFI_OUT_OF_RESOURCES;
187 }
188
189 if (GraphicsOutput != NULL) {
190 HorizontalResolution = GraphicsOutput->Mode->Info->HorizontalResolution;
191 VerticalResolution = GraphicsOutput->Mode->Info->VerticalResolution;
192 } else {
193 UgaDraw->GetMode (UgaDraw, &HorizontalResolution, &VerticalResolution, &ColorDepth, &RefreshRate);
194 }
195 ASSERT ((HorizontalResolution != 0) && (VerticalResolution !=0));
196
197 LineBufferLen = sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * HorizontalResolution * GLYPH_HEIGHT;
198 LineBuffer = EfiLibAllocatePool (LineBufferLen);
199 if (LineBuffer == NULL) {
200 gBS->FreePool (Buffer);
201 return EFI_OUT_OF_RESOURCES;
202 }
203
204 Status = gBS->LocateProtocol (&gEfiHiiProtocolGuid, NULL, (VOID**)&Hii);
205 if (EFI_ERROR (Status)) {
206 goto Error;
207 }
208
209 VSPrint (Buffer, 0x10000, fmt, args);
210
211 UnicodeWeight = (CHAR16 *) Buffer;
212
213 for (Index = 0; UnicodeWeight[Index] != 0; Index++) {
214 if (UnicodeWeight[Index] == CHAR_BACKSPACE ||
215 UnicodeWeight[Index] == CHAR_LINEFEED ||
216 UnicodeWeight[Index] == CHAR_CARRIAGE_RETURN) {
217 UnicodeWeight[Index] = 0;
218 }
219 }
220
221 BufferLen = EfiStrLen (Buffer);
222
223 if (GLYPH_WIDTH * GLYPH_HEIGHT * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * BufferLen > LineBufferLen) {
224 Status = EFI_INVALID_PARAMETER;
225 goto Error;
226 }
227
228 for (Index = 0; Index < BufferLen; Index++) {
229 StringIndex = (UINT16) Index;
230 Status = Hii->GetGlyph (Hii, UnicodeWeight, &StringIndex, (UINT8 **) &Glyph, &GlyphWidth, &GlyphStatus);
231 if (EFI_ERROR (Status)) {
232 goto Error;
233 }
234
235 if (Foreground == NULL || Background == NULL) {
236 Status = Hii->GlyphToBlt (
237 Hii,
238 (UINT8 *) Glyph,
239 mEfiColors[Sto->Mode->Attribute & 0x0f],
240 mEfiColors[Sto->Mode->Attribute >> 4],
241 BufferLen,
242 GlyphWidth,
243 GLYPH_HEIGHT,
244 &LineBuffer[Index * GLYPH_WIDTH]
245 );
246 } else {
247 Status = Hii->GlyphToBlt (
248 Hii,
249 (UINT8 *) Glyph,
250 *Foreground,
251 *Background,
252 BufferLen,
253 GlyphWidth,
254 GLYPH_HEIGHT,
255 &LineBuffer[Index * GLYPH_WIDTH]
256 );
257 }
258 }
259
260 //
261 // Blt a character to the screen
262 //
263 if (GraphicsOutput != NULL) {
264 Status = GraphicsOutput->Blt (
265 GraphicsOutput,
266 LineBuffer,
267 EfiBltBufferToVideo,
268 0,
269 0,
270 X,
271 Y,
272 GLYPH_WIDTH * BufferLen,
273 GLYPH_HEIGHT,
274 GLYPH_WIDTH * BufferLen * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
275 );
276 } else {
277 Status = UgaDraw->Blt (
278 UgaDraw,
279 (EFI_UGA_PIXEL *) LineBuffer,
280 EfiUgaBltBufferToVideo,
281 0,
282 0,
283 X,
284 Y,
285 GLYPH_WIDTH * BufferLen,
286 GLYPH_HEIGHT,
287 GLYPH_WIDTH * BufferLen * sizeof (EFI_UGA_PIXEL)
288 );
289 }
290
291 Error:
292 gBS->FreePool (LineBuffer);
293 gBS->FreePool (Buffer);
294 return Status;
295 }
296
297
298 UINTN
299 PrintXY (
300 IN UINTN X,
301 IN UINTN Y,
302 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *ForeGround, OPTIONAL
303 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BackGround, OPTIONAL
304 IN CHAR_W *Fmt,
305 ...
306 )
307 /*++
308
309 Routine Description:
310
311 Prints a formatted unicode string to the default console
312
313 Arguments:
314
315 X - X coordinate to start printing
316
317 Y - Y coordinate to start printing
318
319 ForeGround - Foreground color
320
321 BackGround - Background color
322
323 Fmt - Format string
324
325 ... - Print arguments
326
327 Returns:
328
329 Length of string printed to the console
330
331 --*/
332 {
333 EFI_HANDLE Handle;
334 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
335 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
336 EFI_SIMPLE_TEXT_OUT_PROTOCOL *Sto;
337 EFI_STATUS Status;
338 VA_LIST Args;
339
340 VA_START (Args, Fmt);
341
342 Handle = gST->ConsoleOutHandle;
343
344 Status = gBS->HandleProtocol (
345 Handle,
346 &gEfiGraphicsOutputProtocolGuid,
347 (VOID**)&GraphicsOutput
348 );
349
350 UgaDraw = NULL;
351 if (EFI_ERROR (Status)) {
352 GraphicsOutput = NULL;
353
354 Status = gBS->HandleProtocol (
355 Handle,
356 &gEfiUgaDrawProtocolGuid,
357 (VOID**)&UgaDraw
358 );
359
360 if (EFI_ERROR (Status)) {
361 return Status;
362 }
363 }
364
365 Status = gBS->HandleProtocol (
366 Handle,
367 &gEfiSimpleTextOutProtocolGuid,
368 (VOID**)&Sto
369 );
370
371 if (EFI_ERROR (Status)) {
372 return Status;
373 }
374
375 return _IPrint (GraphicsOutput, UgaDraw, Sto, X, Y, ForeGround, BackGround, Fmt, Args);
376 }
377
378
379 UINTN
380 SPrint (
381 OUT CHAR_W *Buffer,
382 IN UINTN BufferSize,
383 IN CONST CHAR_W *Format,
384 ...
385 )
386 /*++
387
388 Routine Description:
389
390 SPrint function to process format and place the results in Buffer.
391
392 Arguments:
393
394 Buffer - Wide char buffer to print the results of the parsing of Format into.
395
396 BufferSize - Maximum number of characters to put into buffer. Zero means no
397 limit.
398
399 Format - Format string see file header for more details.
400
401 ... - Vararg list consumed by processing Format.
402
403 Returns:
404
405 Number of characters printed.
406
407 --*/
408 {
409 UINTN Return;
410 VA_LIST Marker;
411
412 VA_START (Marker, Format);
413 Return = VSPrint (Buffer, BufferSize, Format, Marker);
414 VA_END (Marker);
415
416 return Return;
417 }
418
419 UINTN
420 VSPrint (
421 OUT CHAR_W *StartOfBuffer,
422 IN UINTN BufferSize,
423 IN CONST CHAR_W *FormatString,
424 IN VA_LIST Marker
425 )
426 /*++
427
428 Routine Description:
429
430 VSPrint function to process format and place the results in Buffer. Since a
431 VA_LIST is used this rountine allows the nesting of Vararg routines. Thus
432 this is the main print working routine
433
434 Arguments:
435
436 StartOfBuffer - Unicode buffer to print the results of the parsing of Format into.
437
438 BufferSize - Maximum number of characters to put into buffer. Zero means
439 no limit.
440
441 FormatString - Unicode format string see file header for more details.
442
443 Marker - Vararg list consumed by processing Format.
444
445 Returns:
446
447 Number of characters printed.
448
449 --*/
450 {
451 CHAR16 TempBuffer[CHARACTER_NUMBER_FOR_VALUE];
452 CHAR_W *Buffer;
453 CHAR8 *AsciiStr;
454 CHAR16 *UnicodeStr;
455 CHAR_W *Format;
456 UINTN Index;
457 UINTN Flags;
458 UINTN Width;
459 UINTN Count;
460 UINTN NumberOfCharacters;
461 UINTN BufferLeft;
462 UINT64 Value;
463 EFI_GUID *TmpGUID;
464
465 //
466 // Process the format string. Stop if Buffer is over run.
467 //
468
469 Buffer = StartOfBuffer;
470 Format = (CHAR_W *) FormatString;
471 NumberOfCharacters = BufferSize / sizeof (CHAR_W);
472 BufferLeft = BufferSize;
473 for (Index = 0; (*Format != '\0') && (Index < NumberOfCharacters - 1); Format++) {
474 if (*Format != '%') {
475 if ((*Format == '\n') && (Index < NumberOfCharacters - 2)) {
476 //
477 // If carage return add line feed
478 //
479 Buffer[Index++] = '\r';
480 BufferLeft -= sizeof (CHAR_W);
481 }
482
483 Buffer[Index++] = *Format;
484 BufferLeft -= sizeof (CHAR_W);
485 } else {
486
487 //
488 // Now it's time to parse what follows after %
489 //
490 Format = GetFlagsAndWidth (Format, &Flags, &Width, &Marker);
491 switch (*Format) {
492 case 'X':
493 Flags |= PREFIX_ZERO;
494 Width = sizeof (UINT64) * 2;
495
496 //
497 // break skiped on purpose
498 //
499 case 'x':
500 if ((Flags & LONG_TYPE) == LONG_TYPE) {
501 Value = VA_ARG (Marker, UINT64);
502 } else {
503 Value = VA_ARG (Marker, UINTN);
504 }
505
506 EfiValueToHexStr (TempBuffer, Value, Flags, Width);
507 UnicodeStr = TempBuffer;
508
509 for (; (*UnicodeStr != '\0') && (Index < NumberOfCharacters - 1); UnicodeStr++) {
510 Buffer[Index++] = *UnicodeStr;
511 }
512 break;
513
514 case 'd':
515 if ((Flags & LONG_TYPE) == LONG_TYPE) {
516 Value = VA_ARG (Marker, UINT64);
517 } else {
518 Value = (UINTN) VA_ARG (Marker, UINTN);
519 }
520
521 EfiValueToString (TempBuffer, Value, Flags, Width);
522 UnicodeStr = TempBuffer;
523
524 for (; (*UnicodeStr != '\0') && (Index < NumberOfCharacters - 1); UnicodeStr++) {
525 Buffer[Index++] = *UnicodeStr;
526 }
527 break;
528
529 case 's':
530 case 'S':
531 UnicodeStr = (CHAR16 *) VA_ARG (Marker, CHAR_W *);
532 if (UnicodeStr == NULL) {
533 UnicodeStr = L"<null string>";
534 }
535
536 for (Count = 0; (*UnicodeStr != '\0') && (Index < NumberOfCharacters - 1); UnicodeStr++, Count++) {
537 Buffer[Index++] = *UnicodeStr;
538 }
539 //
540 // Add padding if needed
541 //
542 for (; (Count < Width) && (Index < NumberOfCharacters - 1); Count++) {
543 Buffer[Index++] = ' ';
544 }
545
546 break;
547
548 case 'a':
549 AsciiStr = (CHAR8 *) VA_ARG (Marker, CHAR8 *);
550 if (AsciiStr == NULL) {
551 AsciiStr = "<null string>";
552 }
553
554 for (Count = 0; (*AsciiStr != '\0') && (Index < NumberOfCharacters - 1); AsciiStr++, Count++) {
555 Buffer[Index++] = (CHAR_W) * AsciiStr;
556 }
557 //
558 // Add padding if needed
559 //
560 for (; (Count < Width) && (Index < NumberOfCharacters - 1); Count++) {
561 Buffer[Index++] = ' ';
562 }
563 break;
564
565 case 'c':
566 Buffer[Index++] = (CHAR_W) VA_ARG (Marker, UINTN);
567 break;
568
569 case 'g':
570 TmpGUID = VA_ARG (Marker, EFI_GUID *);
571 if (TmpGUID != NULL) {
572 Index += GuidToString (
573 TmpGUID,
574 &Buffer[Index],
575 BufferLeft
576 );
577 }
578 break;
579
580 case 't':
581 Index += TimeToString (
582 VA_ARG (Marker, EFI_TIME *),
583 &Buffer[Index],
584 BufferLeft
585 );
586 break;
587
588 case 'r':
589 Index += EfiStatusToString (
590 VA_ARG (Marker, EFI_STATUS),
591 &Buffer[Index],
592 BufferLeft
593 );
594 break;
595
596 case '%':
597 Buffer[Index++] = *Format;
598 break;
599
600 default:
601 //
602 // if the type is unknown print it to the screen
603 //
604 Buffer[Index++] = *Format;
605 }
606
607 BufferLeft = BufferSize - Index * sizeof (CHAR_W);
608 }
609 }
610
611 Buffer[Index++] = '\0';
612
613 return &Buffer[Index] - StartOfBuffer;
614 }
615
616 STATIC
617 CHAR_W *
618 GetFlagsAndWidth (
619 IN CHAR_W *Format,
620 OUT UINTN *Flags,
621 OUT UINTN *Width,
622 IN OUT VA_LIST *Marker
623 )
624 /*++
625
626 Routine Description:
627
628 VSPrint worker function that parses flag and width information from the
629 Format string and returns the next index into the Format string that needs
630 to be parsed. See file headed for details of Flag and Width.
631
632 Arguments:
633
634 Format - Current location in the VSPrint format string.
635
636 Flags - Returns flags
637
638 Width - Returns width of element
639
640 Marker - Vararg list that may be paritally consumed and returned.
641
642 Returns:
643
644 Pointer indexed into the Format string for all the information parsed
645 by this routine.
646
647 --*/
648 {
649 UINTN Count;
650 BOOLEAN Done;
651
652 *Flags = 0;
653 *Width = 0;
654 for (Done = FALSE; !Done;) {
655 Format++;
656
657 switch (*Format) {
658
659 case '-':
660 *Flags |= LEFT_JUSTIFY;
661 break;
662
663 case '+':
664 *Flags |= PREFIX_SIGN;
665 break;
666
667 case ' ':
668 *Flags |= PREFIX_BLANK;
669 break;
670
671 case ',':
672 *Flags |= COMMA_TYPE;
673 break;
674
675 case 'L':
676 case 'l':
677 *Flags |= LONG_TYPE;
678 break;
679
680 case '*':
681 *Width = VA_ARG (*Marker, UINTN);
682 break;
683
684 case '0':
685 *Flags |= PREFIX_ZERO;
686
687 case '1':
688 case '2':
689 case '3':
690 case '4':
691 case '5':
692 case '6':
693 case '7':
694 case '8':
695 case '9':
696 Count = 0;
697 do {
698 Count = (Count * 10) +*Format - '0';
699 Format++;
700 } while ((*Format >= '0') && (*Format <= '9'));
701 Format--;
702 *Width = Count;
703 break;
704
705 default:
706 Done = TRUE;
707 }
708 }
709
710 return Format;
711 }
712
713 STATIC
714 UINTN
715 GuidToString (
716 IN EFI_GUID *Guid,
717 IN CHAR_W *Buffer,
718 IN UINTN BufferSize
719 )
720 /*++
721
722 Routine Description:
723
724 VSPrint worker function that prints an EFI_GUID.
725
726 Arguments:
727
728 Guid - Pointer to GUID to print.
729
730 Buffer - Buffe to print Guid into.
731
732 BufferSize - Size of Buffer.
733
734 Returns:
735
736 Number of characters printed.
737
738 --*/
739 {
740 UINTN Size;
741
742 Size = SPrint (
743 Buffer,
744 BufferSize,
745 STRING_W ("%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x"),
746 (UINTN)Guid->Data1,
747 (UINTN)Guid->Data2,
748 (UINTN)Guid->Data3,
749 (UINTN)Guid->Data4[0],
750 (UINTN)Guid->Data4[1],
751 (UINTN)Guid->Data4[2],
752 (UINTN)Guid->Data4[3],
753 (UINTN)Guid->Data4[4],
754 (UINTN)Guid->Data4[5],
755 (UINTN)Guid->Data4[6],
756 (UINTN)Guid->Data4[7]
757 );
758
759 //
760 // SPrint will null terminate the string. The -1 skips the null
761 //
762 return Size - 1;
763 }
764
765
766 STATIC
767 UINTN
768 TimeToString (
769 IN EFI_TIME *Time,
770 OUT CHAR_W *Buffer,
771 IN UINTN BufferSize
772 )
773 /*++
774
775 Routine Description:
776
777 VSPrint worker function that prints EFI_TIME.
778
779 Arguments:
780
781 Time - Pointer to EFI_TIME sturcture to print.
782
783 Buffer - Buffer to print Time into.
784
785 BufferSize - Size of Buffer.
786
787 Returns:
788
789 Number of characters printed.
790
791 --*/
792 {
793 UINTN Size;
794
795 Size = SPrint (
796 Buffer,
797 BufferSize,
798 STRING_W ("%02d/%02d/%04d %02d:%02d"),
799 (UINTN)Time->Month,
800 (UINTN)Time->Day,
801 (UINTN)Time->Year,
802 (UINTN)Time->Hour,
803 (UINTN)Time->Minute
804 );
805
806 //
807 // SPrint will null terminate the string. The -1 skips the null
808 //
809 return Size - 1;
810 }
811
812 STATIC
813 UINTN
814 EfiStatusToString (
815 IN EFI_STATUS Status,
816 OUT CHAR_W *Buffer,
817 IN UINTN BufferSize
818 )
819 /*++
820
821 Routine Description:
822
823 VSPrint worker function that prints EFI_STATUS as a string. If string is
824 not known a hex value will be printed.
825
826 Arguments:
827
828 Status - EFI_STATUS sturcture to print.
829
830 Buffer - Buffer to print EFI_STATUS message string into.
831
832 BufferSize - Size of Buffer.
833
834 Returns:
835
836 Number of characters printed.
837
838 --*/
839 {
840 UINTN Size;
841 CHAR8 *Desc;
842
843 Desc = NULL;
844
845 //
846 // Can't use global Status String Array as UINTN is not constant for EBC
847 //
848 if (Status == EFI_SUCCESS) { Desc = "Success"; } else
849 if (Status == EFI_LOAD_ERROR) { Desc = "Load Error"; } else
850 if (Status == EFI_INVALID_PARAMETER) { Desc = "Invalid Parameter"; } else
851 if (Status == EFI_UNSUPPORTED) { Desc = "Unsupported"; } else
852 if (Status == EFI_BAD_BUFFER_SIZE) { Desc = "Bad Buffer Size"; } else
853 if (Status == EFI_BUFFER_TOO_SMALL) { Desc = "Buffer Too Small"; } else
854 if (Status == EFI_NOT_READY) { Desc = "Not Ready"; } else
855 if (Status == EFI_DEVICE_ERROR) { Desc = "Device Error"; } else
856 if (Status == EFI_WRITE_PROTECTED) { Desc = "Write Protected"; } else
857 if (Status == EFI_OUT_OF_RESOURCES) { Desc = "Out of Resources"; } else
858 if (Status == EFI_VOLUME_CORRUPTED) { Desc = "Volume Corrupt"; } else
859 if (Status == EFI_VOLUME_FULL) { Desc = "Volume Full"; } else
860 if (Status == EFI_NO_MEDIA) { Desc = "No Media"; } else
861 if (Status == EFI_MEDIA_CHANGED) { Desc = "Media changed"; } else
862 if (Status == EFI_NOT_FOUND) { Desc = "Not Found"; } else
863 if (Status == EFI_ACCESS_DENIED) { Desc = "Access Denied"; } else
864 if (Status == EFI_NO_RESPONSE) { Desc = "No Response"; } else
865 if (Status == EFI_NO_MAPPING) { Desc = "No mapping"; } else
866 if (Status == EFI_TIMEOUT) { Desc = "Time out"; } else
867 if (Status == EFI_NOT_STARTED) { Desc = "Not started"; } else
868 if (Status == EFI_ALREADY_STARTED) { Desc = "Already started"; } else
869 if (Status == EFI_ABORTED) { Desc = "Aborted"; } else
870 if (Status == EFI_ICMP_ERROR) { Desc = "ICMP Error"; } else
871 if (Status == EFI_TFTP_ERROR) { Desc = "TFTP Error"; } else
872 if (Status == EFI_PROTOCOL_ERROR) { Desc = "Protocol Error"; } else
873 if (Status == EFI_WARN_UNKNOWN_GLYPH) { Desc = "Warning Unknown Glyph"; } else
874 if (Status == EFI_WARN_DELETE_FAILURE) { Desc = "Warning Delete Failure"; } else
875 if (Status == EFI_WARN_WRITE_FAILURE) { Desc = "Warning Write Failure"; } else
876 if (Status == EFI_WARN_BUFFER_TOO_SMALL) { Desc = "Warning Buffer Too Small"; }
877
878 //
879 // If we found a match, copy the message to the user's buffer. Otherwise
880 // sprint the hex status code to their buffer.
881 //
882 if (Desc != NULL) {
883 Size = SPrint (Buffer, BufferSize, STRING_W ("%a"), Desc);
884 } else {
885 Size = SPrint (Buffer, BufferSize, STRING_W ("%X"), Status);
886 }
887
888 return Size - 1;
889 }