TianoCore EDK2 master
Loading...
Searching...
No Matches
AmlDbgPrint.c
Go to the documentation of this file.
1
10#include <AmlNodeDefines.h>
12
13#include <AmlCoreInterface.h>
14#include <String/AmlString.h>
15#include <Tree/AmlNode.h>
17
18#if !defined (MDEPKG_NDEBUG)
19
23 "EAmlNodeDataTypeNone",
24 "EAmlNodeDataTypeReserved1",
25 "EAmlNodeDataTypeReserved2",
26 "EAmlNodeDataTypeReserved3",
27 "EAmlNodeDataTypeReserved4",
28 "EAmlNodeDataTypeReserved5",
29 "EAmlNodeDataTypeNameString",
30 "EAmlNodeDataTypeString",
31 "EAmlNodeDataTypeUInt",
32 "EAmlNodeDataTypeRaw",
33 "EAmlNodeDataTypeResourceData",
34 "EAmlNodeDataTypeFieldPkgLen",
35 "EAmlNodeDataTypeMax"
36};
37
41 "EAmlNodeUnknown",
42 "EAmlNodeRoot",
43 "EAmlNodeObject",
44 "EAmlNodeData",
45 "EAmlNodeMax"
46};
47
54VOID
55EFIAPI
57 IN UINT32 ErrorLevel,
58 IN CONST CHAR8 *Buffer,
59 IN UINT32 Size
60 )
61{
62 UINT32 i;
63
64 if (Buffer == NULL) {
65 ASSERT (0);
66 return;
67 }
68
69 for (i = 0; i < Size; i++) {
70 DEBUG ((ErrorLevel, "%c", Buffer[i]));
71 }
72}
73
79VOID
80EFIAPI
82 IN CONST CHAR8 *Buffer
83 )
84{
85 if (Buffer == NULL) {
86 ASSERT (0);
87 return;
88 }
89
90 DEBUG ((DEBUG_INFO, "%c", Buffer[0]));
91 if ((Buffer[1] == AML_NAME_CHAR__) &&
92 (Buffer[2] == AML_NAME_CHAR__) &&
93 (Buffer[3] == AML_NAME_CHAR__))
94 {
95 return;
96 }
97
98 DEBUG ((DEBUG_INFO, "%c", Buffer[1]));
99 if ((Buffer[2] == AML_NAME_CHAR__) &&
100 (Buffer[3] == AML_NAME_CHAR__))
101 {
102 return;
103 }
104
105 DEBUG ((DEBUG_INFO, "%c", Buffer[2]));
106 if (Buffer[3] == AML_NAME_CHAR__) {
107 return;
108 }
109
110 DEBUG ((DEBUG_INFO, "%c", Buffer[3]));
111 return;
112}
113
119VOID
120EFIAPI
122 IN CONST CHAR8 *Buffer,
123 IN BOOLEAN NewLine
124 )
125{
126 UINT8 SegCount;
127 UINT8 Index;
128
129 if (Buffer == NULL) {
130 ASSERT (0);
131 return;
132 }
133
134 // Handle Root and Parent(s).
135 if (*Buffer == AML_ROOT_CHAR) {
136 Buffer++;
137 DEBUG ((DEBUG_INFO, "\\"));
138 } else if (*Buffer == AML_PARENT_PREFIX_CHAR) {
139 do {
140 Buffer++;
141 DEBUG ((DEBUG_INFO, "^"));
142 } while (*Buffer == AML_PARENT_PREFIX_CHAR);
143 }
144
145 // Handle SegCount(s).
146 if (*Buffer == AML_DUAL_NAME_PREFIX) {
147 Buffer++;
148 SegCount = 2;
149 } else if (*Buffer == AML_MULTI_NAME_PREFIX) {
150 Buffer++;
151 // For multi name prefix the seg count is in the second byte.
152 SegCount = *Buffer;
153 Buffer++;
154 } else if (AmlIsLeadNameChar (*Buffer)) {
155 // Only check the first char first to avoid overflow.
156 // Then the whole NameSeg can be checked.
157 if (!AmlIsNameSeg (Buffer)) {
158 ASSERT (0);
159 return;
160 }
161
162 SegCount = 1;
163 } else if (*Buffer == AML_ZERO_OP) {
164 SegCount = 0;
165 } else {
166 // Should not be possible.
167 ASSERT (0);
168 return;
169 }
170
171 if (SegCount != 0) {
172 AMLDBG_PRINT_NAMESEG (Buffer);
173 Buffer += AML_NAME_SEG_SIZE;
174 for (Index = 0; Index < SegCount - 1; Index++) {
175 DEBUG ((DEBUG_INFO, "."));
176 AMLDBG_PRINT_NAMESEG (Buffer);
177 Buffer += AML_NAME_SEG_SIZE;
178 }
179 }
180
181 if (NewLine) {
182 DEBUG ((DEBUG_INFO, "\n"));
183 }
184
185 return;
186}
187
193STATIC
194VOID
195EFIAPI
197 IN AML_NODE_HEADER *Node,
198 IN UINT8 Level
199 )
200{
201 if (!IS_AML_NODE_VALID (Node)) {
202 ASSERT (0);
203 return;
204 }
205
206 DEBUG ((
207 DEBUG_INFO,
208 "%3d | %-15a | ",
209 Level,
210 NodeTypeStrTbl[Node->NodeType]
211 ));
212}
213
219STATIC
220VOID
221EFIAPI
223 IN AML_DATA_NODE *DataNode,
224 IN UINT8 Level
225 )
226{
227 UINT32 Idx;
228
229 if (!IS_AML_DATA_NODE (DataNode)) {
230 ASSERT (0);
231 return;
232 }
233
234 AmlDbgPrintNodeHeader ((AML_NODE_HEADER *)DataNode, Level);
235
236 DEBUG ((DEBUG_INFO, "%-36a | ", NodeDataTypeStrTbl[DataNode->DataType]));
237 DEBUG ((DEBUG_INFO, "0x%04x | ", DataNode->Size));
238
239 if ((DataNode->DataType == EAmlNodeDataTypeNameString) ||
240 (DataNode->DataType == EAmlNodeDataTypeString))
241 {
242 AMLDBG_PRINT_CHARS (
243 DEBUG_INFO,
244 (CONST CHAR8 *)DataNode->Buffer,
245 DataNode->Size
246 );
247 } else if (DataNode->DataType == EAmlNodeDataTypeUInt) {
248 switch (DataNode->Size) {
249 case 1:
250 {
251 DEBUG ((DEBUG_INFO, "0x%0x", *((UINT8 *)DataNode->Buffer)));
252 break;
253 }
254 case 2:
255 {
256 DEBUG ((DEBUG_INFO, "0x%0x", *((UINT16 *)DataNode->Buffer)));
257 break;
258 }
259 case 4:
260 {
261 DEBUG ((DEBUG_INFO, "0x%0lx", *((UINT32 *)DataNode->Buffer)));
262 break;
263 }
264 case 8:
265 {
266 DEBUG ((DEBUG_INFO, "0x%0llx", *((UINT64 *)DataNode->Buffer)));
267 break;
268 }
269 default:
270 {
271 ASSERT (0);
272 return;
273 }
274 }
275 } else {
276 // No specific format.
277 for (Idx = 0; Idx < DataNode->Size; Idx++) {
278 DEBUG ((DEBUG_INFO, "%02x ", DataNode->Buffer[Idx]));
279 }
280 }
281
282 DEBUG ((DEBUG_INFO, "\n"));
283}
284
290STATIC
291VOID
292EFIAPI
294 IN AML_OBJECT_NODE *ObjectNode,
295 IN UINT8 Level
296 )
297{
298 if (!IS_AML_OBJECT_NODE (ObjectNode)) {
299 ASSERT (0);
300 return;
301 }
302
303 AmlDbgPrintNodeHeader ((AML_NODE_HEADER *)ObjectNode, Level);
304
305 DEBUG ((DEBUG_INFO, "0x%02x | ", ObjectNode->AmlByteEncoding->OpCode));
306 DEBUG ((DEBUG_INFO, "0x%02x | ", ObjectNode->AmlByteEncoding->SubOpCode));
307
308 // Print a string corresponding to the field object OpCode/SubOpCode.
309 if (AmlNodeHasAttribute (ObjectNode, AML_IS_FIELD_ELEMENT)) {
310 DEBUG ((
311 DEBUG_INFO,
312 "%-15a ",
314 ObjectNode->AmlByteEncoding->OpCode,
315 0
316 )
317 ));
318 } else {
319 // Print a string corresponding to the object OpCode/SubOpCode.
320 DEBUG ((
321 DEBUG_INFO,
322 "%-15a | ",
324 ObjectNode->AmlByteEncoding->OpCode,
325 ObjectNode->AmlByteEncoding->SubOpCode
326 )
327 ));
328 }
329
330 DEBUG ((DEBUG_INFO, "%3d | ", ObjectNode->AmlByteEncoding->MaxIndex));
331 DEBUG ((DEBUG_INFO, "0x%08x | ", ObjectNode->AmlByteEncoding->Attribute));
332 DEBUG ((DEBUG_INFO, "0x%04x | ", ObjectNode->PkgLen));
333 if (AmlNodeHasAttribute (ObjectNode, AML_IN_NAMESPACE)) {
334 AMLDBG_PRINT_NAMESTR (
335 AmlNodeGetName ((CONST AML_OBJECT_NODE *)ObjectNode),
336 FALSE
337 );
338 }
339
340 DEBUG ((DEBUG_INFO, "\n"));
341}
342
348STATIC
349VOID
350EFIAPI
352 IN AML_ROOT_NODE *RootNode,
353 IN UINT8 Level
354 )
355{
356 if (!IS_AML_ROOT_NODE (RootNode)) {
357 ASSERT (0);
358 return;
359 }
360
361 AmlDbgPrintNodeHeader ((AML_NODE_HEADER *)RootNode, Level);
362
363 DEBUG ((DEBUG_INFO, "%8x | ", RootNode->SdtHeader->Signature));
364 DEBUG ((DEBUG_INFO, "0x%08x | ", RootNode->SdtHeader->Length));
365 DEBUG ((DEBUG_INFO, "%3d | ", RootNode->SdtHeader->Revision));
366 DEBUG ((DEBUG_INFO, "0x%02x | ", RootNode->SdtHeader->Checksum));
367 DEBUG ((
368 DEBUG_INFO,
369 "%c%c%c%c%c%c | ",
370 RootNode->SdtHeader->OemId[0],
371 RootNode->SdtHeader->OemId[1],
372 RootNode->SdtHeader->OemId[2],
373 RootNode->SdtHeader->OemId[3],
374 RootNode->SdtHeader->OemId[4],
375 RootNode->SdtHeader->OemId[5]
376 ));
377 DEBUG ((DEBUG_INFO, "%-16llx | ", RootNode->SdtHeader->OemTableId));
378 DEBUG ((DEBUG_INFO, "%8x | ", RootNode->SdtHeader->OemRevision));
379 DEBUG ((DEBUG_INFO, "%8x | ", RootNode->SdtHeader->CreatorId));
380 DEBUG ((DEBUG_INFO, "%8x", RootNode->SdtHeader->CreatorRevision));
381 DEBUG ((DEBUG_INFO, "\n"));
382}
383
386STATIC
387VOID
388EFIAPI
390 VOID
391 )
392{
393 DEBUG ((DEBUG_INFO, "Lvl | Node Type |\n"));
394 DEBUG ((
395 DEBUG_INFO,
396 " | %-15a | Signature| Length | Rev | CSum | OemId | "
397 "OemTableId | OemRev | CreatorId| CreatorRev\n",
399 ));
400 DEBUG ((
401 DEBUG_INFO,
402 " | %-15a | Op | SubOp| OpName | MaxI| Attribute | "
403 "PkgLen | NodeName (opt)\n",
405 ));
406 DEBUG ((
407 DEBUG_INFO,
408 " | %-15a | Data Type | Size | "
409 "Buffer\n",
411 ));
412 DEBUG ((
413 DEBUG_INFO,
414 "---------------------------------------"
415 "---------------------------------------\n"
416 ));
417}
418
427STATIC
428VOID
429EFIAPI
431 IN AML_NODE_HEADER *Node,
432 IN BOOLEAN Recurse,
433 IN UINT8 Level
434 )
435{
436 AML_NODE_HEADER *ChildNode;
437
438 if (!IS_AML_NODE_VALID (Node)) {
439 ASSERT (0);
440 return;
441 }
442
443 if (IS_AML_DATA_NODE (Node)) {
444 AmlDbgPrintDataNode ((AML_DATA_NODE *)Node, Level);
445 return;
446 } else if (IS_AML_OBJECT_NODE (Node)) {
447 AmlDbgPrintObjectNode ((AML_OBJECT_NODE *)Node, Level);
448 } else if (IS_AML_ROOT_NODE (Node)) {
449 AmlDbgPrintRootNode ((AML_ROOT_NODE *)Node, Level);
450 } else {
451 // Should not be possible.
452 ASSERT (0);
453 return;
454 }
455
456 if (!Recurse) {
457 return;
458 }
459
460 // Get the first child node.
461 ChildNode = AmlGetNextSibling (Node, NULL);
462 while (ChildNode != NULL) {
463 ASSERT (Level < MAX_UINT8);
464 AmlDbgPrintTreeInternal (ChildNode, Recurse, (UINT8)(Level + 1));
465 ChildNode = AmlGetNextSibling (Node, ChildNode);
466 }
467}
468
474VOID
475EFIAPI
477 IN AML_NODE_HEADER *Node
478 )
479{
482}
483
489VOID
490EFIAPI
492 IN AML_NODE_HEADER *Node
493 )
494{
496 AmlDbgPrintTreeInternal (Node, TRUE, 0);
497}
498
504VOID
505EFIAPI
507 IN CONST UINT8 *Ptr,
508 IN UINT32 Length
509 )
510{
511 UINT32 ByteCount;
512 UINT32 PartLineChars;
513 UINT32 AsciiBufferIndex;
514 CHAR8 AsciiBuffer[17];
515
516 ByteCount = 0;
517 AsciiBufferIndex = 0;
518
519 DEBUG ((DEBUG_VERBOSE, "Address : 0x%p\n", Ptr));
520 DEBUG ((DEBUG_VERBOSE, "Length : %lld", Length));
521
522 while (ByteCount < Length) {
523 if ((ByteCount & 0x0F) == 0) {
524 AsciiBuffer[AsciiBufferIndex] = '\0';
525 DEBUG ((DEBUG_VERBOSE, " %a\n%08X : ", AsciiBuffer, ByteCount));
526 AsciiBufferIndex = 0;
527 } else if ((ByteCount & 0x07) == 0) {
528 DEBUG ((DEBUG_VERBOSE, "- "));
529 }
530
531 if ((*Ptr >= ' ') && (*Ptr < 0x7F)) {
532 AsciiBuffer[AsciiBufferIndex++] = *Ptr;
533 } else {
534 AsciiBuffer[AsciiBufferIndex++] = '.';
535 }
536
537 DEBUG ((DEBUG_VERBOSE, "%02X ", *Ptr++));
538
539 ByteCount++;
540 }
541
542 // Justify the final line using spaces before printing
543 // the ASCII data.
544 PartLineChars = (Length & 0x0F);
545 if (PartLineChars != 0) {
546 PartLineChars = 48 - (PartLineChars * 3);
547 if ((Length & 0x0F) <= 8) {
548 PartLineChars += 2;
549 }
550
551 while (PartLineChars > 0) {
552 DEBUG ((DEBUG_VERBOSE, " "));
553 PartLineChars--;
554 }
555 }
556
557 // Print ASCII data for the final line.
558 AsciiBuffer[AsciiBufferIndex] = '\0';
559 DEBUG ((DEBUG_VERBOSE, " %a\n\n", AsciiBuffer));
560}
561
562#endif // MDEPKG_NDEBUG
#define AML_IS_FIELD_ELEMENT
Definition: Aml.h:93
#define AML_IN_NAMESPACE
Definition: Aml.h:98
STATIC VOID EFIAPI AmlDbgPrintTableHeader(VOID)
Definition: AmlDbgPrint.c:389
VOID EFIAPI AmlDbgPrintNameString(IN CONST CHAR8 *Buffer, IN BOOLEAN NewLine)
Definition: AmlDbgPrint.c:121
STATIC VOID EFIAPI AmlDbgPrintNodeHeader(IN AML_NODE_HEADER *Node, IN UINT8 Level)
Definition: AmlDbgPrint.c:196
STATIC VOID EFIAPI AmlDbgPrintTreeInternal(IN AML_NODE_HEADER *Node, IN BOOLEAN Recurse, IN UINT8 Level)
Definition: AmlDbgPrint.c:430
VOID EFIAPI AmlDbgPrintNameSeg(IN CONST CHAR8 *Buffer)
Definition: AmlDbgPrint.c:81
STATIC VOID EFIAPI AmlDbgPrintRootNode(IN AML_ROOT_NODE *RootNode, IN UINT8 Level)
Definition: AmlDbgPrint.c:351
VOID EFIAPI AmlDbgDumpRaw(IN CONST UINT8 *Ptr, IN UINT32 Length)
Definition: AmlDbgPrint.c:506
VOID EFIAPI AmlDbgPrintNode(IN AML_NODE_HEADER *Node)
Definition: AmlDbgPrint.c:476
CONST CHAR8 * NodeDataTypeStrTbl[]
Definition: AmlDbgPrint.c:22
STATIC VOID EFIAPI AmlDbgPrintDataNode(IN AML_DATA_NODE *DataNode, IN UINT8 Level)
Definition: AmlDbgPrint.c:222
VOID EFIAPI AmlDbgPrintTree(IN AML_NODE_HEADER *Node)
Definition: AmlDbgPrint.c:491
CONST CHAR8 * NodeTypeStrTbl[]
Definition: AmlDbgPrint.c:40
STATIC VOID EFIAPI AmlDbgPrintObjectNode(IN AML_OBJECT_NODE *ObjectNode, IN UINT8 Level)
Definition: AmlDbgPrint.c:293
BOOLEAN EFIAPI AmlNodeHasAttribute(IN CONST AML_OBJECT_NODE *ObjectNode, IN AML_OP_ATTRIBUTE Attribute)
Definition: AmlNode.c:430
CHAR8 *EFIAPI AmlNodeGetName(IN CONST AML_OBJECT_NODE *ObjectNode)
Definition: AmlNode.c:663
#define IS_AML_ROOT_NODE(Node)
#define IS_AML_OBJECT_NODE(Node)
#define IS_AML_DATA_NODE(Node)
#define IS_AML_NODE_VALID(Node)
AML_NODE_HEADER *EFIAPI AmlGetNextSibling(IN CONST AML_NODE_HEADER *Node, IN CONST AML_NODE_HEADER *ChildNode)
CONST CHAR8 * AmlGetOpCodeStr(IN UINT8 OpCode, IN UINT8 SubOpCode)
Definition: Aml.c:470
CONST CHAR8 * AmlGetFieldOpCodeStr(IN UINT8 OpCode, IN UINT8 SubOpCode)
Definition: Aml.c:504
BOOLEAN EFIAPI AmlIsLeadNameChar(IN CHAR8 Ch)
Definition: AmlString.c:144
BOOLEAN EFIAPI AmlIsNameSeg(IN CONST CHAR8 *AmlBuffer)
Definition: AmlString.c:244
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define DEBUG(Expression)
Definition: DebugLib.h:434
VOID EFIAPI AmlDbgPrintChars(IN UINT32 ErrorLevel, IN CONST CHAR8 *Buffer, IN UINT32 Size)
Definition: AmlDbgPrint.c:56
@ EAmlNodeData
Definition: AmlDefines.h:176
@ EAmlNodeRoot
AML Root Node, typically represents a DefinitionBlock.
Definition: AmlDefines.h:173
@ EAmlNodeObject
Definition: AmlDefines.h:174
@ EAmlNodeDataTypeString
EAmlString, NULL terminated string.
Definition: AmlDefines.h:40
@ EAmlNodeDataTypeUInt
Definition: AmlDefines.h:41
@ EAmlNodeDataTypeNameString
Definition: AmlDefines.h:37