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