1440f8f127f0c61eb44273b7e56901a3503e99f0
[mirror_edk2.git] / MdePkg / Library / BaseDebugLibNull / DebugLib.c
1 /** @file
2 Base Debug Library that uses PrintLib to print messages to a memory buffer.
3
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 //
16 // Define the maximum debug and assert message length that this library supports
17 //
18 #define MAX_DEBUG_MESSAGE_LENGTH 0x100
19
20 /**
21
22 Prints a debug message to the debug output device if the specified error level is enabled.
23
24 If any bit in ErrorLevel is also set in PcdDebugPrintErrorLevel, then print
25 the message specified by Format and the associated variable argument list to
26 the debug output device.
27
28 If Format is NULL, then ASSERT().
29
30 @param ErrorLevel The error level of the debug message.
31 @param Format Format string for the debug message to print.
32
33 **/
34 VOID
35 EFIAPI
36 DebugPrint (
37 IN UINTN ErrorLevel,
38 IN CHAR8 *Format,
39 ...
40 )
41 {
42 CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH];
43 VA_LIST Marker;
44
45 //
46 // If Format is NULL, then ASSERT().
47 //
48 ASSERT (Format != NULL);
49
50 //
51 // Print the assert message to a buffer
52 //
53 VA_START (Marker, Format);
54 AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker);
55 VA_END (Marker);
56 }
57
58
59 /**
60
61 Prints an assert message containing a filename, line number, and description.
62 This may be followed by a breakpoint or a dead loop.
63
64 Print a message of the form \93ASSERT <FileName>(<LineNumber>): <Description>\n\94
65 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
66 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if
67 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then
68 CpuDeadLoop() is called. If neither of these bits are set, then this function
69 returns immediately after the message is printed to the debug output device.
70 DebugAssert() must actively prevent recusrsion. If DebugAssert() is called while
71 processing another DebugAssert(), then DebugAssert() must return immediately.
72
73 If FileName is NULL, then a <FileName> string of \93(NULL) Filename\94 is printed.
74
75 If Description is NULL, then a <Description> string of \93(NULL) Description\94 is printed.
76
77 @param FileName Pointer to the name of the source file that generated the assert condition.
78 @param LineNumber The line number in the source file that generated the assert condition
79 @param Description Pointer to the description of the assert condition.
80
81 **/
82 VOID
83 EFIAPI
84 DebugAssert (
85 IN CHAR8 *FileName,
86 IN INTN LineNumber,
87 IN CHAR8 *Description
88 )
89 {
90 CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH];
91
92 //
93 // Print the assert message to a buffer
94 //
95 AsciiSPrint (Buffer, sizeof (Buffer), "ASSERT %s(%d): %s\n", FileName, LineNumber, Description);
96
97 //
98 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings
99 //
100 if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {
101 CpuBreakpoint ();
102 } else if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {
103 CpuDeadLoop ();
104 }
105 }
106
107
108 /**
109
110 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.
111
112 This function fills Length bytes of Buffer with the value specified by
113 PcdDebugClearMemoryValue, and returns Buffer.
114
115 If Buffer is NULL, then ASSERT().
116
117 If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT().
118
119 @param Buffer Pointer to the target buffer to fill with PcdDebugClearMemoryValue.
120 @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
121
122 @return Buffer
123
124 **/
125 VOID *
126 EFIAPI
127 DebugClearMemory (
128 OUT VOID *Buffer,
129 IN UINTN Length
130 )
131 {
132 //
133 // If Buffer is NULL, then ASSERT().
134 //
135 ASSERT (Buffer != NULL);
136
137 //
138 // SetMem() checks for the the ASSERT() condition on Length and returns Buffer
139 //
140 return SetMem (Buffer, Length, PcdGet8(PcdDebugClearMemoryValue));
141 }
142
143
144 /**
145
146 Returns TRUE if ASSERT() macros are enabled.
147
148 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
149 PcdDebugProperyMask is set. Otherwise FALSE is returned.
150
151 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.
152 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.
153
154 **/
155 BOOLEAN
156 EFIAPI
157 DebugAssertEnabled (
158 VOID
159 )
160 {
161 return ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);
162 }
163
164
165 /**
166
167 Returns TRUE if DEBUG()macros are enabled.
168
169 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
170 PcdDebugProperyMask is set. Otherwise FALSE is returned.
171
172 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.
173 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.
174
175 **/
176 BOOLEAN
177 EFIAPI
178 DebugPrintEnabled (
179 VOID
180 )
181 {
182 return ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);
183 }
184
185
186 /**
187
188 Returns TRUE if DEBUG_CODE()macros are enabled.
189
190 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
191 PcdDebugProperyMask is set. Otherwise FALSE is returned.
192
193 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.
194 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.
195
196 **/
197 BOOLEAN
198 EFIAPI
199 DebugCodeEnabled (
200 VOID
201 )
202 {
203 return ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);
204 }
205
206
207 /**
208
209 Returns TRUE if DEBUG_CLEAR_MEMORY()macro is enabled.
210
211 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of
212 PcdDebugProperyMask is set. Otherwise FALSE is returned.
213
214 @retval TRUE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.
215 @retval FALSE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.
216
217 **/
218 BOOLEAN
219 EFIAPI
220 DebugClearMemoryEnabled (
221 VOID
222 )
223 {
224 return ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);
225 }