1100966Siwasaki/*******************************************************************************
2100966Siwasaki *
3100966Siwasaki * Module Name: dmutils - AML disassembler utilities
4100966Siwasaki *
5100966Siwasaki ******************************************************************************/
6100966Siwasaki
7316303Sjkim/******************************************************************************
8316303Sjkim *
9316303Sjkim * 1. Copyright Notice
10316303Sjkim *
11316303Sjkim * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp.
12100966Siwasaki * All rights reserved.
13100966Siwasaki *
14316303Sjkim * 2. License
15316303Sjkim *
16316303Sjkim * 2.1. This is your license from Intel Corp. under its intellectual property
17316303Sjkim * rights. You may have additional license terms from the party that provided
18316303Sjkim * you this software, covering your right to use that party's intellectual
19316303Sjkim * property rights.
20316303Sjkim *
21316303Sjkim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22316303Sjkim * copy of the source code appearing in this file ("Covered Code") an
23316303Sjkim * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24316303Sjkim * base code distributed originally by Intel ("Original Intel Code") to copy,
25316303Sjkim * make derivatives, distribute, use and display any portion of the Covered
26316303Sjkim * Code in any form, with the right to sublicense such rights; and
27316303Sjkim *
28316303Sjkim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29316303Sjkim * license (with the right to sublicense), under only those claims of Intel
30316303Sjkim * patents that are infringed by the Original Intel Code, to make, use, sell,
31316303Sjkim * offer to sell, and import the Covered Code and derivative works thereof
32316303Sjkim * solely to the minimum extent necessary to exercise the above copyright
33316303Sjkim * license, and in no event shall the patent license extend to any additions
34316303Sjkim * to or modifications of the Original Intel Code. No other license or right
35316303Sjkim * is granted directly or by implication, estoppel or otherwise;
36316303Sjkim *
37316303Sjkim * The above copyright and patent license is granted only if the following
38316303Sjkim * conditions are met:
39316303Sjkim *
40316303Sjkim * 3. Conditions
41316303Sjkim *
42316303Sjkim * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43316303Sjkim * Redistribution of source code of any substantial portion of the Covered
44316303Sjkim * Code or modification with rights to further distribute source must include
45316303Sjkim * the above Copyright Notice, the above License, this list of Conditions,
46316303Sjkim * and the following Disclaimer and Export Compliance provision. In addition,
47316303Sjkim * Licensee must cause all Covered Code to which Licensee contributes to
48316303Sjkim * contain a file documenting the changes Licensee made to create that Covered
49316303Sjkim * Code and the date of any change. Licensee must include in that file the
50316303Sjkim * documentation of any changes made by any predecessor Licensee. Licensee
51316303Sjkim * must include a prominent statement that the modification is derived,
52316303Sjkim * directly or indirectly, from Original Intel Code.
53316303Sjkim *
54316303Sjkim * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55316303Sjkim * Redistribution of source code of any substantial portion of the Covered
56316303Sjkim * Code or modification without rights to further distribute source must
57316303Sjkim * include the following Disclaimer and Export Compliance provision in the
58316303Sjkim * documentation and/or other materials provided with distribution. In
59316303Sjkim * addition, Licensee may not authorize further sublicense of source of any
60316303Sjkim * portion of the Covered Code, and must include terms to the effect that the
61316303Sjkim * license from Licensee to its licensee is limited to the intellectual
62316303Sjkim * property embodied in the software Licensee provides to its licensee, and
63316303Sjkim * not to intellectual property embodied in modifications its licensee may
64316303Sjkim * make.
65316303Sjkim *
66316303Sjkim * 3.3. Redistribution of Executable. Redistribution in executable form of any
67316303Sjkim * substantial portion of the Covered Code or modification must reproduce the
68316303Sjkim * above Copyright Notice, and the following Disclaimer and Export Compliance
69316303Sjkim * provision in the documentation and/or other materials provided with the
70316303Sjkim * distribution.
71316303Sjkim *
72316303Sjkim * 3.4. Intel retains all right, title, and interest in and to the Original
73316303Sjkim * Intel Code.
74316303Sjkim *
75316303Sjkim * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76316303Sjkim * Intel shall be used in advertising or otherwise to promote the sale, use or
77316303Sjkim * other dealings in products derived from or relating to the Covered Code
78316303Sjkim * without prior written authorization from Intel.
79316303Sjkim *
80316303Sjkim * 4. Disclaimer and Export Compliance
81316303Sjkim *
82316303Sjkim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83316303Sjkim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84316303Sjkim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85316303Sjkim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86316303Sjkim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87316303Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88316303Sjkim * PARTICULAR PURPOSE.
89316303Sjkim *
90316303Sjkim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91316303Sjkim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92316303Sjkim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93316303Sjkim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94316303Sjkim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95316303Sjkim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96316303Sjkim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97316303Sjkim * LIMITED REMEDY.
98316303Sjkim *
99316303Sjkim * 4.3. Licensee shall not export, either directly or indirectly, any of this
100316303Sjkim * software or system incorporating such software without first obtaining any
101316303Sjkim * required license or other approval from the U. S. Department of Commerce or
102316303Sjkim * any other agency or department of the United States Government. In the
103316303Sjkim * event Licensee exports any such software from the United States or
104316303Sjkim * re-exports any such software from a foreign destination, Licensee shall
105316303Sjkim * ensure that the distribution and export/re-export of the software is in
106316303Sjkim * compliance with all laws, regulations, orders, or other restrictions of the
107316303Sjkim * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108316303Sjkim * any of its subsidiaries will export/re-export any technical data, process,
109316303Sjkim * software, or service, directly or indirectly, to any country for which the
110316303Sjkim * United States government or any agency thereof requires an export license,
111316303Sjkim * other governmental approval, or letter of assurance, without first obtaining
112316303Sjkim * such license, approval or letter.
113316303Sjkim *
114316303Sjkim *****************************************************************************
115316303Sjkim *
116316303Sjkim * Alternatively, you may choose to be licensed under the terms of the
117316303Sjkim * following license:
118316303Sjkim *
119217365Sjkim * Redistribution and use in source and binary forms, with or without
120217365Sjkim * modification, are permitted provided that the following conditions
121217365Sjkim * are met:
122217365Sjkim * 1. Redistributions of source code must retain the above copyright
123217365Sjkim *    notice, this list of conditions, and the following disclaimer,
124217365Sjkim *    without modification.
125217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126217365Sjkim *    substantially similar to the "NO WARRANTY" disclaimer below
127217365Sjkim *    ("Disclaimer") and any redistribution must be conditioned upon
128217365Sjkim *    including a substantially similar Disclaimer requirement for further
129217365Sjkim *    binary redistribution.
130217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names
131217365Sjkim *    of any contributors may be used to endorse or promote products derived
132217365Sjkim *    from this software without specific prior written permission.
133100966Siwasaki *
134316303Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135316303Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136316303Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137316303Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138316303Sjkim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139316303Sjkim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140316303Sjkim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141316303Sjkim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142316303Sjkim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143316303Sjkim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144316303Sjkim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145316303Sjkim *
146316303Sjkim * Alternatively, you may choose to be licensed under the terms of the
147217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free
148217365Sjkim * Software Foundation.
149100966Siwasaki *
150316303Sjkim *****************************************************************************/
151100966Siwasaki
152193341Sjkim#include <contrib/dev/acpica/include/acpi.h>
153193341Sjkim#include <contrib/dev/acpica/include/accommon.h>
154193341Sjkim#include <contrib/dev/acpica/include/amlcode.h>
155193341Sjkim#include <contrib/dev/acpica/include/acdisasm.h>
156316303Sjkim#include <contrib/dev/acpica/include/acconvert.h>
157151937Sjkim
158151937Sjkim#ifdef ACPI_ASL_COMPILER
159193341Sjkim#include <contrib/dev/acpica/include/acnamesp.h>
160151937Sjkim#endif
161100966Siwasaki
162100966Siwasaki
163102550Siwasaki#define _COMPONENT          ACPI_CA_DEBUGGER
164100966Siwasaki        ACPI_MODULE_NAME    ("dmutils")
165100966Siwasaki
166100966Siwasaki
167100966Siwasaki/* Data used in keeping track of fields */
168100966Siwasaki#if 0
169167802Sjkimconst char                      *AcpiGbl_FENames[] =
170100966Siwasaki{
171100966Siwasaki    "skip",
172100966Siwasaki    "?access?"
173100966Siwasaki};              /* FE = Field Element */
174100966Siwasaki#endif
175100966Siwasaki
176167802Sjkim/* Operators for Match() */
177100966Siwasaki
178167802Sjkimconst char                      *AcpiGbl_MatchOps[] =
179100966Siwasaki{
180100966Siwasaki    "MTR",
181100966Siwasaki    "MEQ",
182100966Siwasaki    "MLE",
183100966Siwasaki    "MLT",
184100966Siwasaki    "MGE",
185100966Siwasaki    "MGT"
186100966Siwasaki};
187100966Siwasaki
188100966Siwasaki/* Access type decoding */
189100966Siwasaki
190167802Sjkimconst char                      *AcpiGbl_AccessTypes[] =
191100966Siwasaki{
192100966Siwasaki    "AnyAcc",
193100966Siwasaki    "ByteAcc",
194100966Siwasaki    "WordAcc",
195100966Siwasaki    "DWordAcc",
196100966Siwasaki    "QWordAcc",
197100966Siwasaki    "BufferAcc",
198167802Sjkim    "InvalidAccType",
199167802Sjkim    "InvalidAccType"
200100966Siwasaki};
201100966Siwasaki
202100966Siwasaki/* Lock rule decoding */
203100966Siwasaki
204167802Sjkimconst char                      *AcpiGbl_LockRule[] =
205100966Siwasaki{
206100966Siwasaki    "NoLock",
207100966Siwasaki    "Lock"
208100966Siwasaki};
209100966Siwasaki
210100966Siwasaki/* Update rule decoding */
211100966Siwasaki
212167802Sjkimconst char                      *AcpiGbl_UpdateRules[] =
213100966Siwasaki{
214100966Siwasaki    "Preserve",
215100966Siwasaki    "WriteAsOnes",
216167802Sjkim    "WriteAsZeros",
217167802Sjkim    "InvalidUpdateRule"
218100966Siwasaki};
219100966Siwasaki
220167802Sjkim/* Strings used to decode resource descriptors */
221100966Siwasaki
222167802Sjkimconst char                      *AcpiGbl_WordDecode[] =
223100966Siwasaki{
224151937Sjkim    "Memory",
225151937Sjkim    "IO",
226151937Sjkim    "BusNumber",
227167802Sjkim    "UnknownResourceType"
228100966Siwasaki};
229100966Siwasaki
230167802Sjkimconst char                      *AcpiGbl_IrqDecode[] =
231100966Siwasaki{
232100966Siwasaki    "IRQNoFlags",
233100966Siwasaki    "IRQ"
234100966Siwasaki};
235100966Siwasaki
236100966Siwasaki
237100966Siwasaki/*******************************************************************************
238100966Siwasaki *
239107325Siwasaki * FUNCTION:    AcpiDmDecodeAttribute
240107325Siwasaki *
241107325Siwasaki * PARAMETERS:  Attribute       - Attribute field of AccessAs keyword
242107325Siwasaki *
243107325Siwasaki * RETURN:      None
244107325Siwasaki *
245228110Sjkim * DESCRIPTION: Decode the AccessAs attribute byte. (Mostly SMBus and
246228110Sjkim *              GenericSerialBus stuff.)
247107325Siwasaki *
248107325Siwasaki ******************************************************************************/
249107325Siwasaki
250107325Siwasakivoid
251107325SiwasakiAcpiDmDecodeAttribute (
252107325Siwasaki    UINT8                   Attribute)
253107325Siwasaki{
254107325Siwasaki
255107325Siwasaki    switch (Attribute)
256107325Siwasaki    {
257228110Sjkim    case AML_FIELD_ATTRIB_QUICK:
258107325Siwasaki
259228110Sjkim        AcpiOsPrintf ("AttribQuick");
260107325Siwasaki        break;
261107325Siwasaki
262228110Sjkim    case AML_FIELD_ATTRIB_SEND_RCV:
263107325Siwasaki
264228110Sjkim        AcpiOsPrintf ("AttribSendReceive");
265107325Siwasaki        break;
266107325Siwasaki
267228110Sjkim    case AML_FIELD_ATTRIB_BYTE:
268107325Siwasaki
269228110Sjkim        AcpiOsPrintf ("AttribByte");
270107325Siwasaki        break;
271107325Siwasaki
272228110Sjkim    case AML_FIELD_ATTRIB_WORD:
273107325Siwasaki
274228110Sjkim        AcpiOsPrintf ("AttribWord");
275107325Siwasaki        break;
276107325Siwasaki
277228110Sjkim    case AML_FIELD_ATTRIB_BLOCK:
278107325Siwasaki
279228110Sjkim        AcpiOsPrintf ("AttribBlock");
280107325Siwasaki        break;
281107325Siwasaki
282228110Sjkim    case AML_FIELD_ATTRIB_MULTIBYTE:
283107325Siwasaki
284228110Sjkim        AcpiOsPrintf ("AttribBytes");
285107325Siwasaki        break;
286107325Siwasaki
287228110Sjkim    case AML_FIELD_ATTRIB_WORD_CALL:
288107325Siwasaki
289228110Sjkim        AcpiOsPrintf ("AttribProcessCall");
290107325Siwasaki        break;
291107325Siwasaki
292228110Sjkim    case AML_FIELD_ATTRIB_BLOCK_CALL:
293228110Sjkim
294228110Sjkim        AcpiOsPrintf ("AttribBlockProcessCall");
295228110Sjkim        break;
296228110Sjkim
297228110Sjkim    case AML_FIELD_ATTRIB_RAW_BYTES:
298228110Sjkim
299228110Sjkim        AcpiOsPrintf ("AttribRawBytes");
300228110Sjkim        break;
301228110Sjkim
302228110Sjkim    case AML_FIELD_ATTRIB_RAW_PROCESS:
303228110Sjkim
304228110Sjkim        AcpiOsPrintf ("AttribRawProcessBytes");
305228110Sjkim        break;
306228110Sjkim
307107325Siwasaki    default:
308107325Siwasaki
309228110Sjkim        /* A ByteConst is allowed by the grammar */
310228110Sjkim
311228110Sjkim        AcpiOsPrintf ("0x%2.2X", Attribute);
312107325Siwasaki        break;
313107325Siwasaki    }
314107325Siwasaki}
315107325Siwasaki
316107325Siwasaki
317107325Siwasaki/*******************************************************************************
318107325Siwasaki *
319100966Siwasaki * FUNCTION:    AcpiDmIndent
320100966Siwasaki *
321100966Siwasaki * PARAMETERS:  Level               - Current source code indentation level
322100966Siwasaki *
323100966Siwasaki * RETURN:      None
324100966Siwasaki *
325100966Siwasaki * DESCRIPTION: Indent 4 spaces per indentation level.
326100966Siwasaki *
327100966Siwasaki ******************************************************************************/
328100966Siwasaki
329100966Siwasakivoid
330100966SiwasakiAcpiDmIndent (
331100966Siwasaki    UINT32                  Level)
332100966Siwasaki{
333100966Siwasaki
334100966Siwasaki    if (!Level)
335100966Siwasaki    {
336100966Siwasaki        return;
337100966Siwasaki    }
338100966Siwasaki
339298714Sjkim    AcpiOsPrintf ("%*.s", (Level * 4), " ");
340100966Siwasaki}
341100966Siwasaki
342100966Siwasaki
343100966Siwasaki/*******************************************************************************
344100966Siwasaki *
345100966Siwasaki * FUNCTION:    AcpiDmCommaIfListMember
346100966Siwasaki *
347100966Siwasaki * PARAMETERS:  Op              - Current operator/operand
348100966Siwasaki *
349100966Siwasaki * RETURN:      TRUE if a comma was inserted
350100966Siwasaki *
351100966Siwasaki * DESCRIPTION: Insert a comma if this Op is a member of an argument list.
352100966Siwasaki *
353100966Siwasaki ******************************************************************************/
354100966Siwasaki
355100966SiwasakiBOOLEAN
356100966SiwasakiAcpiDmCommaIfListMember (
357100966Siwasaki    ACPI_PARSE_OBJECT       *Op)
358100966Siwasaki{
359100966Siwasaki
360100966Siwasaki    if (!Op->Common.Next)
361100966Siwasaki    {
362316303Sjkim        ASL_CV_PRINT_ONE_COMMENT (Op, AMLCOMMENT_INLINE, NULL, 0);
363241973Sjkim        return (FALSE);
364100966Siwasaki    }
365100966Siwasaki
366100966Siwasaki    if (AcpiDmListType (Op->Common.Parent) & BLOCK_COMMA_LIST)
367100966Siwasaki    {
368278970Sjkim        /* Exit if Target has been marked IGNORE */
369278970Sjkim
370278970Sjkim        if (Op->Common.Next->Common.DisasmFlags & ACPI_PARSEOP_IGNORE)
371278970Sjkim        {
372316303Sjkim            ASL_CV_PRINT_ONE_COMMENT (Op, AMLCOMMENT_INLINE, NULL, 0);
373278970Sjkim            return (FALSE);
374278970Sjkim        }
375278970Sjkim
376100966Siwasaki        /* Check for a NULL target operand */
377100966Siwasaki
378100966Siwasaki        if ((Op->Common.Next->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&
379100966Siwasaki            (!Op->Common.Next->Common.Value.String))
380100966Siwasaki        {
381100966Siwasaki            /*
382100966Siwasaki             * To handle the Divide() case where there are two optional
383241973Sjkim             * targets, look ahead one more op. If null, this null target
384241973Sjkim             * is the one and only target -- no comma needed. Otherwise,
385100966Siwasaki             * we need a comma to prepare for the next target.
386100966Siwasaki             */
387100966Siwasaki            if (!Op->Common.Next->Common.Next)
388100966Siwasaki            {
389316303Sjkim                ASL_CV_PRINT_ONE_COMMENT (Op, AMLCOMMENT_INLINE, NULL, 0);
390241973Sjkim                return (FALSE);
391100966Siwasaki            }
392100966Siwasaki        }
393100966Siwasaki
394298714Sjkim        if ((Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMETER_LIST) &&
395298714Sjkim            (!(Op->Common.Next->Common.DisasmFlags & ACPI_PARSEOP_PARAMETER_LIST)))
396100966Siwasaki        {
397316303Sjkim            ASL_CV_PRINT_ONE_COMMENT (Op, AMLCOMMENT_INLINE, NULL, 0);
398241973Sjkim            return (FALSE);
399100966Siwasaki        }
400100966Siwasaki
401278970Sjkim        /* Emit comma only if this is not a C-style operator */
402278970Sjkim
403278970Sjkim        if (!Op->Common.OperatorSymbol)
404278970Sjkim        {
405278970Sjkim            AcpiOsPrintf (", ");
406316303Sjkim            ASL_CV_PRINT_ONE_COMMENT (Op, AMLCOMMENT_INLINE, NULL, 0);
407278970Sjkim        }
408278970Sjkim
409100966Siwasaki        return (TRUE);
410100966Siwasaki    }
411100966Siwasaki
412298714Sjkim    else if ((Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMETER_LIST) &&
413298714Sjkim             (Op->Common.Next->Common.DisasmFlags & ACPI_PARSEOP_PARAMETER_LIST))
414100966Siwasaki    {
415100966Siwasaki        AcpiOsPrintf (", ");
416316303Sjkim        ASL_CV_PRINT_ONE_COMMENT (Op, AMLCOMMENT_INLINE, NULL, 0);
417316303Sjkim
418100966Siwasaki        return (TRUE);
419100966Siwasaki    }
420100966Siwasaki
421100966Siwasaki    return (FALSE);
422100966Siwasaki}
423100966Siwasaki
424100966Siwasaki
425100966Siwasaki/*******************************************************************************
426100966Siwasaki *
427100966Siwasaki * FUNCTION:    AcpiDmCommaIfFieldMember
428100966Siwasaki *
429100966Siwasaki * PARAMETERS:  Op              - Current operator/operand
430100966Siwasaki *
431100966Siwasaki * RETURN:      None
432100966Siwasaki *
433100966Siwasaki * DESCRIPTION: Insert a comma if this Op is a member of a Field argument list.
434100966Siwasaki *
435100966Siwasaki ******************************************************************************/
436100966Siwasaki
437100966Siwasakivoid
438100966SiwasakiAcpiDmCommaIfFieldMember (
439100966Siwasaki    ACPI_PARSE_OBJECT       *Op)
440100966Siwasaki{
441100966Siwasaki
442100966Siwasaki    if (Op->Common.Next)
443100966Siwasaki    {
444100966Siwasaki        AcpiOsPrintf (", ");
445100966Siwasaki    }
446100966Siwasaki}
447