1 /*******************************************************************************
3 * Module Name: dmbuffer - AML disassembler, buffer and string support
5 ******************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************/
118 #include "accommon.h"
119 #include "acdisasm.h"
120 #include "acparser.h"
124 #ifdef ACPI_DISASSEMBLER
126 #define _COMPONENT ACPI_CA_DEBUGGER
127 ACPI_MODULE_NAME ("dmbuffer")
129 /* Local prototypes */
133 ACPI_PARSE_OBJECT
*Op
);
136 AcpiDmIsEisaIdElement (
137 ACPI_PARSE_OBJECT
*Op
);
140 /*******************************************************************************
142 * FUNCTION: AcpiDmDisasmByteList
144 * PARAMETERS: Level - Current source code indentation level
145 * ByteData - Pointer to the byte list
146 * ByteCount - Length of the byte list
150 * DESCRIPTION: Dump an AML "ByteList" in Hex format. 8 bytes per line, prefixed
151 * with the hex buffer offset.
153 ******************************************************************************/
156 AcpiDmDisasmByteList (
169 /* Dump the byte list */
171 for (i
= 0; i
< ByteCount
; i
++)
173 /* New line every 8 bytes */
175 if (((i
% 8) == 0) && (i
< ByteCount
))
182 AcpiDmIndent (Level
);
185 AcpiOsPrintf ("/* %04X */ ", i
);
189 AcpiOsPrintf ("0x%2.2X", (UINT32
) ByteData
[i
]);
191 /* Add comma if there are more bytes to display */
193 if (i
< (ByteCount
-1))
206 /*******************************************************************************
208 * FUNCTION: AcpiDmByteList
210 * PARAMETERS: Info - Parse tree walk info
215 * DESCRIPTION: Dump a buffer byte list, handling the various types of buffers.
216 * Buffer type must be already set in the Op DisasmOpcode.
218 ******************************************************************************/
222 ACPI_OP_WALK_INFO
*Info
,
223 ACPI_PARSE_OBJECT
*Op
)
229 ByteData
= Op
->Named
.Data
;
230 ByteCount
= (UINT32
) Op
->Common
.Value
.Integer
;
233 * The byte list belongs to a buffer, and can be produced by either
234 * a ResourceTemplate, Unicode, quoted string, or a plain byte list.
236 switch (Op
->Common
.Parent
->Common
.DisasmOpcode
)
238 case ACPI_DASM_RESOURCE
:
240 AcpiDmResourceTemplate (Info
, Op
->Common
.Parent
, ByteData
, ByteCount
);
243 case ACPI_DASM_STRING
:
245 AcpiDmIndent (Info
->Level
);
246 AcpiUtPrintString ((char *) ByteData
, ACPI_UINT8_MAX
);
250 case ACPI_DASM_UNICODE
:
255 case ACPI_DASM_BUFFER
:
259 * Not a resource, string, or unicode string.
260 * Just dump the buffer
262 AcpiDmDisasmByteList (Info
->Level
, ByteData
, ByteCount
);
268 /*******************************************************************************
270 * FUNCTION: AcpiDmIsUnicodeBuffer
272 * PARAMETERS: Op - Buffer Object to be examined
274 * RETURN: TRUE if buffer contains a UNICODE string
276 * DESCRIPTION: Determine if a buffer Op contains a Unicode string
278 ******************************************************************************/
281 AcpiDmIsUnicodeBuffer (
282 ACPI_PARSE_OBJECT
*Op
)
287 ACPI_PARSE_OBJECT
*SizeOp
;
288 ACPI_PARSE_OBJECT
*NextOp
;
292 /* Buffer size is the buffer argument */
294 SizeOp
= Op
->Common
.Value
.Arg
;
296 /* Next, the initializer byte list to examine */
298 NextOp
= SizeOp
->Common
.Next
;
304 /* Extract the byte list info */
306 ByteData
= NextOp
->Named
.Data
;
307 ByteCount
= (UINT32
) NextOp
->Common
.Value
.Integer
;
308 WordCount
= ACPI_DIV_2 (ByteCount
);
311 * Unicode string must have an even number of bytes and last
317 ((UINT16
*) (void *) ByteData
)[WordCount
- 1] != 0)
322 /* For each word, 1st byte must be ascii, 2nd byte must be zero */
324 for (i
= 0; i
< (ByteCount
- 2); i
+= 2)
326 if ((!ACPI_IS_PRINT (ByteData
[i
])) ||
327 (ByteData
[(ACPI_SIZE
) i
+ 1] != 0))
333 /* Ignore the Size argument in the disassembly of this buffer op */
335 SizeOp
->Common
.DisasmFlags
|= ACPI_PARSEOP_IGNORE
;
340 /*******************************************************************************
342 * FUNCTION: AcpiDmIsStringBuffer
344 * PARAMETERS: Op - Buffer Object to be examined
346 * RETURN: TRUE if buffer contains a ASCII string, FALSE otherwise
348 * DESCRIPTION: Determine if a buffer Op contains a ASCII string
350 ******************************************************************************/
353 AcpiDmIsStringBuffer (
354 ACPI_PARSE_OBJECT
*Op
)
358 ACPI_PARSE_OBJECT
*SizeOp
;
359 ACPI_PARSE_OBJECT
*NextOp
;
363 /* Buffer size is the buffer argument */
365 SizeOp
= Op
->Common
.Value
.Arg
;
367 /* Next, the initializer byte list to examine */
369 NextOp
= SizeOp
->Common
.Next
;
375 /* Extract the byte list info */
377 ByteData
= NextOp
->Named
.Data
;
378 ByteCount
= (UINT32
) NextOp
->Common
.Value
.Integer
;
380 /* Last byte must be the null terminator */
384 (ByteData
[ByteCount
-1] != 0))
389 for (i
= 0; i
< (ByteCount
- 1); i
++)
391 /* TBD: allow some escapes (non-ascii chars).
392 * they will be handled in the string output routine
395 if (!ACPI_IS_PRINT (ByteData
[i
]))
405 /*******************************************************************************
407 * FUNCTION: AcpiDmUnicode
409 * PARAMETERS: Op - Byte List op containing Unicode string
413 * DESCRIPTION: Dump Unicode string as a standard ASCII string. (Remove
414 * the extra zero bytes).
416 ******************************************************************************/
420 ACPI_PARSE_OBJECT
*Op
)
427 /* Extract the buffer info as a WORD buffer */
429 WordData
= ACPI_CAST_PTR (UINT16
, Op
->Named
.Data
);
430 WordCount
= ACPI_DIV_2 (((UINT32
) Op
->Common
.Value
.Integer
));
435 /* Write every other byte as an ASCII character */
437 for (i
= 0; i
< (WordCount
- 1); i
++)
439 AcpiOsPrintf ("%c", (int) WordData
[i
]);
442 AcpiOsPrintf ("\")");
446 /*******************************************************************************
448 * FUNCTION: AcpiDmIsEisaIdElement
450 * PARAMETERS: Op - Op to be examined
454 * DESCRIPTION: Determine if an Op (argument to _HID or _CID) can be converted
457 ******************************************************************************/
460 AcpiDmIsEisaIdElement (
461 ACPI_PARSE_OBJECT
*Op
)
468 /* The parameter must be either a word or a dword */
470 if ((Op
->Common
.AmlOpcode
!= AML_DWORD_OP
) &&
471 (Op
->Common
.AmlOpcode
!= AML_WORD_OP
))
476 /* Swap from little-endian to big-endian to simplify conversion */
478 BigEndianId
= AcpiUtDwordByteSwap ((UINT32
) Op
->Common
.Value
.Integer
);
480 /* Create the 3 leading ASCII letters */
482 Prefix
[0] = ((BigEndianId
>> 26) & 0x1F) + 0x40;
483 Prefix
[1] = ((BigEndianId
>> 21) & 0x1F) + 0x40;
484 Prefix
[2] = ((BigEndianId
>> 16) & 0x1F) + 0x40;
486 /* Verify that all 3 are ascii and alpha */
488 for (i
= 0; i
< 3; i
++)
490 if (!ACPI_IS_ASCII (Prefix
[i
]) ||
491 !ACPI_IS_ALPHA (Prefix
[i
]))
497 /* OK - mark this node as convertable to an EISA ID */
499 Op
->Common
.DisasmOpcode
= ACPI_DASM_EISAID
;
503 /*******************************************************************************
505 * FUNCTION: AcpiDmIsEisaId
507 * PARAMETERS: Op - Op to be examined
511 * DESCRIPTION: Determine if a Name() Op can be converted to an EisaId.
513 ******************************************************************************/
517 ACPI_PARSE_OBJECT
*Op
)
520 ACPI_PARSE_OBJECT
*NextOp
;
523 /* Get the NameSegment */
525 Name
= AcpiPsGetName (Op
);
531 NextOp
= AcpiPsGetDepthNext (NULL
, Op
);
537 /* Check for _HID - has one argument */
539 if (ACPI_COMPARE_NAME (&Name
, METHOD_NAME__HID
))
541 AcpiDmIsEisaIdElement (NextOp
);
545 /* Exit if not _CID */
547 if (!ACPI_COMPARE_NAME (&Name
, METHOD_NAME__CID
))
552 /* _CID can contain a single argument or a package */
554 if (NextOp
->Common
.AmlOpcode
!= AML_PACKAGE_OP
)
556 AcpiDmIsEisaIdElement (NextOp
);
560 /* _CID with Package: get the package length */
562 NextOp
= AcpiPsGetDepthNext (NULL
, NextOp
);
564 /* Don't need to use the length, just walk the peer list */
566 NextOp
= NextOp
->Common
.Next
;
569 AcpiDmIsEisaIdElement (NextOp
);
570 NextOp
= NextOp
->Common
.Next
;
575 /*******************************************************************************
577 * FUNCTION: AcpiDmEisaId
579 * PARAMETERS: EncodedId - Raw encoded EISA ID.
583 * DESCRIPTION: Convert an encoded EISAID back to the original ASCII String.
585 ******************************************************************************/
594 /* Swap from little-endian to big-endian to simplify conversion */
596 BigEndianId
= AcpiUtDwordByteSwap (EncodedId
);
599 /* Split to form "AAANNNN" string */
601 AcpiOsPrintf ("EisaId (\"%c%c%c%4.4X\")",
603 /* Three Alpha characters (AAA), 5 bits each */
605 (int) ((BigEndianId
>> 26) & 0x1F) + 0x40,
606 (int) ((BigEndianId
>> 21) & 0x1F) + 0x40,
607 (int) ((BigEndianId
>> 16) & 0x1F) + 0x40,
609 /* Numeric part (NNNN) is simply the lower 16 bits */
611 (UINT32
) (BigEndianId
& 0xFFFF));