1 /*******************************************************************************
3 * Module Name: dmbuffer - AML disassembler, buffer and string support
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2013, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
52 #ifdef ACPI_DISASSEMBLER
54 #define _COMPONENT ACPI_CA_DEBUGGER
55 ACPI_MODULE_NAME ("dmbuffer")
57 /* Local prototypes */
61 ACPI_PARSE_OBJECT
*Op
);
64 AcpiDmIsEisaIdElement (
65 ACPI_PARSE_OBJECT
*Op
);
74 /*******************************************************************************
76 * FUNCTION: AcpiDmDisasmByteList
78 * PARAMETERS: Level - Current source code indentation level
79 * ByteData - Pointer to the byte list
80 * ByteCount - Length of the byte list
84 * DESCRIPTION: Dump an AML "ByteList" in Hex format. 8 bytes per line, prefixed
85 * with the hex buffer offset.
87 ******************************************************************************/
90 AcpiDmDisasmByteList (
103 /* Dump the byte list */
105 for (i
= 0; i
< ByteCount
; i
++)
107 /* New line every 8 bytes */
109 if (((i
% 8) == 0) && (i
< ByteCount
))
116 AcpiDmIndent (Level
);
119 AcpiOsPrintf ("/* %04X */ ", i
);
123 AcpiOsPrintf (" 0x%2.2X", (UINT32
) ByteData
[i
]);
125 /* Add comma if there are more bytes to display */
127 if (i
< (ByteCount
-1))
140 /*******************************************************************************
142 * FUNCTION: AcpiDmByteList
144 * PARAMETERS: Info - Parse tree walk info
149 * DESCRIPTION: Dump a buffer byte list, handling the various types of buffers.
150 * Buffer type must be already set in the Op DisasmOpcode.
152 ******************************************************************************/
156 ACPI_OP_WALK_INFO
*Info
,
157 ACPI_PARSE_OBJECT
*Op
)
163 ByteData
= Op
->Named
.Data
;
164 ByteCount
= (UINT32
) Op
->Common
.Value
.Integer
;
167 * The byte list belongs to a buffer, and can be produced by either
168 * a ResourceTemplate, Unicode, quoted string, or a plain byte list.
170 switch (Op
->Common
.Parent
->Common
.DisasmOpcode
)
172 case ACPI_DASM_RESOURCE
:
174 AcpiDmResourceTemplate (Info
, Op
->Common
.Parent
, ByteData
, ByteCount
);
177 case ACPI_DASM_STRING
:
179 AcpiDmIndent (Info
->Level
);
180 AcpiUtPrintString ((char *) ByteData
, ACPI_UINT16_MAX
);
184 case ACPI_DASM_UNICODE
:
189 case ACPI_DASM_PLD_METHOD
:
191 AcpiDmDisasmByteList (Info
->Level
, ByteData
, ByteCount
);
192 AcpiDmPldBuffer (Info
->Level
, ByteData
, ByteCount
);
195 case ACPI_DASM_BUFFER
:
198 * Not a resource, string, or unicode string.
199 * Just dump the buffer
201 AcpiDmDisasmByteList (Info
->Level
, ByteData
, ByteCount
);
207 /*******************************************************************************
209 * FUNCTION: AcpiDmIsUnicodeBuffer
211 * PARAMETERS: Op - Buffer Object to be examined
213 * RETURN: TRUE if buffer contains a UNICODE string
215 * DESCRIPTION: Determine if a buffer Op contains a Unicode string
217 ******************************************************************************/
220 AcpiDmIsUnicodeBuffer (
221 ACPI_PARSE_OBJECT
*Op
)
226 ACPI_PARSE_OBJECT
*SizeOp
;
227 ACPI_PARSE_OBJECT
*NextOp
;
231 /* Buffer size is the buffer argument */
233 SizeOp
= Op
->Common
.Value
.Arg
;
235 /* Next, the initializer byte list to examine */
237 NextOp
= SizeOp
->Common
.Next
;
243 /* Extract the byte list info */
245 ByteData
= NextOp
->Named
.Data
;
246 ByteCount
= (UINT32
) NextOp
->Common
.Value
.Integer
;
247 WordCount
= ACPI_DIV_2 (ByteCount
);
250 * Unicode string must have an even number of bytes and last
256 ((UINT16
*) (void *) ByteData
)[WordCount
- 1] != 0)
261 /* For each word, 1st byte must be ascii, 2nd byte must be zero */
263 for (i
= 0; i
< (ByteCount
- 2); i
+= 2)
265 if ((!ACPI_IS_PRINT (ByteData
[i
])) ||
266 (ByteData
[(ACPI_SIZE
) i
+ 1] != 0))
272 /* Ignore the Size argument in the disassembly of this buffer op */
274 SizeOp
->Common
.DisasmFlags
|= ACPI_PARSEOP_IGNORE
;
279 /*******************************************************************************
281 * FUNCTION: AcpiDmIsStringBuffer
283 * PARAMETERS: Op - Buffer Object to be examined
285 * RETURN: TRUE if buffer contains a ASCII string, FALSE otherwise
287 * DESCRIPTION: Determine if a buffer Op contains a ASCII string
289 ******************************************************************************/
292 AcpiDmIsStringBuffer (
293 ACPI_PARSE_OBJECT
*Op
)
297 ACPI_PARSE_OBJECT
*SizeOp
;
298 ACPI_PARSE_OBJECT
*NextOp
;
302 /* Buffer size is the buffer argument */
304 SizeOp
= Op
->Common
.Value
.Arg
;
306 /* Next, the initializer byte list to examine */
308 NextOp
= SizeOp
->Common
.Next
;
314 /* Extract the byte list info */
316 ByteData
= NextOp
->Named
.Data
;
317 ByteCount
= (UINT32
) NextOp
->Common
.Value
.Integer
;
319 /* Last byte must be the null terminator */
323 (ByteData
[ByteCount
-1] != 0))
328 for (i
= 0; i
< (ByteCount
- 1); i
++)
330 /* TBD: allow some escapes (non-ascii chars).
331 * they will be handled in the string output routine
334 if (!ACPI_IS_PRINT (ByteData
[i
]))
344 /*******************************************************************************
346 * FUNCTION: AcpiDmIsPldBuffer
348 * PARAMETERS: Op - Buffer Object to be examined
350 * RETURN: TRUE if buffer contains a ASCII string, FALSE otherwise
352 * DESCRIPTION: Determine if a buffer Op contains a _PLD structure
354 ******************************************************************************/
358 ACPI_PARSE_OBJECT
*Op
)
360 ACPI_NAMESPACE_NODE
*Node
;
361 ACPI_PARSE_OBJECT
*ParentOp
;
364 ParentOp
= Op
->Common
.Parent
;
370 /* Check for form: Name(_PLD, Buffer() {}). Not legal, however */
372 if (ParentOp
->Common
.AmlOpcode
== AML_NAME_OP
)
374 Node
= ParentOp
->Common
.Node
;
376 if (ACPI_COMPARE_NAME (Node
->Name
.Ascii
, METHOD_NAME__PLD
))
384 /* Check for proper form: Name(_PLD, Package() {Buffer() {}}) */
386 if (ParentOp
->Common
.AmlOpcode
== AML_PACKAGE_OP
)
388 ParentOp
= ParentOp
->Common
.Parent
;
394 if (ParentOp
->Common
.AmlOpcode
== AML_NAME_OP
)
396 Node
= ParentOp
->Common
.Node
;
398 if (ACPI_COMPARE_NAME (Node
->Name
.Ascii
, METHOD_NAME__PLD
))
409 /*******************************************************************************
411 * FUNCTION: AcpiDmPldBuffer
413 * PARAMETERS: Level - Current source code indentation level
414 * ByteData - Pointer to the byte list
415 * ByteCount - Length of the byte list
419 * DESCRIPTION: Dump and format the contents of a _PLD buffer object
421 ******************************************************************************/
423 #define ACPI_PLD_OUTPUT08 "%*.s/* %18s : %-6.2X */\n", ACPI_MUL_4 (Level), " "
424 #define ACPI_PLD_OUTPUT16 "%*.s/* %18s : %-6.4X */\n", ACPI_MUL_4 (Level), " "
425 #define ACPI_PLD_OUTPUT24 "%*.s/* %18s : %-6.6X */\n", ACPI_MUL_4 (Level), " "
433 ACPI_PLD_INFO
*PldInfo
;
437 /* Check for valid byte count */
439 if (ByteCount
< ACPI_PLD_REV1_BUFFER_SIZE
)
444 /* Convert _PLD buffer to local _PLD struct */
446 Status
= AcpiDecodePldBuffer (ByteData
, ByteCount
, &PldInfo
);
447 if (ACPI_FAILURE (Status
))
452 /* First 32-bit dword */
454 AcpiOsPrintf (ACPI_PLD_OUTPUT08
, "Revision", PldInfo
->Revision
);
455 AcpiOsPrintf (ACPI_PLD_OUTPUT08
, "IgnoreColor", PldInfo
->IgnoreColor
);
456 AcpiOsPrintf (ACPI_PLD_OUTPUT24
,"Color", PldInfo
->Color
);
458 /* Second 32-bit dword */
460 AcpiOsPrintf (ACPI_PLD_OUTPUT16
,"Width", PldInfo
->Width
);
461 AcpiOsPrintf (ACPI_PLD_OUTPUT16
,"Height", PldInfo
->Height
);
463 /* Third 32-bit dword */
465 AcpiOsPrintf (ACPI_PLD_OUTPUT08
, "UserVisible", PldInfo
->UserVisible
);
466 AcpiOsPrintf (ACPI_PLD_OUTPUT08
, "Dock", PldInfo
->Dock
);
467 AcpiOsPrintf (ACPI_PLD_OUTPUT08
, "Lid", PldInfo
->Lid
);
468 AcpiOsPrintf (ACPI_PLD_OUTPUT08
, "Panel", PldInfo
->Panel
);
469 AcpiOsPrintf (ACPI_PLD_OUTPUT08
, "VerticalPosition", PldInfo
->VerticalPosition
);
470 AcpiOsPrintf (ACPI_PLD_OUTPUT08
, "HorizontalPosition", PldInfo
->HorizontalPosition
);
471 AcpiOsPrintf (ACPI_PLD_OUTPUT08
, "Shape", PldInfo
->Shape
);
472 AcpiOsPrintf (ACPI_PLD_OUTPUT08
, "GroupOrientation", PldInfo
->GroupOrientation
);
473 AcpiOsPrintf (ACPI_PLD_OUTPUT08
, "GroupToken", PldInfo
->GroupToken
);
474 AcpiOsPrintf (ACPI_PLD_OUTPUT08
, "GroupPosition", PldInfo
->GroupPosition
);
475 AcpiOsPrintf (ACPI_PLD_OUTPUT08
, "Bay", PldInfo
->Bay
);
477 /* Fourth 32-bit dword */
479 AcpiOsPrintf (ACPI_PLD_OUTPUT08
, "Ejectable", PldInfo
->Ejectable
);
480 AcpiOsPrintf (ACPI_PLD_OUTPUT08
, "OspmEjectRequired", PldInfo
->OspmEjectRequired
);
481 AcpiOsPrintf (ACPI_PLD_OUTPUT08
, "CabinetNumber", PldInfo
->CabinetNumber
);
482 AcpiOsPrintf (ACPI_PLD_OUTPUT08
, "CardCageNumber", PldInfo
->CardCageNumber
);
483 AcpiOsPrintf (ACPI_PLD_OUTPUT08
, "Reference", PldInfo
->Reference
);
484 AcpiOsPrintf (ACPI_PLD_OUTPUT08
, "Rotation", PldInfo
->Rotation
);
485 AcpiOsPrintf (ACPI_PLD_OUTPUT08
, "Order", PldInfo
->Order
);
487 /* Fifth 32-bit dword */
489 if (ByteCount
>= ACPI_PLD_REV1_BUFFER_SIZE
)
491 AcpiOsPrintf (ACPI_PLD_OUTPUT16
,"VerticalOffset", PldInfo
->VerticalOffset
);
492 AcpiOsPrintf (ACPI_PLD_OUTPUT16
,"HorizontalOffset", PldInfo
->HorizontalOffset
);
499 /*******************************************************************************
501 * FUNCTION: AcpiDmUnicode
503 * PARAMETERS: Op - Byte List op containing Unicode string
507 * DESCRIPTION: Dump Unicode string as a standard ASCII string. (Remove
508 * the extra zero bytes).
510 ******************************************************************************/
514 ACPI_PARSE_OBJECT
*Op
)
521 /* Extract the buffer info as a WORD buffer */
523 WordData
= ACPI_CAST_PTR (UINT16
, Op
->Named
.Data
);
524 WordCount
= ACPI_DIV_2 (((UINT32
) Op
->Common
.Value
.Integer
));
526 /* Write every other byte as an ASCII character */
529 for (i
= 0; i
< (WordCount
- 1); i
++)
531 AcpiOsPrintf ("%c", (int) WordData
[i
]);
534 AcpiOsPrintf ("\")");
538 /*******************************************************************************
540 * FUNCTION: AcpiDmIsEisaIdElement
542 * PARAMETERS: Op - Op to be examined
546 * DESCRIPTION: Determine if an Op (argument to _HID or _CID) can be converted
549 ******************************************************************************/
552 AcpiDmIsEisaIdElement (
553 ACPI_PARSE_OBJECT
*Op
)
560 /* The parameter must be either a word or a dword */
562 if ((Op
->Common
.AmlOpcode
!= AML_DWORD_OP
) &&
563 (Op
->Common
.AmlOpcode
!= AML_WORD_OP
))
568 /* Swap from little-endian to big-endian to simplify conversion */
570 BigEndianId
= AcpiUtDwordByteSwap ((UINT32
) Op
->Common
.Value
.Integer
);
572 /* Create the 3 leading ASCII letters */
574 Prefix
[0] = ((BigEndianId
>> 26) & 0x1F) + 0x40;
575 Prefix
[1] = ((BigEndianId
>> 21) & 0x1F) + 0x40;
576 Prefix
[2] = ((BigEndianId
>> 16) & 0x1F) + 0x40;
578 /* Verify that all 3 are ascii and alpha */
580 for (i
= 0; i
< 3; i
++)
582 if (!ACPI_IS_ASCII (Prefix
[i
]) ||
583 !ACPI_IS_ALPHA (Prefix
[i
]))
589 /* OK - mark this node as convertable to an EISA ID */
591 Op
->Common
.DisasmOpcode
= ACPI_DASM_EISAID
;
595 /*******************************************************************************
597 * FUNCTION: AcpiDmIsEisaId
599 * PARAMETERS: Op - Op to be examined
603 * DESCRIPTION: Determine if a Name() Op can be converted to an EisaId.
605 ******************************************************************************/
609 ACPI_PARSE_OBJECT
*Op
)
612 ACPI_PARSE_OBJECT
*NextOp
;
615 /* Get the NameSegment */
617 Name
= AcpiPsGetName (Op
);
623 NextOp
= AcpiPsGetDepthNext (NULL
, Op
);
629 /* Check for _HID - has one argument */
631 if (ACPI_COMPARE_NAME (&Name
, METHOD_NAME__HID
))
633 AcpiDmIsEisaIdElement (NextOp
);
637 /* Exit if not _CID */
639 if (!ACPI_COMPARE_NAME (&Name
, METHOD_NAME__CID
))
644 /* _CID can contain a single argument or a package */
646 if (NextOp
->Common
.AmlOpcode
!= AML_PACKAGE_OP
)
648 AcpiDmIsEisaIdElement (NextOp
);
652 /* _CID with Package: get the package length */
654 NextOp
= AcpiPsGetDepthNext (NULL
, NextOp
);
656 /* Don't need to use the length, just walk the peer list */
658 NextOp
= NextOp
->Common
.Next
;
661 AcpiDmIsEisaIdElement (NextOp
);
662 NextOp
= NextOp
->Common
.Next
;
667 /*******************************************************************************
669 * FUNCTION: AcpiDmEisaId
671 * PARAMETERS: EncodedId - Raw encoded EISA ID.
675 * DESCRIPTION: Convert an encoded EISAID back to the original ASCII String.
677 ******************************************************************************/
686 /* Swap from little-endian to big-endian to simplify conversion */
688 BigEndianId
= AcpiUtDwordByteSwap (EncodedId
);
691 /* Split to form "AAANNNN" string */
693 AcpiOsPrintf ("EisaId (\"%c%c%c%4.4X\")",
695 /* Three Alpha characters (AAA), 5 bits each */
697 (int) ((BigEndianId
>> 26) & 0x1F) + 0x40,
698 (int) ((BigEndianId
>> 21) & 0x1F) + 0x40,
699 (int) ((BigEndianId
>> 16) & 0x1F) + 0x40,
701 /* Numeric part (NNNN) is simply the lower 16 bits */
703 (UINT32
) (BigEndianId
& 0xFFFF));