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