1 /*******************************************************************************
3 * Module Name: dmbuffer - AML disassembler, buffer and string support
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2012, 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.
45 #include <contrib/dev/acpica/include/acpi.h>
46 #include <contrib/dev/acpica/include/accommon.h>
47 #include <contrib/dev/acpica/include/acdisasm.h>
48 #include <contrib/dev/acpica/include/acparser.h>
49 #include <contrib/dev/acpica/include/amlcode.h>
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);
68 /*******************************************************************************
70 * FUNCTION: AcpiDmDisasmByteList
72 * PARAMETERS: Level - Current source code indentation level
73 * ByteData - Pointer to the byte list
74 * ByteCount - Length of the byte list
78 * DESCRIPTION: Dump an AML "ByteList" in Hex format. 8 bytes per line, prefixed
79 * with the hex buffer offset.
81 ******************************************************************************/
84 AcpiDmDisasmByteList (
97 /* Dump the byte list */
99 for (i = 0; i < ByteCount; i++)
101 /* New line every 8 bytes */
103 if (((i % 8) == 0) && (i < ByteCount))
110 AcpiDmIndent (Level);
113 AcpiOsPrintf ("/* %04X */ ", i);
117 AcpiOsPrintf (" 0x%2.2X", (UINT32) ByteData[i]);
119 /* Add comma if there are more bytes to display */
121 if (i < (ByteCount -1))
134 /*******************************************************************************
136 * FUNCTION: AcpiDmByteList
138 * PARAMETERS: Info - Parse tree walk info
143 * DESCRIPTION: Dump a buffer byte list, handling the various types of buffers.
144 * Buffer type must be already set in the Op DisasmOpcode.
146 ******************************************************************************/
150 ACPI_OP_WALK_INFO *Info,
151 ACPI_PARSE_OBJECT *Op)
157 ByteData = Op->Named.Data;
158 ByteCount = (UINT32) Op->Common.Value.Integer;
161 * The byte list belongs to a buffer, and can be produced by either
162 * a ResourceTemplate, Unicode, quoted string, or a plain byte list.
164 switch (Op->Common.Parent->Common.DisasmOpcode)
166 case ACPI_DASM_RESOURCE:
168 AcpiDmResourceTemplate (Info, Op->Common.Parent, ByteData, ByteCount);
171 case ACPI_DASM_STRING:
173 AcpiDmIndent (Info->Level);
174 AcpiUtPrintString ((char *) ByteData, ACPI_UINT8_MAX);
178 case ACPI_DASM_UNICODE:
183 case ACPI_DASM_BUFFER:
187 * Not a resource, string, or unicode string.
188 * Just dump the buffer
190 AcpiDmDisasmByteList (Info->Level, ByteData, ByteCount);
196 /*******************************************************************************
198 * FUNCTION: AcpiDmIsUnicodeBuffer
200 * PARAMETERS: Op - Buffer Object to be examined
202 * RETURN: TRUE if buffer contains a UNICODE string
204 * DESCRIPTION: Determine if a buffer Op contains a Unicode string
206 ******************************************************************************/
209 AcpiDmIsUnicodeBuffer (
210 ACPI_PARSE_OBJECT *Op)
215 ACPI_PARSE_OBJECT *SizeOp;
216 ACPI_PARSE_OBJECT *NextOp;
220 /* Buffer size is the buffer argument */
222 SizeOp = Op->Common.Value.Arg;
224 /* Next, the initializer byte list to examine */
226 NextOp = SizeOp->Common.Next;
232 /* Extract the byte list info */
234 ByteData = NextOp->Named.Data;
235 ByteCount = (UINT32) NextOp->Common.Value.Integer;
236 WordCount = ACPI_DIV_2 (ByteCount);
239 * Unicode string must have an even number of bytes and last
245 ((UINT16 *) (void *) ByteData)[WordCount - 1] != 0)
250 /* For each word, 1st byte must be ascii, 2nd byte must be zero */
252 for (i = 0; i < (ByteCount - 2); i += 2)
254 if ((!ACPI_IS_PRINT (ByteData[i])) ||
255 (ByteData[(ACPI_SIZE) i + 1] != 0))
261 /* Ignore the Size argument in the disassembly of this buffer op */
263 SizeOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
268 /*******************************************************************************
270 * FUNCTION: AcpiDmIsStringBuffer
272 * PARAMETERS: Op - Buffer Object to be examined
274 * RETURN: TRUE if buffer contains a ASCII string, FALSE otherwise
276 * DESCRIPTION: Determine if a buffer Op contains a ASCII string
278 ******************************************************************************/
281 AcpiDmIsStringBuffer (
282 ACPI_PARSE_OBJECT *Op)
286 ACPI_PARSE_OBJECT *SizeOp;
287 ACPI_PARSE_OBJECT *NextOp;
291 /* Buffer size is the buffer argument */
293 SizeOp = Op->Common.Value.Arg;
295 /* Next, the initializer byte list to examine */
297 NextOp = SizeOp->Common.Next;
303 /* Extract the byte list info */
305 ByteData = NextOp->Named.Data;
306 ByteCount = (UINT32) NextOp->Common.Value.Integer;
308 /* Last byte must be the null terminator */
312 (ByteData[ByteCount-1] != 0))
317 for (i = 0; i < (ByteCount - 1); i++)
319 /* TBD: allow some escapes (non-ascii chars).
320 * they will be handled in the string output routine
323 if (!ACPI_IS_PRINT (ByteData[i]))
333 /*******************************************************************************
335 * FUNCTION: AcpiDmUnicode
337 * PARAMETERS: Op - Byte List op containing Unicode string
341 * DESCRIPTION: Dump Unicode string as a standard ASCII string. (Remove
342 * the extra zero bytes).
344 ******************************************************************************/
348 ACPI_PARSE_OBJECT *Op)
355 /* Extract the buffer info as a WORD buffer */
357 WordData = ACPI_CAST_PTR (UINT16, Op->Named.Data);
358 WordCount = ACPI_DIV_2 (((UINT32) Op->Common.Value.Integer));
363 /* Write every other byte as an ASCII character */
365 for (i = 0; i < (WordCount - 1); i++)
367 AcpiOsPrintf ("%c", (int) WordData[i]);
370 AcpiOsPrintf ("\")");
374 /*******************************************************************************
376 * FUNCTION: AcpiDmIsEisaIdElement
378 * PARAMETERS: Op - Op to be examined
382 * DESCRIPTION: Determine if an Op (argument to _HID or _CID) can be converted
385 ******************************************************************************/
388 AcpiDmIsEisaIdElement (
389 ACPI_PARSE_OBJECT *Op)
396 /* The parameter must be either a word or a dword */
398 if ((Op->Common.AmlOpcode != AML_DWORD_OP) &&
399 (Op->Common.AmlOpcode != AML_WORD_OP))
404 /* Swap from little-endian to big-endian to simplify conversion */
406 BigEndianId = AcpiUtDwordByteSwap ((UINT32) Op->Common.Value.Integer);
408 /* Create the 3 leading ASCII letters */
410 Prefix[0] = ((BigEndianId >> 26) & 0x1F) + 0x40;
411 Prefix[1] = ((BigEndianId >> 21) & 0x1F) + 0x40;
412 Prefix[2] = ((BigEndianId >> 16) & 0x1F) + 0x40;
414 /* Verify that all 3 are ascii and alpha */
416 for (i = 0; i < 3; i++)
418 if (!ACPI_IS_ASCII (Prefix[i]) ||
419 !ACPI_IS_ALPHA (Prefix[i]))
425 /* OK - mark this node as convertable to an EISA ID */
427 Op->Common.DisasmOpcode = ACPI_DASM_EISAID;
431 /*******************************************************************************
433 * FUNCTION: AcpiDmIsEisaId
435 * PARAMETERS: Op - Op to be examined
439 * DESCRIPTION: Determine if a Name() Op can be converted to an EisaId.
441 ******************************************************************************/
445 ACPI_PARSE_OBJECT *Op)
448 ACPI_PARSE_OBJECT *NextOp;
451 /* Get the NameSegment */
453 Name = AcpiPsGetName (Op);
459 NextOp = AcpiPsGetDepthNext (NULL, Op);
465 /* Check for _HID - has one argument */
467 if (ACPI_COMPARE_NAME (&Name, METHOD_NAME__HID))
469 AcpiDmIsEisaIdElement (NextOp);
473 /* Exit if not _CID */
475 if (!ACPI_COMPARE_NAME (&Name, METHOD_NAME__CID))
480 /* _CID can contain a single argument or a package */
482 if (NextOp->Common.AmlOpcode != AML_PACKAGE_OP)
484 AcpiDmIsEisaIdElement (NextOp);
488 /* _CID with Package: get the package length */
490 NextOp = AcpiPsGetDepthNext (NULL, NextOp);
492 /* Don't need to use the length, just walk the peer list */
494 NextOp = NextOp->Common.Next;
497 AcpiDmIsEisaIdElement (NextOp);
498 NextOp = NextOp->Common.Next;
503 /*******************************************************************************
505 * FUNCTION: AcpiDmEisaId
507 * PARAMETERS: EncodedId - Raw encoded EISA ID.
511 * DESCRIPTION: Convert an encoded EISAID back to the original ASCII String.
513 ******************************************************************************/
522 /* Swap from little-endian to big-endian to simplify conversion */
524 BigEndianId = AcpiUtDwordByteSwap (EncodedId);
527 /* Split to form "AAANNNN" string */
529 AcpiOsPrintf ("EisaId (\"%c%c%c%4.4X\")",
531 /* Three Alpha characters (AAA), 5 bits each */
533 (int) ((BigEndianId >> 26) & 0x1F) + 0x40,
534 (int) ((BigEndianId >> 21) & 0x1F) + 0x40,
535 (int) ((BigEndianId >> 16) & 0x1F) + 0x40,
537 /* Numeric part (NNNN) is simply the lower 16 bits */
539 (UINT32) (BigEndianId & 0xFFFF));