exmisc.c revision 1.1 1 1.1 jruoho
2 1.1 jruoho /******************************************************************************
3 1.1 jruoho *
4 1.1 jruoho * Module Name: exmisc - ACPI AML (p-code) execution - specific opcodes
5 1.1 jruoho *
6 1.1 jruoho *****************************************************************************/
7 1.1 jruoho
8 1.1 jruoho /******************************************************************************
9 1.1 jruoho *
10 1.1 jruoho * 1. Copyright Notice
11 1.1 jruoho *
12 1.1 jruoho * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
13 1.1 jruoho * All rights reserved.
14 1.1 jruoho *
15 1.1 jruoho * 2. License
16 1.1 jruoho *
17 1.1 jruoho * 2.1. This is your license from Intel Corp. under its intellectual property
18 1.1 jruoho * rights. You may have additional license terms from the party that provided
19 1.1 jruoho * you this software, covering your right to use that party's intellectual
20 1.1 jruoho * property rights.
21 1.1 jruoho *
22 1.1 jruoho * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 1.1 jruoho * copy of the source code appearing in this file ("Covered Code") an
24 1.1 jruoho * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 1.1 jruoho * base code distributed originally by Intel ("Original Intel Code") to copy,
26 1.1 jruoho * make derivatives, distribute, use and display any portion of the Covered
27 1.1 jruoho * Code in any form, with the right to sublicense such rights; and
28 1.1 jruoho *
29 1.1 jruoho * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 1.1 jruoho * license (with the right to sublicense), under only those claims of Intel
31 1.1 jruoho * patents that are infringed by the Original Intel Code, to make, use, sell,
32 1.1 jruoho * offer to sell, and import the Covered Code and derivative works thereof
33 1.1 jruoho * solely to the minimum extent necessary to exercise the above copyright
34 1.1 jruoho * license, and in no event shall the patent license extend to any additions
35 1.1 jruoho * to or modifications of the Original Intel Code. No other license or right
36 1.1 jruoho * is granted directly or by implication, estoppel or otherwise;
37 1.1 jruoho *
38 1.1 jruoho * The above copyright and patent license is granted only if the following
39 1.1 jruoho * conditions are met:
40 1.1 jruoho *
41 1.1 jruoho * 3. Conditions
42 1.1 jruoho *
43 1.1 jruoho * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 1.1 jruoho * Redistribution of source code of any substantial portion of the Covered
45 1.1 jruoho * Code or modification with rights to further distribute source must include
46 1.1 jruoho * the above Copyright Notice, the above License, this list of Conditions,
47 1.1 jruoho * and the following Disclaimer and Export Compliance provision. In addition,
48 1.1 jruoho * Licensee must cause all Covered Code to which Licensee contributes to
49 1.1 jruoho * contain a file documenting the changes Licensee made to create that Covered
50 1.1 jruoho * Code and the date of any change. Licensee must include in that file the
51 1.1 jruoho * documentation of any changes made by any predecessor Licensee. Licensee
52 1.1 jruoho * must include a prominent statement that the modification is derived,
53 1.1 jruoho * directly or indirectly, from Original Intel Code.
54 1.1 jruoho *
55 1.1 jruoho * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 1.1 jruoho * Redistribution of source code of any substantial portion of the Covered
57 1.1 jruoho * Code or modification without rights to further distribute source must
58 1.1 jruoho * include the following Disclaimer and Export Compliance provision in the
59 1.1 jruoho * documentation and/or other materials provided with distribution. In
60 1.1 jruoho * addition, Licensee may not authorize further sublicense of source of any
61 1.1 jruoho * portion of the Covered Code, and must include terms to the effect that the
62 1.1 jruoho * license from Licensee to its licensee is limited to the intellectual
63 1.1 jruoho * property embodied in the software Licensee provides to its licensee, and
64 1.1 jruoho * not to intellectual property embodied in modifications its licensee may
65 1.1 jruoho * make.
66 1.1 jruoho *
67 1.1 jruoho * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 1.1 jruoho * substantial portion of the Covered Code or modification must reproduce the
69 1.1 jruoho * above Copyright Notice, and the following Disclaimer and Export Compliance
70 1.1 jruoho * provision in the documentation and/or other materials provided with the
71 1.1 jruoho * distribution.
72 1.1 jruoho *
73 1.1 jruoho * 3.4. Intel retains all right, title, and interest in and to the Original
74 1.1 jruoho * Intel Code.
75 1.1 jruoho *
76 1.1 jruoho * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 1.1 jruoho * Intel shall be used in advertising or otherwise to promote the sale, use or
78 1.1 jruoho * other dealings in products derived from or relating to the Covered Code
79 1.1 jruoho * without prior written authorization from Intel.
80 1.1 jruoho *
81 1.1 jruoho * 4. Disclaimer and Export Compliance
82 1.1 jruoho *
83 1.1 jruoho * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 1.1 jruoho * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 1.1 jruoho * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 1.1 jruoho * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 1.1 jruoho
88 1.1 jruoho * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
89 1.1 jruoho * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 1.1 jruoho * PARTICULAR PURPOSE.
91 1.1 jruoho *
92 1.1 jruoho * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93 1.1 jruoho * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94 1.1 jruoho * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95 1.1 jruoho * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96 1.1 jruoho * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97 1.1 jruoho * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
98 1.1 jruoho * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 1.1 jruoho * LIMITED REMEDY.
100 1.1 jruoho *
101 1.1 jruoho * 4.3. Licensee shall not export, either directly or indirectly, any of this
102 1.1 jruoho * software or system incorporating such software without first obtaining any
103 1.1 jruoho * required license or other approval from the U. S. Department of Commerce or
104 1.1 jruoho * any other agency or department of the United States Government. In the
105 1.1 jruoho * event Licensee exports any such software from the United States or
106 1.1 jruoho * re-exports any such software from a foreign destination, Licensee shall
107 1.1 jruoho * ensure that the distribution and export/re-export of the software is in
108 1.1 jruoho * compliance with all laws, regulations, orders, or other restrictions of the
109 1.1 jruoho * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110 1.1 jruoho * any of its subsidiaries will export/re-export any technical data, process,
111 1.1 jruoho * software, or service, directly or indirectly, to any country for which the
112 1.1 jruoho * United States government or any agency thereof requires an export license,
113 1.1 jruoho * other governmental approval, or letter of assurance, without first obtaining
114 1.1 jruoho * such license, approval or letter.
115 1.1 jruoho *
116 1.1 jruoho *****************************************************************************/
117 1.1 jruoho
118 1.1 jruoho #define __EXMISC_C__
119 1.1 jruoho
120 1.1 jruoho #include "acpi.h"
121 1.1 jruoho #include "accommon.h"
122 1.1 jruoho #include "acinterp.h"
123 1.1 jruoho #include "amlcode.h"
124 1.1 jruoho #include "amlresrc.h"
125 1.1 jruoho
126 1.1 jruoho
127 1.1 jruoho #define _COMPONENT ACPI_EXECUTER
128 1.1 jruoho ACPI_MODULE_NAME ("exmisc")
129 1.1 jruoho
130 1.1 jruoho
131 1.1 jruoho /*******************************************************************************
132 1.1 jruoho *
133 1.1 jruoho * FUNCTION: AcpiExGetObjectReference
134 1.1 jruoho *
135 1.1 jruoho * PARAMETERS: ObjDesc - Create a reference to this object
136 1.1 jruoho * ReturnDesc - Where to store the reference
137 1.1 jruoho * WalkState - Current state
138 1.1 jruoho *
139 1.1 jruoho * RETURN: Status
140 1.1 jruoho *
141 1.1 jruoho * DESCRIPTION: Obtain and return a "reference" to the target object
142 1.1 jruoho * Common code for the RefOfOp and the CondRefOfOp.
143 1.1 jruoho *
144 1.1 jruoho ******************************************************************************/
145 1.1 jruoho
146 1.1 jruoho ACPI_STATUS
147 1.1 jruoho AcpiExGetObjectReference (
148 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc,
149 1.1 jruoho ACPI_OPERAND_OBJECT **ReturnDesc,
150 1.1 jruoho ACPI_WALK_STATE *WalkState)
151 1.1 jruoho {
152 1.1 jruoho ACPI_OPERAND_OBJECT *ReferenceObj;
153 1.1 jruoho ACPI_OPERAND_OBJECT *ReferencedObj;
154 1.1 jruoho
155 1.1 jruoho
156 1.1 jruoho ACPI_FUNCTION_TRACE_PTR (ExGetObjectReference, ObjDesc);
157 1.1 jruoho
158 1.1 jruoho
159 1.1 jruoho *ReturnDesc = NULL;
160 1.1 jruoho
161 1.1 jruoho switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc))
162 1.1 jruoho {
163 1.1 jruoho case ACPI_DESC_TYPE_OPERAND:
164 1.1 jruoho
165 1.1 jruoho if (ObjDesc->Common.Type != ACPI_TYPE_LOCAL_REFERENCE)
166 1.1 jruoho {
167 1.1 jruoho return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
168 1.1 jruoho }
169 1.1 jruoho
170 1.1 jruoho /*
171 1.1 jruoho * Must be a reference to a Local or Arg
172 1.1 jruoho */
173 1.1 jruoho switch (ObjDesc->Reference.Class)
174 1.1 jruoho {
175 1.1 jruoho case ACPI_REFCLASS_LOCAL:
176 1.1 jruoho case ACPI_REFCLASS_ARG:
177 1.1 jruoho case ACPI_REFCLASS_DEBUG:
178 1.1 jruoho
179 1.1 jruoho /* The referenced object is the pseudo-node for the local/arg */
180 1.1 jruoho
181 1.1 jruoho ReferencedObj = ObjDesc->Reference.Object;
182 1.1 jruoho break;
183 1.1 jruoho
184 1.1 jruoho default:
185 1.1 jruoho
186 1.1 jruoho ACPI_ERROR ((AE_INFO, "Unknown Reference Class 0x%2.2X",
187 1.1 jruoho ObjDesc->Reference.Class));
188 1.1 jruoho return_ACPI_STATUS (AE_AML_INTERNAL);
189 1.1 jruoho }
190 1.1 jruoho break;
191 1.1 jruoho
192 1.1 jruoho
193 1.1 jruoho case ACPI_DESC_TYPE_NAMED:
194 1.1 jruoho
195 1.1 jruoho /*
196 1.1 jruoho * A named reference that has already been resolved to a Node
197 1.1 jruoho */
198 1.1 jruoho ReferencedObj = ObjDesc;
199 1.1 jruoho break;
200 1.1 jruoho
201 1.1 jruoho
202 1.1 jruoho default:
203 1.1 jruoho
204 1.1 jruoho ACPI_ERROR ((AE_INFO, "Invalid descriptor type 0x%X",
205 1.1 jruoho ACPI_GET_DESCRIPTOR_TYPE (ObjDesc)));
206 1.1 jruoho return_ACPI_STATUS (AE_TYPE);
207 1.1 jruoho }
208 1.1 jruoho
209 1.1 jruoho
210 1.1 jruoho /* Create a new reference object */
211 1.1 jruoho
212 1.1 jruoho ReferenceObj = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
213 1.1 jruoho if (!ReferenceObj)
214 1.1 jruoho {
215 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
216 1.1 jruoho }
217 1.1 jruoho
218 1.1 jruoho ReferenceObj->Reference.Class = ACPI_REFCLASS_REFOF;
219 1.1 jruoho ReferenceObj->Reference.Object = ReferencedObj;
220 1.1 jruoho *ReturnDesc = ReferenceObj;
221 1.1 jruoho
222 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
223 1.1 jruoho "Object %p Type [%s], returning Reference %p\n",
224 1.1 jruoho ObjDesc, AcpiUtGetObjectTypeName (ObjDesc), *ReturnDesc));
225 1.1 jruoho
226 1.1 jruoho return_ACPI_STATUS (AE_OK);
227 1.1 jruoho }
228 1.1 jruoho
229 1.1 jruoho
230 1.1 jruoho /*******************************************************************************
231 1.1 jruoho *
232 1.1 jruoho * FUNCTION: AcpiExConcatTemplate
233 1.1 jruoho *
234 1.1 jruoho * PARAMETERS: Operand0 - First source object
235 1.1 jruoho * Operand1 - Second source object
236 1.1 jruoho * ActualReturnDesc - Where to place the return object
237 1.1 jruoho * WalkState - Current walk state
238 1.1 jruoho *
239 1.1 jruoho * RETURN: Status
240 1.1 jruoho *
241 1.1 jruoho * DESCRIPTION: Concatenate two resource templates
242 1.1 jruoho *
243 1.1 jruoho ******************************************************************************/
244 1.1 jruoho
245 1.1 jruoho ACPI_STATUS
246 1.1 jruoho AcpiExConcatTemplate (
247 1.1 jruoho ACPI_OPERAND_OBJECT *Operand0,
248 1.1 jruoho ACPI_OPERAND_OBJECT *Operand1,
249 1.1 jruoho ACPI_OPERAND_OBJECT **ActualReturnDesc,
250 1.1 jruoho ACPI_WALK_STATE *WalkState)
251 1.1 jruoho {
252 1.1 jruoho ACPI_STATUS Status;
253 1.1 jruoho ACPI_OPERAND_OBJECT *ReturnDesc;
254 1.1 jruoho UINT8 *NewBuf;
255 1.1 jruoho UINT8 *EndTag;
256 1.1 jruoho ACPI_SIZE Length0;
257 1.1 jruoho ACPI_SIZE Length1;
258 1.1 jruoho ACPI_SIZE NewLength;
259 1.1 jruoho
260 1.1 jruoho
261 1.1 jruoho ACPI_FUNCTION_TRACE (ExConcatTemplate);
262 1.1 jruoho
263 1.1 jruoho
264 1.1 jruoho /*
265 1.1 jruoho * Find the EndTag descriptor in each resource template.
266 1.1 jruoho * Note1: returned pointers point TO the EndTag, not past it.
267 1.1 jruoho * Note2: zero-length buffers are allowed; treated like one EndTag
268 1.1 jruoho */
269 1.1 jruoho
270 1.1 jruoho /* Get the length of the first resource template */
271 1.1 jruoho
272 1.1 jruoho Status = AcpiUtGetResourceEndTag (Operand0, &EndTag);
273 1.1 jruoho if (ACPI_FAILURE (Status))
274 1.1 jruoho {
275 1.1 jruoho return_ACPI_STATUS (Status);
276 1.1 jruoho }
277 1.1 jruoho
278 1.1 jruoho Length0 = ACPI_PTR_DIFF (EndTag, Operand0->Buffer.Pointer);
279 1.1 jruoho
280 1.1 jruoho /* Get the length of the second resource template */
281 1.1 jruoho
282 1.1 jruoho Status = AcpiUtGetResourceEndTag (Operand1, &EndTag);
283 1.1 jruoho if (ACPI_FAILURE (Status))
284 1.1 jruoho {
285 1.1 jruoho return_ACPI_STATUS (Status);
286 1.1 jruoho }
287 1.1 jruoho
288 1.1 jruoho Length1 = ACPI_PTR_DIFF (EndTag, Operand1->Buffer.Pointer);
289 1.1 jruoho
290 1.1 jruoho /* Combine both lengths, minimum size will be 2 for EndTag */
291 1.1 jruoho
292 1.1 jruoho NewLength = Length0 + Length1 + sizeof (AML_RESOURCE_END_TAG);
293 1.1 jruoho
294 1.1 jruoho /* Create a new buffer object for the result (with one EndTag) */
295 1.1 jruoho
296 1.1 jruoho ReturnDesc = AcpiUtCreateBufferObject (NewLength);
297 1.1 jruoho if (!ReturnDesc)
298 1.1 jruoho {
299 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
300 1.1 jruoho }
301 1.1 jruoho
302 1.1 jruoho /*
303 1.1 jruoho * Copy the templates to the new buffer, 0 first, then 1 follows. One
304 1.1 jruoho * EndTag descriptor is copied from Operand1.
305 1.1 jruoho */
306 1.1 jruoho NewBuf = ReturnDesc->Buffer.Pointer;
307 1.1 jruoho ACPI_MEMCPY (NewBuf, Operand0->Buffer.Pointer, Length0);
308 1.1 jruoho ACPI_MEMCPY (NewBuf + Length0, Operand1->Buffer.Pointer, Length1);
309 1.1 jruoho
310 1.1 jruoho /* Insert EndTag and set the checksum to zero, means "ignore checksum" */
311 1.1 jruoho
312 1.1 jruoho NewBuf[NewLength - 1] = 0;
313 1.1 jruoho NewBuf[NewLength - 2] = ACPI_RESOURCE_NAME_END_TAG | 1;
314 1.1 jruoho
315 1.1 jruoho /* Return the completed resource template */
316 1.1 jruoho
317 1.1 jruoho *ActualReturnDesc = ReturnDesc;
318 1.1 jruoho return_ACPI_STATUS (AE_OK);
319 1.1 jruoho }
320 1.1 jruoho
321 1.1 jruoho
322 1.1 jruoho /*******************************************************************************
323 1.1 jruoho *
324 1.1 jruoho * FUNCTION: AcpiExDoConcatenate
325 1.1 jruoho *
326 1.1 jruoho * PARAMETERS: Operand0 - First source object
327 1.1 jruoho * Operand1 - Second source object
328 1.1 jruoho * ActualReturnDesc - Where to place the return object
329 1.1 jruoho * WalkState - Current walk state
330 1.1 jruoho *
331 1.1 jruoho * RETURN: Status
332 1.1 jruoho *
333 1.1 jruoho * DESCRIPTION: Concatenate two objects OF THE SAME TYPE.
334 1.1 jruoho *
335 1.1 jruoho ******************************************************************************/
336 1.1 jruoho
337 1.1 jruoho ACPI_STATUS
338 1.1 jruoho AcpiExDoConcatenate (
339 1.1 jruoho ACPI_OPERAND_OBJECT *Operand0,
340 1.1 jruoho ACPI_OPERAND_OBJECT *Operand1,
341 1.1 jruoho ACPI_OPERAND_OBJECT **ActualReturnDesc,
342 1.1 jruoho ACPI_WALK_STATE *WalkState)
343 1.1 jruoho {
344 1.1 jruoho ACPI_OPERAND_OBJECT *LocalOperand1 = Operand1;
345 1.1 jruoho ACPI_OPERAND_OBJECT *ReturnDesc;
346 1.1 jruoho char *NewBuf;
347 1.1 jruoho ACPI_STATUS Status;
348 1.1 jruoho
349 1.1 jruoho
350 1.1 jruoho ACPI_FUNCTION_TRACE (ExDoConcatenate);
351 1.1 jruoho
352 1.1 jruoho
353 1.1 jruoho /*
354 1.1 jruoho * Convert the second operand if necessary. The first operand
355 1.1 jruoho * determines the type of the second operand, (See the Data Types
356 1.1 jruoho * section of the ACPI specification.) Both object types are
357 1.1 jruoho * guaranteed to be either Integer/String/Buffer by the operand
358 1.1 jruoho * resolution mechanism.
359 1.1 jruoho */
360 1.1 jruoho switch (Operand0->Common.Type)
361 1.1 jruoho {
362 1.1 jruoho case ACPI_TYPE_INTEGER:
363 1.1 jruoho Status = AcpiExConvertToInteger (Operand1, &LocalOperand1, 16);
364 1.1 jruoho break;
365 1.1 jruoho
366 1.1 jruoho case ACPI_TYPE_STRING:
367 1.1 jruoho Status = AcpiExConvertToString (Operand1, &LocalOperand1,
368 1.1 jruoho ACPI_IMPLICIT_CONVERT_HEX);
369 1.1 jruoho break;
370 1.1 jruoho
371 1.1 jruoho case ACPI_TYPE_BUFFER:
372 1.1 jruoho Status = AcpiExConvertToBuffer (Operand1, &LocalOperand1);
373 1.1 jruoho break;
374 1.1 jruoho
375 1.1 jruoho default:
376 1.1 jruoho ACPI_ERROR ((AE_INFO, "Invalid object type: 0x%X",
377 1.1 jruoho Operand0->Common.Type));
378 1.1 jruoho Status = AE_AML_INTERNAL;
379 1.1 jruoho }
380 1.1 jruoho
381 1.1 jruoho if (ACPI_FAILURE (Status))
382 1.1 jruoho {
383 1.1 jruoho goto Cleanup;
384 1.1 jruoho }
385 1.1 jruoho
386 1.1 jruoho /*
387 1.1 jruoho * Both operands are now known to be the same object type
388 1.1 jruoho * (Both are Integer, String, or Buffer), and we can now perform the
389 1.1 jruoho * concatenation.
390 1.1 jruoho */
391 1.1 jruoho
392 1.1 jruoho /*
393 1.1 jruoho * There are three cases to handle:
394 1.1 jruoho *
395 1.1 jruoho * 1) Two Integers concatenated to produce a new Buffer
396 1.1 jruoho * 2) Two Strings concatenated to produce a new String
397 1.1 jruoho * 3) Two Buffers concatenated to produce a new Buffer
398 1.1 jruoho */
399 1.1 jruoho switch (Operand0->Common.Type)
400 1.1 jruoho {
401 1.1 jruoho case ACPI_TYPE_INTEGER:
402 1.1 jruoho
403 1.1 jruoho /* Result of two Integers is a Buffer */
404 1.1 jruoho /* Need enough buffer space for two integers */
405 1.1 jruoho
406 1.1 jruoho ReturnDesc = AcpiUtCreateBufferObject ((ACPI_SIZE)
407 1.1 jruoho ACPI_MUL_2 (AcpiGbl_IntegerByteWidth));
408 1.1 jruoho if (!ReturnDesc)
409 1.1 jruoho {
410 1.1 jruoho Status = AE_NO_MEMORY;
411 1.1 jruoho goto Cleanup;
412 1.1 jruoho }
413 1.1 jruoho
414 1.1 jruoho NewBuf = (char *) ReturnDesc->Buffer.Pointer;
415 1.1 jruoho
416 1.1 jruoho /* Copy the first integer, LSB first */
417 1.1 jruoho
418 1.1 jruoho ACPI_MEMCPY (NewBuf, &Operand0->Integer.Value,
419 1.1 jruoho AcpiGbl_IntegerByteWidth);
420 1.1 jruoho
421 1.1 jruoho /* Copy the second integer (LSB first) after the first */
422 1.1 jruoho
423 1.1 jruoho ACPI_MEMCPY (NewBuf + AcpiGbl_IntegerByteWidth,
424 1.1 jruoho &LocalOperand1->Integer.Value,
425 1.1 jruoho AcpiGbl_IntegerByteWidth);
426 1.1 jruoho break;
427 1.1 jruoho
428 1.1 jruoho case ACPI_TYPE_STRING:
429 1.1 jruoho
430 1.1 jruoho /* Result of two Strings is a String */
431 1.1 jruoho
432 1.1 jruoho ReturnDesc = AcpiUtCreateStringObject (
433 1.1 jruoho ((ACPI_SIZE) Operand0->String.Length +
434 1.1 jruoho LocalOperand1->String.Length));
435 1.1 jruoho if (!ReturnDesc)
436 1.1 jruoho {
437 1.1 jruoho Status = AE_NO_MEMORY;
438 1.1 jruoho goto Cleanup;
439 1.1 jruoho }
440 1.1 jruoho
441 1.1 jruoho NewBuf = ReturnDesc->String.Pointer;
442 1.1 jruoho
443 1.1 jruoho /* Concatenate the strings */
444 1.1 jruoho
445 1.1 jruoho ACPI_STRCPY (NewBuf, Operand0->String.Pointer);
446 1.1 jruoho ACPI_STRCPY (NewBuf + Operand0->String.Length,
447 1.1 jruoho LocalOperand1->String.Pointer);
448 1.1 jruoho break;
449 1.1 jruoho
450 1.1 jruoho case ACPI_TYPE_BUFFER:
451 1.1 jruoho
452 1.1 jruoho /* Result of two Buffers is a Buffer */
453 1.1 jruoho
454 1.1 jruoho ReturnDesc = AcpiUtCreateBufferObject (
455 1.1 jruoho ((ACPI_SIZE) Operand0->Buffer.Length +
456 1.1 jruoho LocalOperand1->Buffer.Length));
457 1.1 jruoho if (!ReturnDesc)
458 1.1 jruoho {
459 1.1 jruoho Status = AE_NO_MEMORY;
460 1.1 jruoho goto Cleanup;
461 1.1 jruoho }
462 1.1 jruoho
463 1.1 jruoho NewBuf = (char *) ReturnDesc->Buffer.Pointer;
464 1.1 jruoho
465 1.1 jruoho /* Concatenate the buffers */
466 1.1 jruoho
467 1.1 jruoho ACPI_MEMCPY (NewBuf, Operand0->Buffer.Pointer,
468 1.1 jruoho Operand0->Buffer.Length);
469 1.1 jruoho ACPI_MEMCPY (NewBuf + Operand0->Buffer.Length,
470 1.1 jruoho LocalOperand1->Buffer.Pointer,
471 1.1 jruoho LocalOperand1->Buffer.Length);
472 1.1 jruoho break;
473 1.1 jruoho
474 1.1 jruoho default:
475 1.1 jruoho
476 1.1 jruoho /* Invalid object type, should not happen here */
477 1.1 jruoho
478 1.1 jruoho ACPI_ERROR ((AE_INFO, "Invalid object type: 0x%X",
479 1.1 jruoho Operand0->Common.Type));
480 1.1 jruoho Status =AE_AML_INTERNAL;
481 1.1 jruoho goto Cleanup;
482 1.1 jruoho }
483 1.1 jruoho
484 1.1 jruoho *ActualReturnDesc = ReturnDesc;
485 1.1 jruoho
486 1.1 jruoho Cleanup:
487 1.1 jruoho if (LocalOperand1 != Operand1)
488 1.1 jruoho {
489 1.1 jruoho AcpiUtRemoveReference (LocalOperand1);
490 1.1 jruoho }
491 1.1 jruoho return_ACPI_STATUS (Status);
492 1.1 jruoho }
493 1.1 jruoho
494 1.1 jruoho
495 1.1 jruoho /*******************************************************************************
496 1.1 jruoho *
497 1.1 jruoho * FUNCTION: AcpiExDoMathOp
498 1.1 jruoho *
499 1.1 jruoho * PARAMETERS: Opcode - AML opcode
500 1.1 jruoho * Integer0 - Integer operand #0
501 1.1 jruoho * Integer1 - Integer operand #1
502 1.1 jruoho *
503 1.1 jruoho * RETURN: Integer result of the operation
504 1.1 jruoho *
505 1.1 jruoho * DESCRIPTION: Execute a math AML opcode. The purpose of having all of the
506 1.1 jruoho * math functions here is to prevent a lot of pointer dereferencing
507 1.1 jruoho * to obtain the operands.
508 1.1 jruoho *
509 1.1 jruoho ******************************************************************************/
510 1.1 jruoho
511 1.1 jruoho UINT64
512 1.1 jruoho AcpiExDoMathOp (
513 1.1 jruoho UINT16 Opcode,
514 1.1 jruoho UINT64 Integer0,
515 1.1 jruoho UINT64 Integer1)
516 1.1 jruoho {
517 1.1 jruoho
518 1.1 jruoho ACPI_FUNCTION_ENTRY ();
519 1.1 jruoho
520 1.1 jruoho
521 1.1 jruoho switch (Opcode)
522 1.1 jruoho {
523 1.1 jruoho case AML_ADD_OP: /* Add (Integer0, Integer1, Result) */
524 1.1 jruoho
525 1.1 jruoho return (Integer0 + Integer1);
526 1.1 jruoho
527 1.1 jruoho
528 1.1 jruoho case AML_BIT_AND_OP: /* And (Integer0, Integer1, Result) */
529 1.1 jruoho
530 1.1 jruoho return (Integer0 & Integer1);
531 1.1 jruoho
532 1.1 jruoho
533 1.1 jruoho case AML_BIT_NAND_OP: /* NAnd (Integer0, Integer1, Result) */
534 1.1 jruoho
535 1.1 jruoho return (~(Integer0 & Integer1));
536 1.1 jruoho
537 1.1 jruoho
538 1.1 jruoho case AML_BIT_OR_OP: /* Or (Integer0, Integer1, Result) */
539 1.1 jruoho
540 1.1 jruoho return (Integer0 | Integer1);
541 1.1 jruoho
542 1.1 jruoho
543 1.1 jruoho case AML_BIT_NOR_OP: /* NOr (Integer0, Integer1, Result) */
544 1.1 jruoho
545 1.1 jruoho return (~(Integer0 | Integer1));
546 1.1 jruoho
547 1.1 jruoho
548 1.1 jruoho case AML_BIT_XOR_OP: /* XOr (Integer0, Integer1, Result) */
549 1.1 jruoho
550 1.1 jruoho return (Integer0 ^ Integer1);
551 1.1 jruoho
552 1.1 jruoho
553 1.1 jruoho case AML_MULTIPLY_OP: /* Multiply (Integer0, Integer1, Result) */
554 1.1 jruoho
555 1.1 jruoho return (Integer0 * Integer1);
556 1.1 jruoho
557 1.1 jruoho
558 1.1 jruoho case AML_SHIFT_LEFT_OP: /* ShiftLeft (Operand, ShiftCount, Result)*/
559 1.1 jruoho
560 1.1 jruoho /*
561 1.1 jruoho * We need to check if the shiftcount is larger than the integer bit
562 1.1 jruoho * width since the behavior of this is not well-defined in the C language.
563 1.1 jruoho */
564 1.1 jruoho if (Integer1 >= AcpiGbl_IntegerBitWidth)
565 1.1 jruoho {
566 1.1 jruoho return (0);
567 1.1 jruoho }
568 1.1 jruoho return (Integer0 << Integer1);
569 1.1 jruoho
570 1.1 jruoho
571 1.1 jruoho case AML_SHIFT_RIGHT_OP: /* ShiftRight (Operand, ShiftCount, Result) */
572 1.1 jruoho
573 1.1 jruoho /*
574 1.1 jruoho * We need to check if the shiftcount is larger than the integer bit
575 1.1 jruoho * width since the behavior of this is not well-defined in the C language.
576 1.1 jruoho */
577 1.1 jruoho if (Integer1 >= AcpiGbl_IntegerBitWidth)
578 1.1 jruoho {
579 1.1 jruoho return (0);
580 1.1 jruoho }
581 1.1 jruoho return (Integer0 >> Integer1);
582 1.1 jruoho
583 1.1 jruoho
584 1.1 jruoho case AML_SUBTRACT_OP: /* Subtract (Integer0, Integer1, Result) */
585 1.1 jruoho
586 1.1 jruoho return (Integer0 - Integer1);
587 1.1 jruoho
588 1.1 jruoho default:
589 1.1 jruoho
590 1.1 jruoho return (0);
591 1.1 jruoho }
592 1.1 jruoho }
593 1.1 jruoho
594 1.1 jruoho
595 1.1 jruoho /*******************************************************************************
596 1.1 jruoho *
597 1.1 jruoho * FUNCTION: AcpiExDoLogicalNumericOp
598 1.1 jruoho *
599 1.1 jruoho * PARAMETERS: Opcode - AML opcode
600 1.1 jruoho * Integer0 - Integer operand #0
601 1.1 jruoho * Integer1 - Integer operand #1
602 1.1 jruoho * LogicalResult - TRUE/FALSE result of the operation
603 1.1 jruoho *
604 1.1 jruoho * RETURN: Status
605 1.1 jruoho *
606 1.1 jruoho * DESCRIPTION: Execute a logical "Numeric" AML opcode. For these Numeric
607 1.1 jruoho * operators (LAnd and LOr), both operands must be integers.
608 1.1 jruoho *
609 1.1 jruoho * Note: cleanest machine code seems to be produced by the code
610 1.1 jruoho * below, rather than using statements of the form:
611 1.1 jruoho * Result = (Integer0 && Integer1);
612 1.1 jruoho *
613 1.1 jruoho ******************************************************************************/
614 1.1 jruoho
615 1.1 jruoho ACPI_STATUS
616 1.1 jruoho AcpiExDoLogicalNumericOp (
617 1.1 jruoho UINT16 Opcode,
618 1.1 jruoho UINT64 Integer0,
619 1.1 jruoho UINT64 Integer1,
620 1.1 jruoho BOOLEAN *LogicalResult)
621 1.1 jruoho {
622 1.1 jruoho ACPI_STATUS Status = AE_OK;
623 1.1 jruoho BOOLEAN LocalResult = FALSE;
624 1.1 jruoho
625 1.1 jruoho
626 1.1 jruoho ACPI_FUNCTION_TRACE (ExDoLogicalNumericOp);
627 1.1 jruoho
628 1.1 jruoho
629 1.1 jruoho switch (Opcode)
630 1.1 jruoho {
631 1.1 jruoho case AML_LAND_OP: /* LAnd (Integer0, Integer1) */
632 1.1 jruoho
633 1.1 jruoho if (Integer0 && Integer1)
634 1.1 jruoho {
635 1.1 jruoho LocalResult = TRUE;
636 1.1 jruoho }
637 1.1 jruoho break;
638 1.1 jruoho
639 1.1 jruoho case AML_LOR_OP: /* LOr (Integer0, Integer1) */
640 1.1 jruoho
641 1.1 jruoho if (Integer0 || Integer1)
642 1.1 jruoho {
643 1.1 jruoho LocalResult = TRUE;
644 1.1 jruoho }
645 1.1 jruoho break;
646 1.1 jruoho
647 1.1 jruoho default:
648 1.1 jruoho Status = AE_AML_INTERNAL;
649 1.1 jruoho break;
650 1.1 jruoho }
651 1.1 jruoho
652 1.1 jruoho /* Return the logical result and status */
653 1.1 jruoho
654 1.1 jruoho *LogicalResult = LocalResult;
655 1.1 jruoho return_ACPI_STATUS (Status);
656 1.1 jruoho }
657 1.1 jruoho
658 1.1 jruoho
659 1.1 jruoho /*******************************************************************************
660 1.1 jruoho *
661 1.1 jruoho * FUNCTION: AcpiExDoLogicalOp
662 1.1 jruoho *
663 1.1 jruoho * PARAMETERS: Opcode - AML opcode
664 1.1 jruoho * Operand0 - operand #0
665 1.1 jruoho * Operand1 - operand #1
666 1.1 jruoho * LogicalResult - TRUE/FALSE result of the operation
667 1.1 jruoho *
668 1.1 jruoho * RETURN: Status
669 1.1 jruoho *
670 1.1 jruoho * DESCRIPTION: Execute a logical AML opcode. The purpose of having all of the
671 1.1 jruoho * functions here is to prevent a lot of pointer dereferencing
672 1.1 jruoho * to obtain the operands and to simplify the generation of the
673 1.1 jruoho * logical value. For the Numeric operators (LAnd and LOr), both
674 1.1 jruoho * operands must be integers. For the other logical operators,
675 1.1 jruoho * operands can be any combination of Integer/String/Buffer. The
676 1.1 jruoho * first operand determines the type to which the second operand
677 1.1 jruoho * will be converted.
678 1.1 jruoho *
679 1.1 jruoho * Note: cleanest machine code seems to be produced by the code
680 1.1 jruoho * below, rather than using statements of the form:
681 1.1 jruoho * Result = (Operand0 == Operand1);
682 1.1 jruoho *
683 1.1 jruoho ******************************************************************************/
684 1.1 jruoho
685 1.1 jruoho ACPI_STATUS
686 1.1 jruoho AcpiExDoLogicalOp (
687 1.1 jruoho UINT16 Opcode,
688 1.1 jruoho ACPI_OPERAND_OBJECT *Operand0,
689 1.1 jruoho ACPI_OPERAND_OBJECT *Operand1,
690 1.1 jruoho BOOLEAN *LogicalResult)
691 1.1 jruoho {
692 1.1 jruoho ACPI_OPERAND_OBJECT *LocalOperand1 = Operand1;
693 1.1 jruoho UINT64 Integer0;
694 1.1 jruoho UINT64 Integer1;
695 1.1 jruoho UINT32 Length0;
696 1.1 jruoho UINT32 Length1;
697 1.1 jruoho ACPI_STATUS Status = AE_OK;
698 1.1 jruoho BOOLEAN LocalResult = FALSE;
699 1.1 jruoho int Compare;
700 1.1 jruoho
701 1.1 jruoho
702 1.1 jruoho ACPI_FUNCTION_TRACE (ExDoLogicalOp);
703 1.1 jruoho
704 1.1 jruoho
705 1.1 jruoho /*
706 1.1 jruoho * Convert the second operand if necessary. The first operand
707 1.1 jruoho * determines the type of the second operand, (See the Data Types
708 1.1 jruoho * section of the ACPI 3.0+ specification.) Both object types are
709 1.1 jruoho * guaranteed to be either Integer/String/Buffer by the operand
710 1.1 jruoho * resolution mechanism.
711 1.1 jruoho */
712 1.1 jruoho switch (Operand0->Common.Type)
713 1.1 jruoho {
714 1.1 jruoho case ACPI_TYPE_INTEGER:
715 1.1 jruoho Status = AcpiExConvertToInteger (Operand1, &LocalOperand1, 16);
716 1.1 jruoho break;
717 1.1 jruoho
718 1.1 jruoho case ACPI_TYPE_STRING:
719 1.1 jruoho Status = AcpiExConvertToString (Operand1, &LocalOperand1,
720 1.1 jruoho ACPI_IMPLICIT_CONVERT_HEX);
721 1.1 jruoho break;
722 1.1 jruoho
723 1.1 jruoho case ACPI_TYPE_BUFFER:
724 1.1 jruoho Status = AcpiExConvertToBuffer (Operand1, &LocalOperand1);
725 1.1 jruoho break;
726 1.1 jruoho
727 1.1 jruoho default:
728 1.1 jruoho Status = AE_AML_INTERNAL;
729 1.1 jruoho break;
730 1.1 jruoho }
731 1.1 jruoho
732 1.1 jruoho if (ACPI_FAILURE (Status))
733 1.1 jruoho {
734 1.1 jruoho goto Cleanup;
735 1.1 jruoho }
736 1.1 jruoho
737 1.1 jruoho /*
738 1.1 jruoho * Two cases: 1) Both Integers, 2) Both Strings or Buffers
739 1.1 jruoho */
740 1.1 jruoho if (Operand0->Common.Type == ACPI_TYPE_INTEGER)
741 1.1 jruoho {
742 1.1 jruoho /*
743 1.1 jruoho * 1) Both operands are of type integer
744 1.1 jruoho * Note: LocalOperand1 may have changed above
745 1.1 jruoho */
746 1.1 jruoho Integer0 = Operand0->Integer.Value;
747 1.1 jruoho Integer1 = LocalOperand1->Integer.Value;
748 1.1 jruoho
749 1.1 jruoho switch (Opcode)
750 1.1 jruoho {
751 1.1 jruoho case AML_LEQUAL_OP: /* LEqual (Operand0, Operand1) */
752 1.1 jruoho
753 1.1 jruoho if (Integer0 == Integer1)
754 1.1 jruoho {
755 1.1 jruoho LocalResult = TRUE;
756 1.1 jruoho }
757 1.1 jruoho break;
758 1.1 jruoho
759 1.1 jruoho case AML_LGREATER_OP: /* LGreater (Operand0, Operand1) */
760 1.1 jruoho
761 1.1 jruoho if (Integer0 > Integer1)
762 1.1 jruoho {
763 1.1 jruoho LocalResult = TRUE;
764 1.1 jruoho }
765 1.1 jruoho break;
766 1.1 jruoho
767 1.1 jruoho case AML_LLESS_OP: /* LLess (Operand0, Operand1) */
768 1.1 jruoho
769 1.1 jruoho if (Integer0 < Integer1)
770 1.1 jruoho {
771 1.1 jruoho LocalResult = TRUE;
772 1.1 jruoho }
773 1.1 jruoho break;
774 1.1 jruoho
775 1.1 jruoho default:
776 1.1 jruoho Status = AE_AML_INTERNAL;
777 1.1 jruoho break;
778 1.1 jruoho }
779 1.1 jruoho }
780 1.1 jruoho else
781 1.1 jruoho {
782 1.1 jruoho /*
783 1.1 jruoho * 2) Both operands are Strings or both are Buffers
784 1.1 jruoho * Note: Code below takes advantage of common Buffer/String
785 1.1 jruoho * object fields. LocalOperand1 may have changed above. Use
786 1.1 jruoho * memcmp to handle nulls in buffers.
787 1.1 jruoho */
788 1.1 jruoho Length0 = Operand0->Buffer.Length;
789 1.1 jruoho Length1 = LocalOperand1->Buffer.Length;
790 1.1 jruoho
791 1.1 jruoho /* Lexicographic compare: compare the data bytes */
792 1.1 jruoho
793 1.1 jruoho Compare = ACPI_MEMCMP (Operand0->Buffer.Pointer,
794 1.1 jruoho LocalOperand1->Buffer.Pointer,
795 1.1 jruoho (Length0 > Length1) ? Length1 : Length0);
796 1.1 jruoho
797 1.1 jruoho switch (Opcode)
798 1.1 jruoho {
799 1.1 jruoho case AML_LEQUAL_OP: /* LEqual (Operand0, Operand1) */
800 1.1 jruoho
801 1.1 jruoho /* Length and all bytes must be equal */
802 1.1 jruoho
803 1.1 jruoho if ((Length0 == Length1) &&
804 1.1 jruoho (Compare == 0))
805 1.1 jruoho {
806 1.1 jruoho /* Length and all bytes match ==> TRUE */
807 1.1 jruoho
808 1.1 jruoho LocalResult = TRUE;
809 1.1 jruoho }
810 1.1 jruoho break;
811 1.1 jruoho
812 1.1 jruoho case AML_LGREATER_OP: /* LGreater (Operand0, Operand1) */
813 1.1 jruoho
814 1.1 jruoho if (Compare > 0)
815 1.1 jruoho {
816 1.1 jruoho LocalResult = TRUE;
817 1.1 jruoho goto Cleanup; /* TRUE */
818 1.1 jruoho }
819 1.1 jruoho if (Compare < 0)
820 1.1 jruoho {
821 1.1 jruoho goto Cleanup; /* FALSE */
822 1.1 jruoho }
823 1.1 jruoho
824 1.1 jruoho /* Bytes match (to shortest length), compare lengths */
825 1.1 jruoho
826 1.1 jruoho if (Length0 > Length1)
827 1.1 jruoho {
828 1.1 jruoho LocalResult = TRUE;
829 1.1 jruoho }
830 1.1 jruoho break;
831 1.1 jruoho
832 1.1 jruoho case AML_LLESS_OP: /* LLess (Operand0, Operand1) */
833 1.1 jruoho
834 1.1 jruoho if (Compare > 0)
835 1.1 jruoho {
836 1.1 jruoho goto Cleanup; /* FALSE */
837 1.1 jruoho }
838 1.1 jruoho if (Compare < 0)
839 1.1 jruoho {
840 1.1 jruoho LocalResult = TRUE;
841 1.1 jruoho goto Cleanup; /* TRUE */
842 1.1 jruoho }
843 1.1 jruoho
844 1.1 jruoho /* Bytes match (to shortest length), compare lengths */
845 1.1 jruoho
846 1.1 jruoho if (Length0 < Length1)
847 1.1 jruoho {
848 1.1 jruoho LocalResult = TRUE;
849 1.1 jruoho }
850 1.1 jruoho break;
851 1.1 jruoho
852 1.1 jruoho default:
853 1.1 jruoho Status = AE_AML_INTERNAL;
854 1.1 jruoho break;
855 1.1 jruoho }
856 1.1 jruoho }
857 1.1 jruoho
858 1.1 jruoho Cleanup:
859 1.1 jruoho
860 1.1 jruoho /* New object was created if implicit conversion performed - delete */
861 1.1 jruoho
862 1.1 jruoho if (LocalOperand1 != Operand1)
863 1.1 jruoho {
864 1.1 jruoho AcpiUtRemoveReference (LocalOperand1);
865 1.1 jruoho }
866 1.1 jruoho
867 1.1 jruoho /* Return the logical result and status */
868 1.1 jruoho
869 1.1 jruoho *LogicalResult = LocalResult;
870 1.1 jruoho return_ACPI_STATUS (Status);
871 1.1 jruoho }
872 1.1 jruoho
873 1.1 jruoho
874