1295571Sjkim/******************************************************************************
2295571Sjkim *
3295571Sjkim * Module Name: asldebug -- Debug output support
4295571Sjkim *
5295571Sjkim *****************************************************************************/
6295571Sjkim
7295571Sjkim/*
8295571Sjkim * Copyright (C) 2000 - 2016, Intel Corp.
9295571Sjkim * All rights reserved.
10295571Sjkim *
11295571Sjkim * Redistribution and use in source and binary forms, with or without
12295571Sjkim * modification, are permitted provided that the following conditions
13295571Sjkim * are met:
14295571Sjkim * 1. Redistributions of source code must retain the above copyright
15295571Sjkim *    notice, this list of conditions, and the following disclaimer,
16295571Sjkim *    without modification.
17295571Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18295571Sjkim *    substantially similar to the "NO WARRANTY" disclaimer below
19295571Sjkim *    ("Disclaimer") and any redistribution must be conditioned upon
20295571Sjkim *    including a substantially similar Disclaimer requirement for further
21295571Sjkim *    binary redistribution.
22295571Sjkim * 3. Neither the names of the above-listed copyright holders nor the names
23295571Sjkim *    of any contributors may be used to endorse or promote products derived
24295571Sjkim *    from this software without specific prior written permission.
25295571Sjkim *
26295571Sjkim * Alternatively, this software may be distributed under the terms of the
27295571Sjkim * GNU General Public License ("GPL") version 2 as published by the Free
28295571Sjkim * Software Foundation.
29295571Sjkim *
30295571Sjkim * NO WARRANTY
31295571Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32295571Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33295571Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34295571Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35295571Sjkim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36295571Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37295571Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38295571Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39295571Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40295571Sjkim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41295571Sjkim * POSSIBILITY OF SUCH DAMAGES.
42295571Sjkim */
43295571Sjkim
44298714Sjkim#include <contrib/dev/acpica/compiler/aslcompiler.h>
45295571Sjkim#include "aslcompiler.y.h"
46295571Sjkim
47295571Sjkim
48295571Sjkim#define _COMPONENT          ACPI_COMPILER
49295571Sjkim        ACPI_MODULE_NAME    ("asldebug")
50295571Sjkim
51295571Sjkim
52295571Sjkim/* Local prototypes */
53295571Sjkim
54295571Sjkimstatic void
55295571SjkimUtDumpParseOpName (
56295571Sjkim    ACPI_PARSE_OBJECT       *Op,
57295571Sjkim    UINT32                  Level,
58295571Sjkim    UINT32                  DataLength);
59295571Sjkim
60295571Sjkim
61295571Sjkim/*******************************************************************************
62295571Sjkim *
63295571Sjkim * FUNCTION:    UtDumpIntegerOp
64295571Sjkim *
65295571Sjkim * PARAMETERS:  Op                  - Current parse op
66295571Sjkim *              Level               - Current output indentation level
67295571Sjkim *              IntegerLength       - Output length of the integer (2/4/8/16)
68295571Sjkim *
69295571Sjkim * RETURN:      None
70295571Sjkim *
71295571Sjkim * DESCRIPTION: Emit formatted debug output for "integer" ops.
72295571Sjkim *              Note: IntegerLength must be one of 2,4,8,16.
73295571Sjkim *
74295571Sjkim ******************************************************************************/
75295571Sjkim
76295571Sjkimvoid
77295571SjkimUtDumpIntegerOp (
78295571Sjkim    ACPI_PARSE_OBJECT       *Op,
79295571Sjkim    UINT32                  Level,
80295571Sjkim    UINT32                  IntegerLength)
81295571Sjkim{
82295571Sjkim
83295571Sjkim    /* Emit the ParseOp name, leaving room for the integer */
84295571Sjkim
85295571Sjkim    UtDumpParseOpName (Op, Level, IntegerLength);
86295571Sjkim
87295571Sjkim    /* Emit the integer based upon length */
88295571Sjkim
89295571Sjkim    switch (IntegerLength)
90295571Sjkim    {
91295571Sjkim    case 2: /* Byte */
92295571Sjkim    case 4: /* Word */
93295571Sjkim    case 8: /* Dword */
94295571Sjkim
95295571Sjkim        DbgPrint (ASL_TREE_OUTPUT,
96295571Sjkim            "%*.*X", IntegerLength, IntegerLength, Op->Asl.Value.Integer);
97295571Sjkim        break;
98295571Sjkim
99295571Sjkim    case 16: /* Qword and Integer */
100295571Sjkim
101295571Sjkim        DbgPrint (ASL_TREE_OUTPUT,
102295571Sjkim            "%8.8X%8.8X", ACPI_FORMAT_UINT64 (Op->Asl.Value.Integer));
103295571Sjkim        break;
104295571Sjkim
105295571Sjkim    default:
106295571Sjkim        break;
107295571Sjkim    }
108295571Sjkim}
109295571Sjkim
110295571Sjkim
111295571Sjkim/*******************************************************************************
112295571Sjkim *
113295571Sjkim * FUNCTION:    UtDumpStringOp
114295571Sjkim *
115295571Sjkim * PARAMETERS:  Op                  - Current parse op
116295571Sjkim *              Level               - Current output indentation level
117295571Sjkim *
118295571Sjkim * RETURN:      None
119295571Sjkim *
120295571Sjkim * DESCRIPTION: Emit formatted debug output for String/Pathname ops.
121295571Sjkim *
122295571Sjkim ******************************************************************************/
123295571Sjkim
124295571Sjkimvoid
125295571SjkimUtDumpStringOp (
126295571Sjkim    ACPI_PARSE_OBJECT       *Op,
127295571Sjkim    UINT32                  Level)
128295571Sjkim{
129295571Sjkim    char                    *String;
130295571Sjkim
131295571Sjkim
132295571Sjkim    String = Op->Asl.Value.String;
133295571Sjkim
134295571Sjkim    if (Op->Asl.ParseOpcode != PARSEOP_STRING_LITERAL)
135295571Sjkim    {
136295571Sjkim        /*
137295571Sjkim         * For the "path" ops NAMEPATH, NAMESEG, METHODCALL -- if the
138295571Sjkim         * ExternalName is valid, it takes precedence. In these cases the
139295571Sjkim         * Value.String is the raw "internal" name from the AML code, which
140295571Sjkim         * we don't want to use, because it contains non-ascii characters.
141295571Sjkim         */
142295571Sjkim        if (Op->Asl.ExternalName)
143295571Sjkim        {
144295571Sjkim            String = Op->Asl.ExternalName;
145295571Sjkim        }
146295571Sjkim    }
147295571Sjkim
148295571Sjkim    if (!String)
149295571Sjkim    {
150295571Sjkim        DbgPrint (ASL_TREE_OUTPUT,
151295571Sjkim            " ERROR: Could not find a valid String/Path pointer\n");
152295571Sjkim        return;
153295571Sjkim    }
154295571Sjkim
155295571Sjkim    /* Emit the ParseOp name, leaving room for the string */
156295571Sjkim
157295571Sjkim    UtDumpParseOpName (Op, Level, strlen (String));
158295571Sjkim    DbgPrint (ASL_TREE_OUTPUT, "%s", String);
159295571Sjkim}
160295571Sjkim
161295571Sjkim
162295571Sjkim/*******************************************************************************
163295571Sjkim *
164295571Sjkim * FUNCTION:    UtDumpBasicOp
165295571Sjkim *
166295571Sjkim * PARAMETERS:  Op                  - Current parse op
167295571Sjkim *              Level               - Current output indentation level
168295571Sjkim *
169295571Sjkim * RETURN:      None
170295571Sjkim *
171295571Sjkim * DESCRIPTION: Generic formatted debug output for "basic" ops that have no
172295571Sjkim *              associated strings or integer values.
173295571Sjkim *
174295571Sjkim ******************************************************************************/
175295571Sjkim
176295571Sjkimvoid
177295571SjkimUtDumpBasicOp (
178295571Sjkim    ACPI_PARSE_OBJECT       *Op,
179295571Sjkim    UINT32                  Level)
180295571Sjkim{
181295571Sjkim
182295571Sjkim    /* Just print out the ParseOp name, there is no extra data */
183295571Sjkim
184295571Sjkim    UtDumpParseOpName (Op, Level, 0);
185295571Sjkim}
186295571Sjkim
187295571Sjkim
188295571Sjkim/*******************************************************************************
189295571Sjkim *
190295571Sjkim * FUNCTION:    UtDumpParseOpName
191295571Sjkim *
192295571Sjkim * PARAMETERS:  Op                  - Current parse op
193295571Sjkim *              Level               - Current output indentation level
194295571Sjkim *              DataLength          - Length of data to appear after the name
195295571Sjkim *
196295571Sjkim * RETURN:      None
197295571Sjkim *
198295571Sjkim * DESCRIPTION: Indent and emit the ascii ParseOp name for the op
199295571Sjkim *
200295571Sjkim ******************************************************************************/
201295571Sjkim
202295571Sjkimstatic void
203295571SjkimUtDumpParseOpName (
204295571Sjkim    ACPI_PARSE_OBJECT       *Op,
205295571Sjkim    UINT32                  Level,
206295571Sjkim    UINT32                  DataLength)
207295571Sjkim{
208295571Sjkim    char                    *ParseOpName;
209295571Sjkim    UINT32                  IndentLength;
210295571Sjkim    UINT32                  NameLength;
211295571Sjkim    UINT32                  LineLength;
212295571Sjkim    UINT32                  PaddingLength;
213295571Sjkim
214295571Sjkim
215295571Sjkim    /* Emit the LineNumber/IndentLevel prefix on each output line */
216295571Sjkim
217295571Sjkim    DbgPrint (ASL_TREE_OUTPUT,
218295571Sjkim        "%5.5d [%2d]", Op->Asl.LogicalLineNumber, Level);
219295571Sjkim
220295571Sjkim    ParseOpName = UtGetOpName (Op->Asl.ParseOpcode);
221295571Sjkim
222295571Sjkim    /* Calculate various lengths for output alignment */
223295571Sjkim
224295571Sjkim    IndentLength = Level * DEBUG_SPACES_PER_INDENT;
225295571Sjkim    NameLength = strlen (ParseOpName);
226295571Sjkim    LineLength = IndentLength + 1 + NameLength + 1 + DataLength;
227295571Sjkim    PaddingLength = (DEBUG_MAX_LINE_LENGTH + 1) - LineLength;
228295571Sjkim
229295571Sjkim    /* Parse tree indentation is based upon the nesting/indent level */
230295571Sjkim
231295571Sjkim    if (Level)
232295571Sjkim    {
233295571Sjkim        DbgPrint (ASL_TREE_OUTPUT, "%*s", IndentLength, " ");
234295571Sjkim    }
235295571Sjkim
236295571Sjkim    /* Emit the actual name here */
237295571Sjkim
238295571Sjkim    DbgPrint (ASL_TREE_OUTPUT, " %s", ParseOpName);
239295571Sjkim
240295571Sjkim    /* Emit extra padding blanks for alignment of later data items */
241295571Sjkim
242295571Sjkim    if (LineLength > DEBUG_MAX_LINE_LENGTH)
243295571Sjkim    {
244295571Sjkim        /* Split a long line immediately after the ParseOpName string */
245295571Sjkim
246295571Sjkim        DbgPrint (ASL_TREE_OUTPUT, "\n%*s",
247295571Sjkim            (DEBUG_FULL_LINE_LENGTH - DataLength), " ");
248295571Sjkim    }
249295571Sjkim    else
250295571Sjkim    {
251295571Sjkim        DbgPrint (ASL_TREE_OUTPUT, "%*s", PaddingLength, " ");
252295571Sjkim    }
253295571Sjkim}
254