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