dmutils.c revision 1.1.1.4 1 /*******************************************************************************
2 *
3 * Module Name: dmutils - AML disassembler utilities
4 *
5 ******************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2014, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
25 *
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.
29 *
30 * NO WARRANTY
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.
42 */
43
44 #include "acpi.h"
45 #include "accommon.h"
46 #include "amlcode.h"
47 #include "acdisasm.h"
48
49 #ifdef ACPI_ASL_COMPILER
50 #include <acnamesp.h>
51 #endif
52
53 #ifdef ACPI_DISASSEMBLER
54
55 #define _COMPONENT ACPI_CA_DEBUGGER
56 ACPI_MODULE_NAME ("dmutils")
57
58
59 /* Data used in keeping track of fields */
60 #if 0
61 const char *AcpiGbl_FENames[] =
62 {
63 "skip",
64 "?access?"
65 }; /* FE = Field Element */
66 #endif
67
68 /* Operators for Match() */
69
70 const char *AcpiGbl_MatchOps[] =
71 {
72 "MTR",
73 "MEQ",
74 "MLE",
75 "MLT",
76 "MGE",
77 "MGT"
78 };
79
80 /* Access type decoding */
81
82 const char *AcpiGbl_AccessTypes[] =
83 {
84 "AnyAcc",
85 "ByteAcc",
86 "WordAcc",
87 "DWordAcc",
88 "QWordAcc",
89 "BufferAcc",
90 "InvalidAccType",
91 "InvalidAccType"
92 };
93
94 /* Lock rule decoding */
95
96 const char *AcpiGbl_LockRule[] =
97 {
98 "NoLock",
99 "Lock"
100 };
101
102 /* Update rule decoding */
103
104 const char *AcpiGbl_UpdateRules[] =
105 {
106 "Preserve",
107 "WriteAsOnes",
108 "WriteAsZeros",
109 "InvalidUpdateRule"
110 };
111
112 /* Strings used to decode resource descriptors */
113
114 const char *AcpiGbl_WordDecode[] =
115 {
116 "Memory",
117 "IO",
118 "BusNumber",
119 "UnknownResourceType"
120 };
121
122 const char *AcpiGbl_IrqDecode[] =
123 {
124 "IRQNoFlags",
125 "IRQ"
126 };
127
128
129 /*******************************************************************************
130 *
131 * FUNCTION: AcpiDmDecodeAttribute
132 *
133 * PARAMETERS: Attribute - Attribute field of AccessAs keyword
134 *
135 * RETURN: None
136 *
137 * DESCRIPTION: Decode the AccessAs attribute byte. (Mostly SMBus and
138 * GenericSerialBus stuff.)
139 *
140 ******************************************************************************/
141
142 void
143 AcpiDmDecodeAttribute (
144 UINT8 Attribute)
145 {
146
147 switch (Attribute)
148 {
149 case AML_FIELD_ATTRIB_QUICK:
150
151 AcpiOsPrintf ("AttribQuick");
152 break;
153
154 case AML_FIELD_ATTRIB_SEND_RCV:
155
156 AcpiOsPrintf ("AttribSendReceive");
157 break;
158
159 case AML_FIELD_ATTRIB_BYTE:
160
161 AcpiOsPrintf ("AttribByte");
162 break;
163
164 case AML_FIELD_ATTRIB_WORD:
165
166 AcpiOsPrintf ("AttribWord");
167 break;
168
169 case AML_FIELD_ATTRIB_BLOCK:
170
171 AcpiOsPrintf ("AttribBlock");
172 break;
173
174 case AML_FIELD_ATTRIB_MULTIBYTE:
175
176 AcpiOsPrintf ("AttribBytes");
177 break;
178
179 case AML_FIELD_ATTRIB_WORD_CALL:
180
181 AcpiOsPrintf ("AttribProcessCall");
182 break;
183
184 case AML_FIELD_ATTRIB_BLOCK_CALL:
185
186 AcpiOsPrintf ("AttribBlockProcessCall");
187 break;
188
189 case AML_FIELD_ATTRIB_RAW_BYTES:
190
191 AcpiOsPrintf ("AttribRawBytes");
192 break;
193
194 case AML_FIELD_ATTRIB_RAW_PROCESS:
195
196 AcpiOsPrintf ("AttribRawProcessBytes");
197 break;
198
199 default:
200
201 /* A ByteConst is allowed by the grammar */
202
203 AcpiOsPrintf ("0x%2.2X", Attribute);
204 break;
205 }
206 }
207
208
209 /*******************************************************************************
210 *
211 * FUNCTION: AcpiDmIndent
212 *
213 * PARAMETERS: Level - Current source code indentation level
214 *
215 * RETURN: None
216 *
217 * DESCRIPTION: Indent 4 spaces per indentation level.
218 *
219 ******************************************************************************/
220
221 void
222 AcpiDmIndent (
223 UINT32 Level)
224 {
225
226 if (!Level)
227 {
228 return;
229 }
230
231 AcpiOsPrintf ("%*.s", ACPI_MUL_4 (Level), " ");
232 }
233
234
235 /*******************************************************************************
236 *
237 * FUNCTION: AcpiDmCommaIfListMember
238 *
239 * PARAMETERS: Op - Current operator/operand
240 *
241 * RETURN: TRUE if a comma was inserted
242 *
243 * DESCRIPTION: Insert a comma if this Op is a member of an argument list.
244 *
245 ******************************************************************************/
246
247 BOOLEAN
248 AcpiDmCommaIfListMember (
249 ACPI_PARSE_OBJECT *Op)
250 {
251
252 if (!Op->Common.Next)
253 {
254 return (FALSE);
255 }
256
257 if (AcpiDmListType (Op->Common.Parent) & BLOCK_COMMA_LIST)
258 {
259 /* Check for a NULL target operand */
260
261 if ((Op->Common.Next->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&
262 (!Op->Common.Next->Common.Value.String))
263 {
264 /*
265 * To handle the Divide() case where there are two optional
266 * targets, look ahead one more op. If null, this null target
267 * is the one and only target -- no comma needed. Otherwise,
268 * we need a comma to prepare for the next target.
269 */
270 if (!Op->Common.Next->Common.Next)
271 {
272 return (FALSE);
273 }
274 }
275
276 if ((Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST) &&
277 (!(Op->Common.Next->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST)))
278 {
279 return (FALSE);
280 }
281
282 AcpiOsPrintf (", ");
283 return (TRUE);
284 }
285
286 else if ((Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST) &&
287 (Op->Common.Next->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST))
288 {
289 AcpiOsPrintf (", ");
290 return (TRUE);
291 }
292
293 return (FALSE);
294 }
295
296
297 /*******************************************************************************
298 *
299 * FUNCTION: AcpiDmCommaIfFieldMember
300 *
301 * PARAMETERS: Op - Current operator/operand
302 *
303 * RETURN: None
304 *
305 * DESCRIPTION: Insert a comma if this Op is a member of a Field argument list.
306 *
307 ******************************************************************************/
308
309 void
310 AcpiDmCommaIfFieldMember (
311 ACPI_PARSE_OBJECT *Op)
312 {
313
314 if (Op->Common.Next)
315 {
316 AcpiOsPrintf (", ");
317 }
318 }
319
320 #endif
321