]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseDebugLibSerialPort/DebugLib.c
wrong comment for "Unicode" string.
[mirror_edk2.git] / MdePkg / Library / BaseDebugLibSerialPort / DebugLib.c
1 /** @file
2 Base Debug library instance base on Serial Port library.
3 It uses PrintLib to send debug messages to serial port device.
4
5 Copyright (c) 2006 - 2008, Intel Corporation<BR>
6 All rights reserved. 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
10
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.
13
14 **/
15
16 #include <Base.h>
17 #include <Library/DebugLib.h>
18 #include <Library/BaseLib.h>
19 #include <Library/PrintLib.h>
20 #include <Library/PcdLib.h>
21 #include <Library/BaseMemoryLib.h>
22 #include <Library/SerialPortLib.h>
23
24
25 //
26 // Define the maximum debug and assert message length that this library supports
27 //
28 #define MAX_DEBUG_MESSAGE_LENGTH 0x100
29
30
31 /**
32 Prints a debug message to the debug output device if the specified error level is enabled.
33
34 If any bit in ErrorLevel is also set in PcdDebugPrintErrorLevel, then print
35 the message specified by Format and the associated variable argument list to
36 the debug output device.
37
38 If Format is NULL, then ASSERT().
39
40 @param ErrorLevel The error level of the debug message.
41 @param Format Format string for the debug message to print.
42 @param ... The variable argument list.
43
44 **/
45 VOID
46 EFIAPI
47 DebugPrint (
48 IN UINTN ErrorLevel,
49 IN CONST CHAR8 *Format,
50 ...
51 )
52 {
53 CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH];
54 VA_LIST Marker;
55
56 //
57 // If Format is NULL, then ASSERT().
58 //
59 ASSERT (Format != NULL);
60
61 //
62 // Check driver debug mask value and global mask
63 //
64 if ((ErrorLevel & PcdGet32(PcdDebugPrintErrorLevel)) == 0) {
65 return;
66 }
67
68 //
69 // Convert the DEBUG() message to an ASCII String
70 //
71 VA_START (Marker, Format);
72 AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker);
73 VA_END (Marker);
74
75 //
76 // Send the print string to a Serial Port
77 //
78 SerialPortWrite ((UINT8 *) Buffer, AsciiStrLen(Buffer));
79 }
80
81
82 /**
83 Prints an assert message containing a filename, line number, and description.
84 This may be followed by a breakpoint or a dead loop.
85
86 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"
87 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
88 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if
89 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then
90 CpuDeadLoop() is called. If neither of these bits are set, then this function
91 returns immediately after the message is printed to the debug output device.
92 DebugAssert() must actively prevent recusrsion. If DebugAssert() is called while
93 processing another DebugAssert(), then DebugAssert() must return immediately.
94
95 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.
96
97 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.
98
99 @param FileName Pointer to the name of the source file that generated the assert condition.
100 @param LineNumber The line number in the source file that generated the assert condition
101 @param Description Pointer to the description of the assert condition.
102
103 **/
104 VOID
105 EFIAPI
106 DebugAssert (
107 IN CONST CHAR8 *FileName,
108 IN UINTN LineNumber,
109 IN CONST CHAR8 *Description
110 )
111 {
112 CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH];
113
114 //
115 // Generate the ASSERT() message in Ascii format
116 //
117 AsciiSPrint (Buffer, sizeof (Buffer), "ASSERT %a(%d): %a\n", FileName, LineNumber, Description);
118
119 //
120 // Send the print string to the Console Output device
121 //
122 SerialPortWrite ((UINT8 *) Buffer, AsciiStrLen(Buffer));
123
124 //
125 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings
126 //
127 if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {
128 CpuBreakpoint ();
129 } else if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {
130 CpuDeadLoop ();
131 }
132 }
133
134
135 /**
136 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.
137
138 This function fills Length bytes of Buffer with the value specified by
139 PcdDebugClearMemoryValue, and returns Buffer.
140
141 If Buffer is NULL, then ASSERT().
142
143 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
144
145 @param Buffer Pointer to the target buffer to be filled with PcdDebugClearMemoryValue.
146 @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
147
148 @return Buffer filled with PcdDebugClearMemoryValue.
149
150 **/
151 VOID *
152 EFIAPI
153 DebugClearMemory (
154 OUT VOID *Buffer,
155 IN UINTN Length
156 )
157 {
158 //
159 // If Buffer is NULL, then ASSERT().
160 //
161 ASSERT (Buffer != NULL);
162
163 //
164 // SetMem() checks for the the ASSERT() condition on Length and returns Buffer
165 //
166 return SetMem (Buffer, Length, PcdGet8(PcdDebugClearMemoryValue));
167 }
168
169
170 /**
171 Returns TRUE if ASSERT() macros are enabled.
172
173 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
174 PcdDebugProperyMask is set. Otherwise FALSE is returned.
175
176 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.
177 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.
178
179 **/
180 BOOLEAN
181 EFIAPI
182 DebugAssertEnabled (
183 VOID
184 )
185 {
186 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);
187 }
188
189
190 /**
191 Returns TRUE if the DEBUG() macro is enabled.
192
193 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
194 PcdDebugProperyMask is set. Otherwise FALSE is returned.
195
196 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.
197 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.
198
199 **/
200 BOOLEAN
201 EFIAPI
202 DebugPrintEnabled (
203 VOID
204 )
205 {
206 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);
207 }
208
209
210 /**
211 Returns TRUE if the DEBUG_CODE() macros are enabled.
212
213 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
214 PcdDebugProperyMask is set. Otherwise FALSE is returned.
215
216 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.
217 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.
218
219 **/
220 BOOLEAN
221 EFIAPI
222 DebugCodeEnabled (
223 VOID
224 )
225 {
226 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);
227 }
228
229
230 /**
231 Returns TRUE if the DEBUG_CLEAR_MEMORY() macro is enabled.
232
233 This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of
234 PcdDebugProperyMask is set. Otherwise FALSE is returned.
235
236 @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.
237 @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.
238
239 **/
240 BOOLEAN
241 EFIAPI
242 DebugClearMemoryEnabled (
243 VOID
244 )
245 {
246 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);
247 }