aslopcodes.c revision 1.1.1.2.4.2 1 1.1.1.2.4.2 rmind
2 1.1.1.2.4.2 rmind /******************************************************************************
3 1.1.1.2.4.2 rmind *
4 1.1.1.2.4.2 rmind * Module Name: aslopcode - AML opcode generation
5 1.1.1.2.4.2 rmind *
6 1.1.1.2.4.2 rmind *****************************************************************************/
7 1.1.1.2.4.2 rmind
8 1.1.1.2.4.2 rmind /*
9 1.1.1.2.4.2 rmind * Copyright (C) 2000 - 2011, Intel Corp.
10 1.1.1.2.4.2 rmind * All rights reserved.
11 1.1.1.2.4.2 rmind *
12 1.1.1.2.4.2 rmind * Redistribution and use in source and binary forms, with or without
13 1.1.1.2.4.2 rmind * modification, are permitted provided that the following conditions
14 1.1.1.2.4.2 rmind * are met:
15 1.1.1.2.4.2 rmind * 1. Redistributions of source code must retain the above copyright
16 1.1.1.2.4.2 rmind * notice, this list of conditions, and the following disclaimer,
17 1.1.1.2.4.2 rmind * without modification.
18 1.1.1.2.4.2 rmind * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 1.1.1.2.4.2 rmind * substantially similar to the "NO WARRANTY" disclaimer below
20 1.1.1.2.4.2 rmind * ("Disclaimer") and any redistribution must be conditioned upon
21 1.1.1.2.4.2 rmind * including a substantially similar Disclaimer requirement for further
22 1.1.1.2.4.2 rmind * binary redistribution.
23 1.1.1.2.4.2 rmind * 3. Neither the names of the above-listed copyright holders nor the names
24 1.1.1.2.4.2 rmind * of any contributors may be used to endorse or promote products derived
25 1.1.1.2.4.2 rmind * from this software without specific prior written permission.
26 1.1.1.2.4.2 rmind *
27 1.1.1.2.4.2 rmind * Alternatively, this software may be distributed under the terms of the
28 1.1.1.2.4.2 rmind * GNU General Public License ("GPL") version 2 as published by the Free
29 1.1.1.2.4.2 rmind * Software Foundation.
30 1.1.1.2.4.2 rmind *
31 1.1.1.2.4.2 rmind * NO WARRANTY
32 1.1.1.2.4.2 rmind * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 1.1.1.2.4.2 rmind * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 1.1.1.2.4.2 rmind * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 1.1.1.2.4.2 rmind * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 1.1.1.2.4.2 rmind * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 1.1.1.2.4.2 rmind * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 1.1.1.2.4.2 rmind * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 1.1.1.2.4.2 rmind * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 1.1.1.2.4.2 rmind * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 1.1.1.2.4.2 rmind * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 1.1.1.2.4.2 rmind * POSSIBILITY OF SUCH DAMAGES.
43 1.1.1.2.4.2 rmind */
44 1.1.1.2.4.2 rmind
45 1.1.1.2.4.2 rmind
46 1.1.1.2.4.2 rmind #include "aslcompiler.h"
47 1.1.1.2.4.2 rmind #include "aslcompiler.y.h"
48 1.1.1.2.4.2 rmind #include "amlcode.h"
49 1.1.1.2.4.2 rmind
50 1.1.1.2.4.2 rmind #define _COMPONENT ACPI_COMPILER
51 1.1.1.2.4.2 rmind ACPI_MODULE_NAME ("aslopcodes")
52 1.1.1.2.4.2 rmind
53 1.1.1.2.4.2 rmind
54 1.1.1.2.4.2 rmind /* Local prototypes */
55 1.1.1.2.4.2 rmind
56 1.1.1.2.4.2 rmind static void
57 1.1.1.2.4.2 rmind OpcDoAccessAs (
58 1.1.1.2.4.2 rmind ACPI_PARSE_OBJECT *Op);
59 1.1.1.2.4.2 rmind
60 1.1.1.2.4.2 rmind static void
61 1.1.1.2.4.2 rmind OpcDoUnicode (
62 1.1.1.2.4.2 rmind ACPI_PARSE_OBJECT *Op);
63 1.1.1.2.4.2 rmind
64 1.1.1.2.4.2 rmind static void
65 1.1.1.2.4.2 rmind OpcDoEisaId (
66 1.1.1.2.4.2 rmind ACPI_PARSE_OBJECT *Op);
67 1.1.1.2.4.2 rmind
68 1.1.1.2.4.2 rmind static void
69 1.1.1.2.4.2 rmind OpcDoUuId (
70 1.1.1.2.4.2 rmind ACPI_PARSE_OBJECT *Op);
71 1.1.1.2.4.2 rmind
72 1.1.1.2.4.2 rmind
73 1.1.1.2.4.2 rmind /*******************************************************************************
74 1.1.1.2.4.2 rmind *
75 1.1.1.2.4.2 rmind * FUNCTION: OpcAmlOpcodeUpdateWalk
76 1.1.1.2.4.2 rmind *
77 1.1.1.2.4.2 rmind * PARAMETERS: ASL_WALK_CALLBACK
78 1.1.1.2.4.2 rmind *
79 1.1.1.2.4.2 rmind * RETURN: Status
80 1.1.1.2.4.2 rmind *
81 1.1.1.2.4.2 rmind * DESCRIPTION: Opcode update walk, ascending callback
82 1.1.1.2.4.2 rmind *
83 1.1.1.2.4.2 rmind ******************************************************************************/
84 1.1.1.2.4.2 rmind
85 1.1.1.2.4.2 rmind ACPI_STATUS
86 1.1.1.2.4.2 rmind OpcAmlOpcodeUpdateWalk (
87 1.1.1.2.4.2 rmind ACPI_PARSE_OBJECT *Op,
88 1.1.1.2.4.2 rmind UINT32 Level,
89 1.1.1.2.4.2 rmind void *Context)
90 1.1.1.2.4.2 rmind {
91 1.1.1.2.4.2 rmind
92 1.1.1.2.4.2 rmind /*
93 1.1.1.2.4.2 rmind * Handle the Package() case where the actual opcode cannot be determined
94 1.1.1.2.4.2 rmind * until the PackageLength operand has been folded and minimized.
95 1.1.1.2.4.2 rmind * (PackageOp versus VarPackageOp)
96 1.1.1.2.4.2 rmind *
97 1.1.1.2.4.2 rmind * This is (as of ACPI 3.0) the only case where the AML opcode can change
98 1.1.1.2.4.2 rmind * based upon the value of a parameter.
99 1.1.1.2.4.2 rmind *
100 1.1.1.2.4.2 rmind * The parser always inserts a VarPackage opcode, which can possibly be
101 1.1.1.2.4.2 rmind * optimized to a Package opcode.
102 1.1.1.2.4.2 rmind */
103 1.1.1.2.4.2 rmind if (Op->Asl.ParseOpcode == PARSEOP_VAR_PACKAGE)
104 1.1.1.2.4.2 rmind {
105 1.1.1.2.4.2 rmind OpnDoPackage (Op);
106 1.1.1.2.4.2 rmind }
107 1.1.1.2.4.2 rmind
108 1.1.1.2.4.2 rmind return (AE_OK);
109 1.1.1.2.4.2 rmind }
110 1.1.1.2.4.2 rmind
111 1.1.1.2.4.2 rmind
112 1.1.1.2.4.2 rmind /*******************************************************************************
113 1.1.1.2.4.2 rmind *
114 1.1.1.2.4.2 rmind * FUNCTION: OpcAmlOpcodeWalk
115 1.1.1.2.4.2 rmind *
116 1.1.1.2.4.2 rmind * PARAMETERS: ASL_WALK_CALLBACK
117 1.1.1.2.4.2 rmind *
118 1.1.1.2.4.2 rmind * RETURN: Status
119 1.1.1.2.4.2 rmind *
120 1.1.1.2.4.2 rmind * DESCRIPTION: Parse tree walk to generate both the AML opcodes and the AML
121 1.1.1.2.4.2 rmind * operands.
122 1.1.1.2.4.2 rmind *
123 1.1.1.2.4.2 rmind ******************************************************************************/
124 1.1.1.2.4.2 rmind
125 1.1.1.2.4.2 rmind ACPI_STATUS
126 1.1.1.2.4.2 rmind OpcAmlOpcodeWalk (
127 1.1.1.2.4.2 rmind ACPI_PARSE_OBJECT *Op,
128 1.1.1.2.4.2 rmind UINT32 Level,
129 1.1.1.2.4.2 rmind void *Context)
130 1.1.1.2.4.2 rmind {
131 1.1.1.2.4.2 rmind
132 1.1.1.2.4.2 rmind TotalParseNodes++;
133 1.1.1.2.4.2 rmind
134 1.1.1.2.4.2 rmind OpcGenerateAmlOpcode (Op);
135 1.1.1.2.4.2 rmind OpnGenerateAmlOperands (Op);
136 1.1.1.2.4.2 rmind return (AE_OK);
137 1.1.1.2.4.2 rmind }
138 1.1.1.2.4.2 rmind
139 1.1.1.2.4.2 rmind
140 1.1.1.2.4.2 rmind /*******************************************************************************
141 1.1.1.2.4.2 rmind *
142 1.1.1.2.4.2 rmind * FUNCTION: OpcGetIntegerWidth
143 1.1.1.2.4.2 rmind *
144 1.1.1.2.4.2 rmind * PARAMETERS: Op - DEFINITION BLOCK op
145 1.1.1.2.4.2 rmind *
146 1.1.1.2.4.2 rmind * RETURN: none
147 1.1.1.2.4.2 rmind *
148 1.1.1.2.4.2 rmind * DESCRIPTION: Extract integer width from the table revision
149 1.1.1.2.4.2 rmind *
150 1.1.1.2.4.2 rmind ******************************************************************************/
151 1.1.1.2.4.2 rmind
152 1.1.1.2.4.2 rmind void
153 1.1.1.2.4.2 rmind OpcGetIntegerWidth (
154 1.1.1.2.4.2 rmind ACPI_PARSE_OBJECT *Op)
155 1.1.1.2.4.2 rmind {
156 1.1.1.2.4.2 rmind ACPI_PARSE_OBJECT *Child;
157 1.1.1.2.4.2 rmind
158 1.1.1.2.4.2 rmind
159 1.1.1.2.4.2 rmind if (!Op)
160 1.1.1.2.4.2 rmind {
161 1.1.1.2.4.2 rmind return;
162 1.1.1.2.4.2 rmind }
163 1.1.1.2.4.2 rmind
164 1.1.1.2.4.2 rmind if (Gbl_RevisionOverride)
165 1.1.1.2.4.2 rmind {
166 1.1.1.2.4.2 rmind AcpiUtSetIntegerWidth (Gbl_RevisionOverride);
167 1.1.1.2.4.2 rmind }
168 1.1.1.2.4.2 rmind else
169 1.1.1.2.4.2 rmind {
170 1.1.1.2.4.2 rmind Child = Op->Asl.Child;
171 1.1.1.2.4.2 rmind Child = Child->Asl.Next;
172 1.1.1.2.4.2 rmind Child = Child->Asl.Next;
173 1.1.1.2.4.2 rmind
174 1.1.1.2.4.2 rmind /* Use the revision to set the integer width */
175 1.1.1.2.4.2 rmind
176 1.1.1.2.4.2 rmind AcpiUtSetIntegerWidth ((UINT8) Child->Asl.Value.Integer);
177 1.1.1.2.4.2 rmind }
178 1.1.1.2.4.2 rmind }
179 1.1.1.2.4.2 rmind
180 1.1.1.2.4.2 rmind
181 1.1.1.2.4.2 rmind /*******************************************************************************
182 1.1.1.2.4.2 rmind *
183 1.1.1.2.4.2 rmind * FUNCTION: OpcSetOptimalIntegerSize
184 1.1.1.2.4.2 rmind *
185 1.1.1.2.4.2 rmind * PARAMETERS: Op - A parse tree node
186 1.1.1.2.4.2 rmind *
187 1.1.1.2.4.2 rmind * RETURN: Integer width, in bytes. Also sets the node AML opcode to the
188 1.1.1.2.4.2 rmind * optimal integer AML prefix opcode.
189 1.1.1.2.4.2 rmind *
190 1.1.1.2.4.2 rmind * DESCRIPTION: Determine the optimal AML encoding of an integer. All leading
191 1.1.1.2.4.2 rmind * zeros can be truncated to squeeze the integer into the
192 1.1.1.2.4.2 rmind * minimal number of AML bytes.
193 1.1.1.2.4.2 rmind *
194 1.1.1.2.4.2 rmind ******************************************************************************/
195 1.1.1.2.4.2 rmind
196 1.1.1.2.4.2 rmind UINT32
197 1.1.1.2.4.2 rmind OpcSetOptimalIntegerSize (
198 1.1.1.2.4.2 rmind ACPI_PARSE_OBJECT *Op)
199 1.1.1.2.4.2 rmind {
200 1.1.1.2.4.2 rmind
201 1.1.1.2.4.2 rmind #if 0
202 1.1.1.2.4.2 rmind /*
203 1.1.1.2.4.2 rmind * TBD: - we don't want to optimize integers in the block header, but the
204 1.1.1.2.4.2 rmind * code below does not work correctly.
205 1.1.1.2.4.2 rmind */
206 1.1.1.2.4.2 rmind if (Op->Asl.Parent &&
207 1.1.1.2.4.2 rmind Op->Asl.Parent->Asl.Parent &&
208 1.1.1.2.4.2 rmind (Op->Asl.Parent->Asl.Parent->Asl.ParseOpcode == PARSEOP_DEFINITIONBLOCK))
209 1.1.1.2.4.2 rmind {
210 1.1.1.2.4.2 rmind return 0;
211 1.1.1.2.4.2 rmind }
212 1.1.1.2.4.2 rmind #endif
213 1.1.1.2.4.2 rmind
214 1.1.1.2.4.2 rmind /*
215 1.1.1.2.4.2 rmind * Check for the special AML integers first - Zero, One, Ones.
216 1.1.1.2.4.2 rmind * These are single-byte opcodes that are the smallest possible
217 1.1.1.2.4.2 rmind * representation of an integer.
218 1.1.1.2.4.2 rmind *
219 1.1.1.2.4.2 rmind * This optimization is optional.
220 1.1.1.2.4.2 rmind */
221 1.1.1.2.4.2 rmind if (Gbl_IntegerOptimizationFlag)
222 1.1.1.2.4.2 rmind {
223 1.1.1.2.4.2 rmind switch (Op->Asl.Value.Integer)
224 1.1.1.2.4.2 rmind {
225 1.1.1.2.4.2 rmind case 0:
226 1.1.1.2.4.2 rmind
227 1.1.1.2.4.2 rmind Op->Asl.AmlOpcode = AML_ZERO_OP;
228 1.1.1.2.4.2 rmind AslError (ASL_OPTIMIZATION, ASL_MSG_INTEGER_OPTIMIZATION,
229 1.1.1.2.4.2 rmind Op, "Zero");
230 1.1.1.2.4.2 rmind return 1;
231 1.1.1.2.4.2 rmind
232 1.1.1.2.4.2 rmind case 1:
233 1.1.1.2.4.2 rmind
234 1.1.1.2.4.2 rmind Op->Asl.AmlOpcode = AML_ONE_OP;
235 1.1.1.2.4.2 rmind AslError (ASL_OPTIMIZATION, ASL_MSG_INTEGER_OPTIMIZATION,
236 1.1.1.2.4.2 rmind Op, "One");
237 1.1.1.2.4.2 rmind return 1;
238 1.1.1.2.4.2 rmind
239 1.1.1.2.4.2 rmind case ACPI_UINT32_MAX:
240 1.1.1.2.4.2 rmind
241 1.1.1.2.4.2 rmind /* Check for table integer width (32 or 64) */
242 1.1.1.2.4.2 rmind
243 1.1.1.2.4.2 rmind if (AcpiGbl_IntegerByteWidth == 4)
244 1.1.1.2.4.2 rmind {
245 1.1.1.2.4.2 rmind Op->Asl.AmlOpcode = AML_ONES_OP;
246 1.1.1.2.4.2 rmind AslError (ASL_OPTIMIZATION, ASL_MSG_INTEGER_OPTIMIZATION,
247 1.1.1.2.4.2 rmind Op, "Ones");
248 1.1.1.2.4.2 rmind return 1;
249 1.1.1.2.4.2 rmind }
250 1.1.1.2.4.2 rmind break;
251 1.1.1.2.4.2 rmind
252 1.1.1.2.4.2 rmind case ACPI_UINT64_MAX:
253 1.1.1.2.4.2 rmind
254 1.1.1.2.4.2 rmind /* Check for table integer width (32 or 64) */
255 1.1.1.2.4.2 rmind
256 1.1.1.2.4.2 rmind if (AcpiGbl_IntegerByteWidth == 8)
257 1.1.1.2.4.2 rmind {
258 1.1.1.2.4.2 rmind Op->Asl.AmlOpcode = AML_ONES_OP;
259 1.1.1.2.4.2 rmind AslError (ASL_OPTIMIZATION, ASL_MSG_INTEGER_OPTIMIZATION,
260 1.1.1.2.4.2 rmind Op, "Ones");
261 1.1.1.2.4.2 rmind return 1;
262 1.1.1.2.4.2 rmind }
263 1.1.1.2.4.2 rmind break;
264 1.1.1.2.4.2 rmind
265 1.1.1.2.4.2 rmind default:
266 1.1.1.2.4.2 rmind break;
267 1.1.1.2.4.2 rmind }
268 1.1.1.2.4.2 rmind }
269 1.1.1.2.4.2 rmind
270 1.1.1.2.4.2 rmind /* Find the best fit using the various AML integer prefixes */
271 1.1.1.2.4.2 rmind
272 1.1.1.2.4.2 rmind if (Op->Asl.Value.Integer <= ACPI_UINT8_MAX)
273 1.1.1.2.4.2 rmind {
274 1.1.1.2.4.2 rmind Op->Asl.AmlOpcode = AML_BYTE_OP;
275 1.1.1.2.4.2 rmind return 1;
276 1.1.1.2.4.2 rmind }
277 1.1.1.2.4.2 rmind if (Op->Asl.Value.Integer <= ACPI_UINT16_MAX)
278 1.1.1.2.4.2 rmind {
279 1.1.1.2.4.2 rmind Op->Asl.AmlOpcode = AML_WORD_OP;
280 1.1.1.2.4.2 rmind return 2;
281 1.1.1.2.4.2 rmind }
282 1.1.1.2.4.2 rmind if (Op->Asl.Value.Integer <= ACPI_UINT32_MAX)
283 1.1.1.2.4.2 rmind {
284 1.1.1.2.4.2 rmind Op->Asl.AmlOpcode = AML_DWORD_OP;
285 1.1.1.2.4.2 rmind return 4;
286 1.1.1.2.4.2 rmind }
287 1.1.1.2.4.2 rmind else
288 1.1.1.2.4.2 rmind {
289 1.1.1.2.4.2 rmind if (AcpiGbl_IntegerByteWidth == 4)
290 1.1.1.2.4.2 rmind {
291 1.1.1.2.4.2 rmind AslError (ASL_WARNING, ASL_MSG_INTEGER_LENGTH,
292 1.1.1.2.4.2 rmind Op, NULL);
293 1.1.1.2.4.2 rmind
294 1.1.1.2.4.2 rmind if (!Gbl_IgnoreErrors)
295 1.1.1.2.4.2 rmind {
296 1.1.1.2.4.2 rmind /* Truncate the integer to 32-bit */
297 1.1.1.2.4.2 rmind Op->Asl.AmlOpcode = AML_DWORD_OP;
298 1.1.1.2.4.2 rmind return 4;
299 1.1.1.2.4.2 rmind }
300 1.1.1.2.4.2 rmind }
301 1.1.1.2.4.2 rmind
302 1.1.1.2.4.2 rmind Op->Asl.AmlOpcode = AML_QWORD_OP;
303 1.1.1.2.4.2 rmind return 8;
304 1.1.1.2.4.2 rmind }
305 1.1.1.2.4.2 rmind }
306 1.1.1.2.4.2 rmind
307 1.1.1.2.4.2 rmind
308 1.1.1.2.4.2 rmind /*******************************************************************************
309 1.1.1.2.4.2 rmind *
310 1.1.1.2.4.2 rmind * FUNCTION: OpcDoAccessAs
311 1.1.1.2.4.2 rmind *
312 1.1.1.2.4.2 rmind * PARAMETERS: Op - Parse node
313 1.1.1.2.4.2 rmind *
314 1.1.1.2.4.2 rmind * RETURN: None
315 1.1.1.2.4.2 rmind *
316 1.1.1.2.4.2 rmind * DESCRIPTION: Implement the ACCESS_AS ASL keyword.
317 1.1.1.2.4.2 rmind *
318 1.1.1.2.4.2 rmind ******************************************************************************/
319 1.1.1.2.4.2 rmind
320 1.1.1.2.4.2 rmind static void
321 1.1.1.2.4.2 rmind OpcDoAccessAs (
322 1.1.1.2.4.2 rmind ACPI_PARSE_OBJECT *Op)
323 1.1.1.2.4.2 rmind {
324 1.1.1.2.4.2 rmind ACPI_PARSE_OBJECT *Next;
325 1.1.1.2.4.2 rmind
326 1.1.1.2.4.2 rmind
327 1.1.1.2.4.2 rmind Op->Asl.AmlOpcodeLength = 1;
328 1.1.1.2.4.2 rmind Next = Op->Asl.Child;
329 1.1.1.2.4.2 rmind
330 1.1.1.2.4.2 rmind /* First child is the access type */
331 1.1.1.2.4.2 rmind
332 1.1.1.2.4.2 rmind Next->Asl.AmlOpcode = AML_RAW_DATA_BYTE;
333 1.1.1.2.4.2 rmind Next->Asl.ParseOpcode = PARSEOP_RAW_DATA;
334 1.1.1.2.4.2 rmind
335 1.1.1.2.4.2 rmind /* Second child is the optional access attribute */
336 1.1.1.2.4.2 rmind
337 1.1.1.2.4.2 rmind Next = Next->Asl.Next;
338 1.1.1.2.4.2 rmind if (Next->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
339 1.1.1.2.4.2 rmind {
340 1.1.1.2.4.2 rmind Next->Asl.Value.Integer = 0;
341 1.1.1.2.4.2 rmind }
342 1.1.1.2.4.2 rmind Next->Asl.AmlOpcode = AML_RAW_DATA_BYTE;
343 1.1.1.2.4.2 rmind Next->Asl.ParseOpcode = PARSEOP_RAW_DATA;
344 1.1.1.2.4.2 rmind }
345 1.1.1.2.4.2 rmind
346 1.1.1.2.4.2 rmind
347 1.1.1.2.4.2 rmind /*******************************************************************************
348 1.1.1.2.4.2 rmind *
349 1.1.1.2.4.2 rmind * FUNCTION: OpcDoUnicode
350 1.1.1.2.4.2 rmind *
351 1.1.1.2.4.2 rmind * PARAMETERS: Op - Parse node
352 1.1.1.2.4.2 rmind *
353 1.1.1.2.4.2 rmind * RETURN: None
354 1.1.1.2.4.2 rmind *
355 1.1.1.2.4.2 rmind * DESCRIPTION: Implement the UNICODE ASL "macro". Convert the input string
356 1.1.1.2.4.2 rmind * to a unicode buffer. There is no Unicode AML opcode.
357 1.1.1.2.4.2 rmind *
358 1.1.1.2.4.2 rmind * Note: The Unicode string is 16 bits per character, no leading signature,
359 1.1.1.2.4.2 rmind * with a 16-bit terminating NULL.
360 1.1.1.2.4.2 rmind *
361 1.1.1.2.4.2 rmind ******************************************************************************/
362 1.1.1.2.4.2 rmind
363 1.1.1.2.4.2 rmind static void
364 1.1.1.2.4.2 rmind OpcDoUnicode (
365 1.1.1.2.4.2 rmind ACPI_PARSE_OBJECT *Op)
366 1.1.1.2.4.2 rmind {
367 1.1.1.2.4.2 rmind ACPI_PARSE_OBJECT *InitializerOp;
368 1.1.1.2.4.2 rmind UINT32 Length;
369 1.1.1.2.4.2 rmind UINT32 Count;
370 1.1.1.2.4.2 rmind UINT32 i;
371 1.1.1.2.4.2 rmind UINT8 *AsciiString;
372 1.1.1.2.4.2 rmind UINT16 *UnicodeString;
373 1.1.1.2.4.2 rmind ACPI_PARSE_OBJECT *BufferLengthOp;
374 1.1.1.2.4.2 rmind
375 1.1.1.2.4.2 rmind
376 1.1.1.2.4.2 rmind /* Change op into a buffer object */
377 1.1.1.2.4.2 rmind
378 1.1.1.2.4.2 rmind Op->Asl.CompileFlags &= ~NODE_COMPILE_TIME_CONST;
379 1.1.1.2.4.2 rmind Op->Asl.ParseOpcode = PARSEOP_BUFFER;
380 1.1.1.2.4.2 rmind UtSetParseOpName (Op);
381 1.1.1.2.4.2 rmind
382 1.1.1.2.4.2 rmind /* Buffer Length is first, followed by the string */
383 1.1.1.2.4.2 rmind
384 1.1.1.2.4.2 rmind BufferLengthOp = Op->Asl.Child;
385 1.1.1.2.4.2 rmind InitializerOp = BufferLengthOp->Asl.Next;
386 1.1.1.2.4.2 rmind
387 1.1.1.2.4.2 rmind AsciiString = (UINT8 *) InitializerOp->Asl.Value.String;
388 1.1.1.2.4.2 rmind
389 1.1.1.2.4.2 rmind /* Create a new buffer for the Unicode string */
390 1.1.1.2.4.2 rmind
391 1.1.1.2.4.2 rmind Count = strlen (InitializerOp->Asl.Value.String) + 1;
392 1.1.1.2.4.2 rmind Length = Count * sizeof (UINT16);
393 1.1.1.2.4.2 rmind UnicodeString = UtLocalCalloc (Length);
394 1.1.1.2.4.2 rmind
395 1.1.1.2.4.2 rmind /* Convert to Unicode string (including null terminator) */
396 1.1.1.2.4.2 rmind
397 1.1.1.2.4.2 rmind for (i = 0; i < Count; i++)
398 1.1.1.2.4.2 rmind {
399 1.1.1.2.4.2 rmind UnicodeString[i] = (UINT16) AsciiString[i];
400 1.1.1.2.4.2 rmind }
401 1.1.1.2.4.2 rmind
402 1.1.1.2.4.2 rmind /*
403 1.1.1.2.4.2 rmind * Just set the buffer size node to be the buffer length, regardless
404 1.1.1.2.4.2 rmind * of whether it was previously an integer or a default_arg placeholder
405 1.1.1.2.4.2 rmind */
406 1.1.1.2.4.2 rmind BufferLengthOp->Asl.ParseOpcode = PARSEOP_INTEGER;
407 1.1.1.2.4.2 rmind BufferLengthOp->Asl.AmlOpcode = AML_DWORD_OP;
408 1.1.1.2.4.2 rmind BufferLengthOp->Asl.Value.Integer = Length;
409 1.1.1.2.4.2 rmind UtSetParseOpName (BufferLengthOp);
410 1.1.1.2.4.2 rmind
411 1.1.1.2.4.2 rmind (void) OpcSetOptimalIntegerSize (BufferLengthOp);
412 1.1.1.2.4.2 rmind
413 1.1.1.2.4.2 rmind /* The Unicode string is a raw data buffer */
414 1.1.1.2.4.2 rmind
415 1.1.1.2.4.2 rmind InitializerOp->Asl.Value.Buffer = (UINT8 *) UnicodeString;
416 1.1.1.2.4.2 rmind InitializerOp->Asl.AmlOpcode = AML_RAW_DATA_BUFFER;
417 1.1.1.2.4.2 rmind InitializerOp->Asl.AmlLength = Length;
418 1.1.1.2.4.2 rmind InitializerOp->Asl.ParseOpcode = PARSEOP_RAW_DATA;
419 1.1.1.2.4.2 rmind InitializerOp->Asl.Child = NULL;
420 1.1.1.2.4.2 rmind UtSetParseOpName (InitializerOp);
421 1.1.1.2.4.2 rmind }
422 1.1.1.2.4.2 rmind
423 1.1.1.2.4.2 rmind
424 1.1.1.2.4.2 rmind /*******************************************************************************
425 1.1.1.2.4.2 rmind *
426 1.1.1.2.4.2 rmind * FUNCTION: OpcDoEisaId
427 1.1.1.2.4.2 rmind *
428 1.1.1.2.4.2 rmind * PARAMETERS: Op - Parse node
429 1.1.1.2.4.2 rmind *
430 1.1.1.2.4.2 rmind * RETURN: None
431 1.1.1.2.4.2 rmind *
432 1.1.1.2.4.2 rmind * DESCRIPTION: Convert a string EISA ID to numeric representation. See the
433 1.1.1.2.4.2 rmind * Pnp BIOS Specification for details. Here is an excerpt:
434 1.1.1.2.4.2 rmind *
435 1.1.1.2.4.2 rmind * A seven character ASCII representation of the product
436 1.1.1.2.4.2 rmind * identifier compressed into a 32-bit identifier. The seven
437 1.1.1.2.4.2 rmind * character ID consists of a three character manufacturer code,
438 1.1.1.2.4.2 rmind * a three character hexadecimal product identifier, and a one
439 1.1.1.2.4.2 rmind * character hexadecimal revision number. The manufacturer code
440 1.1.1.2.4.2 rmind * is a 3 uppercase character code that is compressed into 3 5-bit
441 1.1.1.2.4.2 rmind * values as follows:
442 1.1.1.2.4.2 rmind * 1) Find hex ASCII value for each letter
443 1.1.1.2.4.2 rmind * 2) Subtract 40h from each ASCII value
444 1.1.1.2.4.2 rmind * 3) Retain 5 least signficant bits for each letter by
445 1.1.1.2.4.2 rmind * discarding upper 3 bits because they are always 0.
446 1.1.1.2.4.2 rmind * 4) Compressed code = concatenate 0 and the 3 5-bit values
447 1.1.1.2.4.2 rmind *
448 1.1.1.2.4.2 rmind * The format of the compressed product identifier is as follows:
449 1.1.1.2.4.2 rmind * Byte 0: Bit 7 - Reserved (0)
450 1.1.1.2.4.2 rmind * Bits 6-2: - 1st character of compressed mfg code
451 1.1.1.2.4.2 rmind * Bits 1-0 - Upper 2 bits of 2nd character of mfg code
452 1.1.1.2.4.2 rmind * Byte 1: Bits 7-5 - Lower 3 bits of 2nd character of mfg code
453 1.1.1.2.4.2 rmind * Bits 4-0 - 3rd character of mfg code
454 1.1.1.2.4.2 rmind * Byte 2: Bits 7-4 - 1st hex digit of product number
455 1.1.1.2.4.2 rmind * Bits 3-0 - 2nd hex digit of product number
456 1.1.1.2.4.2 rmind * Byte 3: Bits 7-4 - 3st hex digit of product number
457 1.1.1.2.4.2 rmind * Bits 3-0 - Hex digit of the revision number
458 1.1.1.2.4.2 rmind *
459 1.1.1.2.4.2 rmind ******************************************************************************/
460 1.1.1.2.4.2 rmind
461 1.1.1.2.4.2 rmind static void
462 1.1.1.2.4.2 rmind OpcDoEisaId (
463 1.1.1.2.4.2 rmind ACPI_PARSE_OBJECT *Op)
464 1.1.1.2.4.2 rmind {
465 1.1.1.2.4.2 rmind UINT32 EisaId = 0;
466 1.1.1.2.4.2 rmind UINT32 BigEndianId;
467 1.1.1.2.4.2 rmind char *InString;
468 1.1.1.2.4.2 rmind ACPI_STATUS Status = AE_OK;
469 1.1.1.2.4.2 rmind UINT32 i;
470 1.1.1.2.4.2 rmind
471 1.1.1.2.4.2 rmind
472 1.1.1.2.4.2 rmind InString = (char *) Op->Asl.Value.String;
473 1.1.1.2.4.2 rmind
474 1.1.1.2.4.2 rmind /*
475 1.1.1.2.4.2 rmind * The EISAID string must be exactly 7 characters and of the form
476 1.1.1.2.4.2 rmind * "UUUXXXX" -- 3 uppercase letters and 4 hex digits (e.g., "PNP0001")
477 1.1.1.2.4.2 rmind */
478 1.1.1.2.4.2 rmind if (ACPI_STRLEN (InString) != 7)
479 1.1.1.2.4.2 rmind {
480 1.1.1.2.4.2 rmind Status = AE_BAD_PARAMETER;
481 1.1.1.2.4.2 rmind }
482 1.1.1.2.4.2 rmind else
483 1.1.1.2.4.2 rmind {
484 1.1.1.2.4.2 rmind /* Check all 7 characters for correct format */
485 1.1.1.2.4.2 rmind
486 1.1.1.2.4.2 rmind for (i = 0; i < 7; i++)
487 1.1.1.2.4.2 rmind {
488 1.1.1.2.4.2 rmind /* First 3 characters must be uppercase letters */
489 1.1.1.2.4.2 rmind
490 1.1.1.2.4.2 rmind if (i < 3)
491 1.1.1.2.4.2 rmind {
492 1.1.1.2.4.2 rmind if (!isupper ((int) InString[i]))
493 1.1.1.2.4.2 rmind {
494 1.1.1.2.4.2 rmind Status = AE_BAD_PARAMETER;
495 1.1.1.2.4.2 rmind }
496 1.1.1.2.4.2 rmind }
497 1.1.1.2.4.2 rmind
498 1.1.1.2.4.2 rmind /* Last 4 characters must be hex digits */
499 1.1.1.2.4.2 rmind
500 1.1.1.2.4.2 rmind else if (!isxdigit ((int) InString[i]))
501 1.1.1.2.4.2 rmind {
502 1.1.1.2.4.2 rmind Status = AE_BAD_PARAMETER;
503 1.1.1.2.4.2 rmind }
504 1.1.1.2.4.2 rmind }
505 1.1.1.2.4.2 rmind }
506 1.1.1.2.4.2 rmind
507 1.1.1.2.4.2 rmind if (ACPI_FAILURE (Status))
508 1.1.1.2.4.2 rmind {
509 1.1.1.2.4.2 rmind AslError (ASL_ERROR, ASL_MSG_INVALID_EISAID, Op, Op->Asl.Value.String);
510 1.1.1.2.4.2 rmind }
511 1.1.1.2.4.2 rmind else
512 1.1.1.2.4.2 rmind {
513 1.1.1.2.4.2 rmind /* Create ID big-endian first (bits are contiguous) */
514 1.1.1.2.4.2 rmind
515 1.1.1.2.4.2 rmind BigEndianId =
516 1.1.1.2.4.2 rmind (UINT32) ((UINT8) (InString[0] - 0x40)) << 26 |
517 1.1.1.2.4.2 rmind (UINT32) ((UINT8) (InString[1] - 0x40)) << 21 |
518 1.1.1.2.4.2 rmind (UINT32) ((UINT8) (InString[2] - 0x40)) << 16 |
519 1.1.1.2.4.2 rmind
520 1.1.1.2.4.2 rmind (UtHexCharToValue (InString[3])) << 12 |
521 1.1.1.2.4.2 rmind (UtHexCharToValue (InString[4])) << 8 |
522 1.1.1.2.4.2 rmind (UtHexCharToValue (InString[5])) << 4 |
523 1.1.1.2.4.2 rmind UtHexCharToValue (InString[6]);
524 1.1.1.2.4.2 rmind
525 1.1.1.2.4.2 rmind /* Swap to little-endian to get final ID (see function header) */
526 1.1.1.2.4.2 rmind
527 1.1.1.2.4.2 rmind EisaId = AcpiUtDwordByteSwap (BigEndianId);
528 1.1.1.2.4.2 rmind }
529 1.1.1.2.4.2 rmind
530 1.1.1.2.4.2 rmind /*
531 1.1.1.2.4.2 rmind * Morph the Op into an integer, regardless of whether there
532 1.1.1.2.4.2 rmind * was an error in the EISAID string
533 1.1.1.2.4.2 rmind */
534 1.1.1.2.4.2 rmind Op->Asl.Value.Integer = EisaId;
535 1.1.1.2.4.2 rmind
536 1.1.1.2.4.2 rmind Op->Asl.CompileFlags &= ~NODE_COMPILE_TIME_CONST;
537 1.1.1.2.4.2 rmind Op->Asl.ParseOpcode = PARSEOP_INTEGER;
538 1.1.1.2.4.2 rmind (void) OpcSetOptimalIntegerSize (Op);
539 1.1.1.2.4.2 rmind
540 1.1.1.2.4.2 rmind /* Op is now an integer */
541 1.1.1.2.4.2 rmind
542 1.1.1.2.4.2 rmind UtSetParseOpName (Op);
543 1.1.1.2.4.2 rmind }
544 1.1.1.2.4.2 rmind
545 1.1.1.2.4.2 rmind
546 1.1.1.2.4.2 rmind /*******************************************************************************
547 1.1.1.2.4.2 rmind *
548 1.1.1.2.4.2 rmind * FUNCTION: OpcDoUiId
549 1.1.1.2.4.2 rmind *
550 1.1.1.2.4.2 rmind * PARAMETERS: Op - Parse node
551 1.1.1.2.4.2 rmind *
552 1.1.1.2.4.2 rmind * RETURN: None
553 1.1.1.2.4.2 rmind *
554 1.1.1.2.4.2 rmind * DESCRIPTION: Convert UUID string to 16-byte buffer
555 1.1.1.2.4.2 rmind *
556 1.1.1.2.4.2 rmind ******************************************************************************/
557 1.1.1.2.4.2 rmind
558 1.1.1.2.4.2 rmind static void
559 1.1.1.2.4.2 rmind OpcDoUuId (
560 1.1.1.2.4.2 rmind ACPI_PARSE_OBJECT *Op)
561 1.1.1.2.4.2 rmind {
562 1.1.1.2.4.2 rmind char *InString;
563 1.1.1.2.4.2 rmind char *Buffer;
564 1.1.1.2.4.2 rmind ACPI_STATUS Status = AE_OK;
565 1.1.1.2.4.2 rmind ACPI_PARSE_OBJECT *NewOp;
566 1.1.1.2.4.2 rmind
567 1.1.1.2.4.2 rmind
568 1.1.1.2.4.2 rmind InString = (char *) Op->Asl.Value.String;
569 1.1.1.2.4.2 rmind Buffer = UtLocalCalloc (16);
570 1.1.1.2.4.2 rmind
571 1.1.1.2.4.2 rmind Status = AuValidateUuid (InString);
572 1.1.1.2.4.2 rmind if (ACPI_FAILURE (Status))
573 1.1.1.2.4.2 rmind {
574 1.1.1.2.4.2 rmind AslError (ASL_ERROR, ASL_MSG_INVALID_UUID, Op, Op->Asl.Value.String);
575 1.1.1.2.4.2 rmind }
576 1.1.1.2.4.2 rmind else
577 1.1.1.2.4.2 rmind {
578 1.1.1.2.4.2 rmind (void) AuConvertStringToUuid (InString, Buffer);
579 1.1.1.2.4.2 rmind }
580 1.1.1.2.4.2 rmind
581 1.1.1.2.4.2 rmind /* Change Op to a Buffer */
582 1.1.1.2.4.2 rmind
583 1.1.1.2.4.2 rmind Op->Asl.ParseOpcode = PARSEOP_BUFFER;
584 1.1.1.2.4.2 rmind Op->Common.AmlOpcode = AML_BUFFER_OP;
585 1.1.1.2.4.2 rmind
586 1.1.1.2.4.2 rmind /* Disable further optimization */
587 1.1.1.2.4.2 rmind
588 1.1.1.2.4.2 rmind Op->Asl.CompileFlags &= ~NODE_COMPILE_TIME_CONST;
589 1.1.1.2.4.2 rmind UtSetParseOpName (Op);
590 1.1.1.2.4.2 rmind
591 1.1.1.2.4.2 rmind /* Child node is the buffer length */
592 1.1.1.2.4.2 rmind
593 1.1.1.2.4.2 rmind NewOp = TrAllocateNode (PARSEOP_INTEGER);
594 1.1.1.2.4.2 rmind
595 1.1.1.2.4.2 rmind NewOp->Asl.AmlOpcode = AML_BYTE_OP;
596 1.1.1.2.4.2 rmind NewOp->Asl.Value.Integer = 16;
597 1.1.1.2.4.2 rmind NewOp->Asl.Parent = Op;
598 1.1.1.2.4.2 rmind
599 1.1.1.2.4.2 rmind Op->Asl.Child = NewOp;
600 1.1.1.2.4.2 rmind Op = NewOp;
601 1.1.1.2.4.2 rmind
602 1.1.1.2.4.2 rmind /* Peer to the child is the raw buffer data */
603 1.1.1.2.4.2 rmind
604 1.1.1.2.4.2 rmind NewOp = TrAllocateNode (PARSEOP_RAW_DATA);
605 1.1.1.2.4.2 rmind NewOp->Asl.AmlOpcode = AML_RAW_DATA_BUFFER;
606 1.1.1.2.4.2 rmind NewOp->Asl.AmlLength = 16;
607 1.1.1.2.4.2 rmind NewOp->Asl.Value.String = (char *) Buffer;
608 1.1.1.2.4.2 rmind NewOp->Asl.Parent = Op->Asl.Parent;
609 1.1.1.2.4.2 rmind
610 1.1.1.2.4.2 rmind Op->Asl.Next = NewOp;
611 1.1.1.2.4.2 rmind }
612 1.1.1.2.4.2 rmind
613 1.1.1.2.4.2 rmind
614 1.1.1.2.4.2 rmind /*******************************************************************************
615 1.1.1.2.4.2 rmind *
616 1.1.1.2.4.2 rmind * FUNCTION: OpcGenerateAmlOpcode
617 1.1.1.2.4.2 rmind *
618 1.1.1.2.4.2 rmind * PARAMETERS: Op - Parse node
619 1.1.1.2.4.2 rmind *
620 1.1.1.2.4.2 rmind * RETURN: None
621 1.1.1.2.4.2 rmind *
622 1.1.1.2.4.2 rmind * DESCRIPTION: Generate the AML opcode associated with the node and its
623 1.1.1.2.4.2 rmind * parse (lex/flex) keyword opcode. Essentially implements
624 1.1.1.2.4.2 rmind * a mapping between the parse opcodes and the actual AML opcodes.
625 1.1.1.2.4.2 rmind *
626 1.1.1.2.4.2 rmind ******************************************************************************/
627 1.1.1.2.4.2 rmind
628 1.1.1.2.4.2 rmind void
629 1.1.1.2.4.2 rmind OpcGenerateAmlOpcode (
630 1.1.1.2.4.2 rmind ACPI_PARSE_OBJECT *Op)
631 1.1.1.2.4.2 rmind {
632 1.1.1.2.4.2 rmind
633 1.1.1.2.4.2 rmind UINT16 Index;
634 1.1.1.2.4.2 rmind
635 1.1.1.2.4.2 rmind
636 1.1.1.2.4.2 rmind Index = (UINT16) (Op->Asl.ParseOpcode - ASL_PARSE_OPCODE_BASE);
637 1.1.1.2.4.2 rmind
638 1.1.1.2.4.2 rmind Op->Asl.AmlOpcode = AslKeywordMapping[Index].AmlOpcode;
639 1.1.1.2.4.2 rmind Op->Asl.AcpiBtype = AslKeywordMapping[Index].AcpiBtype;
640 1.1.1.2.4.2 rmind Op->Asl.CompileFlags |= AslKeywordMapping[Index].Flags;
641 1.1.1.2.4.2 rmind
642 1.1.1.2.4.2 rmind if (!Op->Asl.Value.Integer)
643 1.1.1.2.4.2 rmind {
644 1.1.1.2.4.2 rmind Op->Asl.Value.Integer = AslKeywordMapping[Index].Value;
645 1.1.1.2.4.2 rmind }
646 1.1.1.2.4.2 rmind
647 1.1.1.2.4.2 rmind /* Special handling for some opcodes */
648 1.1.1.2.4.2 rmind
649 1.1.1.2.4.2 rmind switch (Op->Asl.ParseOpcode)
650 1.1.1.2.4.2 rmind {
651 1.1.1.2.4.2 rmind case PARSEOP_INTEGER:
652 1.1.1.2.4.2 rmind /*
653 1.1.1.2.4.2 rmind * Set the opcode based on the size of the integer
654 1.1.1.2.4.2 rmind */
655 1.1.1.2.4.2 rmind (void) OpcSetOptimalIntegerSize (Op);
656 1.1.1.2.4.2 rmind break;
657 1.1.1.2.4.2 rmind
658 1.1.1.2.4.2 rmind case PARSEOP_OFFSET:
659 1.1.1.2.4.2 rmind
660 1.1.1.2.4.2 rmind Op->Asl.AmlOpcodeLength = 1;
661 1.1.1.2.4.2 rmind break;
662 1.1.1.2.4.2 rmind
663 1.1.1.2.4.2 rmind case PARSEOP_ACCESSAS:
664 1.1.1.2.4.2 rmind
665 1.1.1.2.4.2 rmind OpcDoAccessAs (Op);
666 1.1.1.2.4.2 rmind break;
667 1.1.1.2.4.2 rmind
668 1.1.1.2.4.2 rmind case PARSEOP_EISAID:
669 1.1.1.2.4.2 rmind
670 1.1.1.2.4.2 rmind OpcDoEisaId (Op);
671 1.1.1.2.4.2 rmind break;
672 1.1.1.2.4.2 rmind
673 1.1.1.2.4.2 rmind case PARSEOP_TOUUID:
674 1.1.1.2.4.2 rmind
675 1.1.1.2.4.2 rmind OpcDoUuId (Op);
676 1.1.1.2.4.2 rmind break;
677 1.1.1.2.4.2 rmind
678 1.1.1.2.4.2 rmind case PARSEOP_UNICODE:
679 1.1.1.2.4.2 rmind
680 1.1.1.2.4.2 rmind OpcDoUnicode (Op);
681 1.1.1.2.4.2 rmind break;
682 1.1.1.2.4.2 rmind
683 1.1.1.2.4.2 rmind case PARSEOP_INCLUDE:
684 1.1.1.2.4.2 rmind
685 1.1.1.2.4.2 rmind Op->Asl.Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
686 1.1.1.2.4.2 rmind Gbl_HasIncludeFiles = TRUE;
687 1.1.1.2.4.2 rmind break;
688 1.1.1.2.4.2 rmind
689 1.1.1.2.4.2 rmind case PARSEOP_EXTERNAL:
690 1.1.1.2.4.2 rmind
691 1.1.1.2.4.2 rmind Op->Asl.Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
692 1.1.1.2.4.2 rmind Op->Asl.Child->Asl.Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
693 1.1.1.2.4.2 rmind break;
694 1.1.1.2.4.2 rmind
695 1.1.1.2.4.2 rmind default:
696 1.1.1.2.4.2 rmind /* Nothing to do for other opcodes */
697 1.1.1.2.4.2 rmind break;
698 1.1.1.2.4.2 rmind }
699 1.1.1.2.4.2 rmind
700 1.1.1.2.4.2 rmind return;
701 1.1.1.2.4.2 rmind }
702 1.1.1.2.4.2 rmind
703 1.1.1.2.4.2 rmind
704