]> git.proxmox.com Git - mirror_edk2.git/blob - DuetPkg/EfiLdr/Debug.c
DuetPkg: Move EfiLdr Handoff data to stack
[mirror_edk2.git] / DuetPkg / EfiLdr / Debug.c
1 /*++
2
3 Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
4 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 Debug.c
14
15 Abstract:
16
17 Revision History:
18
19 --*/
20 #include "EfiLdr.h"
21 #include "Debug.h"
22 #include <Library/SerialPortLib.h>
23
24 UINT8 *mCursor;
25 UINT8 mHeaderIndex = 10;
26
27 VOID
28 PrintHeader (
29 CHAR8 Char
30 )
31 {
32 *(UINT8 *)(UINTN)(0x000b8000 + mHeaderIndex) = Char;
33 mHeaderIndex += 2;
34 }
35
36 VOID
37 ClearScreen (
38 VOID
39 )
40 {
41 UINT32 Index;
42
43 mCursor = (UINT8 *)(UINTN)(0x000b8000 + 160);
44 for (Index = 0; Index < 80 * 49; Index++) {
45 *mCursor = ' ';
46 mCursor += 2;
47 }
48 mCursor = (UINT8 *)(UINTN)(0x000b8000 + 160);
49 }
50
51
52 VOID
53 PrintU32Base10 (
54 UINT32 Value
55 )
56 {
57 UINT32 Index;
58 CHAR8 Char;
59 CHAR8 String[11];
60 UINTN StringPos;
61 UINT32 B10Div;
62
63 B10Div = 1000000000;
64 for (Index = 0, StringPos = 0; Index < 10; Index++) {
65 Char = ((Value / B10Div) % 10) + '0';
66 if ((StringPos > 0) || (Char != '0')) {
67 String[StringPos] = Char;
68 StringPos++;
69 }
70 B10Div = B10Div / 10;
71 }
72
73 if (StringPos == 0) {
74 String[0] = '0';
75 StringPos++;
76 }
77
78 String[StringPos] = '\0';
79
80 PrintString (String);
81 }
82
83
84 VOID
85 PrintValue (
86 UINT32 Value
87 )
88 {
89 UINT32 Index;
90 CHAR8 Char;
91 CHAR8 String[9];
92
93 for (Index = 0; Index < 8; Index++) {
94 Char = (UINT8)(((Value >> ((7 - Index) * 4)) & 0x0f) + '0');
95 if (Char > '9') {
96 Char = (UINT8) (Char - '0' - 10 + 'A');
97 }
98 String[Index] = Char;
99 }
100
101 String[sizeof (String) - 1] = '\0';
102
103 PrintString (String);
104 }
105
106 VOID
107 PrintValue64 (
108 UINT64 Value
109 )
110 {
111 PrintValue ((UINT32) RShiftU64 (Value, 32));
112 PrintValue ((UINT32) Value);
113 }
114
115 VOID
116 PrintString (
117 CHAR8 *String
118 )
119 {
120 UINT32 Index;
121
122 for (Index = 0; String[Index] != 0; Index++) {
123 if (String[Index] == '\n') {
124 mCursor = (UINT8 *)(UINTN)(0xb8000 + (((((UINTN)mCursor - 0xb8000) + 160) / 160) * 160));
125 } else {
126 *mCursor = String[Index];
127 mCursor += 2;
128 }
129 }
130
131 //
132 // All information also output to serial port.
133 //
134 SerialPortWrite ((UINT8*) String, Index);
135 }
136