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