blob: 00a25f8188f4ba4ce8b17c559bd371e696ab5b50 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001
2/******************************************************************************
3 *
4 * Module Name: exmisc - ACPI AML (p-code) execution - specific opcodes
5 *
6 *****************************************************************************/
7
8/*
9 * Copyright (C) 2000 - 2005, R. Byron Moore
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
30 *
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <acpi/acpi.h>
46#include <acpi/acinterp.h>
47#include <acpi/amlcode.h>
Bob Moore96db2552005-11-02 00:00:00 -050048#include <acpi/amlresrc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#define _COMPONENT ACPI_EXECUTER
Len Brown4be44fc2005-08-05 00:44:28 -040051ACPI_MODULE_NAME("exmisc")
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53/*******************************************************************************
54 *
55 * FUNCTION: acpi_ex_get_object_reference
56 *
57 * PARAMETERS: obj_desc - Create a reference to this object
58 * return_desc - Where to store the reference
59 * walk_state - Current state
60 *
61 * RETURN: Status
62 *
63 * DESCRIPTION: Obtain and return a "reference" to the target object
64 * Common code for the ref_of_op and the cond_ref_of_op.
65 *
66 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -070067acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040068acpi_ex_get_object_reference(union acpi_operand_object *obj_desc,
69 union acpi_operand_object **return_desc,
70 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071{
Len Brown4be44fc2005-08-05 00:44:28 -040072 union acpi_operand_object *reference_obj;
73 union acpi_operand_object *referenced_obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Len Brown4be44fc2005-08-05 00:44:28 -040075 ACPI_FUNCTION_TRACE_PTR("ex_get_object_reference", obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77 *return_desc = NULL;
78
Len Brown4be44fc2005-08-05 00:44:28 -040079 switch (ACPI_GET_DESCRIPTOR_TYPE(obj_desc)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 case ACPI_DESC_TYPE_OPERAND:
81
Len Brown4be44fc2005-08-05 00:44:28 -040082 if (ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_LOCAL_REFERENCE) {
83 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 }
85
86 /*
87 * Must be a reference to a Local or Arg
88 */
89 switch (obj_desc->reference.opcode) {
90 case AML_LOCAL_OP:
91 case AML_ARG_OP:
92 case AML_DEBUG_OP:
93
94 /* The referenced object is the pseudo-node for the local/arg */
95
96 referenced_obj = obj_desc->reference.object;
97 break;
98
99 default:
100
Len Brown4be44fc2005-08-05 00:44:28 -0400101 ACPI_REPORT_ERROR(("Unknown Reference opcode in get_reference %X\n", obj_desc->reference.opcode));
102 return_ACPI_STATUS(AE_AML_INTERNAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 }
104 break;
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 case ACPI_DESC_TYPE_NAMED:
107
108 /*
109 * A named reference that has already been resolved to a Node
110 */
111 referenced_obj = obj_desc;
112 break;
113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 default:
115
Len Brown4be44fc2005-08-05 00:44:28 -0400116 ACPI_REPORT_ERROR(("Invalid descriptor type in get_reference: %X\n", ACPI_GET_DESCRIPTOR_TYPE(obj_desc)));
117 return_ACPI_STATUS(AE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 }
119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 /* Create a new reference object */
121
Len Brown4be44fc2005-08-05 00:44:28 -0400122 reference_obj =
123 acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_REFERENCE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 if (!reference_obj) {
Len Brown4be44fc2005-08-05 00:44:28 -0400125 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 }
127
128 reference_obj->reference.opcode = AML_REF_OF_OP;
129 reference_obj->reference.object = referenced_obj;
130 *return_desc = reference_obj;
131
Len Brown4be44fc2005-08-05 00:44:28 -0400132 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
133 "Object %p Type [%s], returning Reference %p\n",
134 obj_desc, acpi_ut_get_object_type_name(obj_desc),
135 *return_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Len Brown4be44fc2005-08-05 00:44:28 -0400137 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138}
139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140/*******************************************************************************
141 *
142 * FUNCTION: acpi_ex_concat_template
143 *
144 * PARAMETERS: Operand0 - First source object
145 * Operand1 - Second source object
146 * actual_return_desc - Where to place the return object
147 * walk_state - Current walk state
148 *
149 * RETURN: Status
150 *
151 * DESCRIPTION: Concatenate two resource templates
152 *
153 ******************************************************************************/
154
155acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400156acpi_ex_concat_template(union acpi_operand_object *operand0,
157 union acpi_operand_object *operand1,
158 union acpi_operand_object **actual_return_desc,
159 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160{
Bob Moore96db2552005-11-02 00:00:00 -0500161 acpi_status status;
Len Brown4be44fc2005-08-05 00:44:28 -0400162 union acpi_operand_object *return_desc;
163 u8 *new_buf;
Bob Moore96db2552005-11-02 00:00:00 -0500164 u8 *end_tag;
165 acpi_size length0;
Len Brown4be44fc2005-08-05 00:44:28 -0400166 acpi_size length1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
Len Brown4be44fc2005-08-05 00:44:28 -0400168 ACPI_FUNCTION_TRACE("ex_concat_template");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
Bob Moore96db2552005-11-02 00:00:00 -0500170 /*
171 * Find the end_tag descriptor in each resource template.
172 * Note: returned pointers point TO the end_tag, not past it.
173 *
174 * Compute the length of each resource template
175 */
176 status = acpi_ut_get_resource_end_tag(operand0, &end_tag);
177 if (ACPI_FAILURE(status)) {
178 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 }
180
Bob Moore96db2552005-11-02 00:00:00 -0500181 length0 = ACPI_PTR_DIFF(end_tag, operand0->buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
Bob Moore96db2552005-11-02 00:00:00 -0500183 status = acpi_ut_get_resource_end_tag(operand1, &end_tag);
184 if (ACPI_FAILURE(status)) {
185 return_ACPI_STATUS(status);
186 }
187
188 /* Include the end_tag in the second template length */
189
190 length1 = ACPI_PTR_DIFF(end_tag, operand1->buffer.pointer) +
191 sizeof(struct aml_resource_end_tag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
193 /* Create a new buffer object for the result */
194
Bob Moore96db2552005-11-02 00:00:00 -0500195 return_desc = acpi_ut_create_buffer_object(length0 + length1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 if (!return_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400197 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 }
199
Bob Moore96db2552005-11-02 00:00:00 -0500200 /*
201 * Copy the templates to the new buffer, 0 first, then 1 follows. One
202 * end_tag descriptor is copied from Operand1.
203 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 new_buf = return_desc->buffer.pointer;
Bob Moore96db2552005-11-02 00:00:00 -0500205 ACPI_MEMCPY(new_buf, operand0->buffer.pointer, length0);
206 ACPI_MEMCPY(new_buf + length0, operand1->buffer.pointer, length1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
208 /* Compute the new checksum */
209
210 new_buf[return_desc->buffer.length - 1] =
Len Brown4be44fc2005-08-05 00:44:28 -0400211 acpi_ut_generate_checksum(return_desc->buffer.pointer,
212 (return_desc->buffer.length - 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
Bob Moore96db2552005-11-02 00:00:00 -0500214 /* Return the completed resource template */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216 *actual_return_desc = return_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400217 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218}
219
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220/*******************************************************************************
221 *
222 * FUNCTION: acpi_ex_do_concatenate
223 *
224 * PARAMETERS: Operand0 - First source object
225 * Operand1 - Second source object
226 * actual_return_desc - Where to place the return object
227 * walk_state - Current walk state
228 *
229 * RETURN: Status
230 *
231 * DESCRIPTION: Concatenate two objects OF THE SAME TYPE.
232 *
233 ******************************************************************************/
234
235acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400236acpi_ex_do_concatenate(union acpi_operand_object *operand0,
237 union acpi_operand_object *operand1,
238 union acpi_operand_object **actual_return_desc,
239 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240{
Len Brown4be44fc2005-08-05 00:44:28 -0400241 union acpi_operand_object *local_operand1 = operand1;
242 union acpi_operand_object *return_desc;
243 char *new_buf;
244 acpi_status status;
245 acpi_size new_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
Len Brown4be44fc2005-08-05 00:44:28 -0400247 ACPI_FUNCTION_TRACE("ex_do_concatenate");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
249 /*
250 * Convert the second operand if necessary. The first operand
251 * determines the type of the second operand, (See the Data Types
252 * section of the ACPI specification.) Both object types are
253 * guaranteed to be either Integer/String/Buffer by the operand
254 * resolution mechanism.
255 */
Len Brown4be44fc2005-08-05 00:44:28 -0400256 switch (ACPI_GET_OBJECT_TYPE(operand0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 case ACPI_TYPE_INTEGER:
Len Brown4be44fc2005-08-05 00:44:28 -0400258 status =
259 acpi_ex_convert_to_integer(operand1, &local_operand1, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 break;
261
262 case ACPI_TYPE_STRING:
Len Brown4be44fc2005-08-05 00:44:28 -0400263 status = acpi_ex_convert_to_string(operand1, &local_operand1,
264 ACPI_IMPLICIT_CONVERT_HEX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 break;
266
267 case ACPI_TYPE_BUFFER:
Len Brown4be44fc2005-08-05 00:44:28 -0400268 status = acpi_ex_convert_to_buffer(operand1, &local_operand1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 break;
270
271 default:
Len Brown4be44fc2005-08-05 00:44:28 -0400272 ACPI_REPORT_ERROR(("Concat - invalid obj type: %X\n",
273 ACPI_GET_OBJECT_TYPE(operand0)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 status = AE_AML_INTERNAL;
275 }
276
Len Brown4be44fc2005-08-05 00:44:28 -0400277 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 goto cleanup;
279 }
280
281 /*
282 * Both operands are now known to be the same object type
283 * (Both are Integer, String, or Buffer), and we can now perform the
284 * concatenation.
285 */
286
287 /*
288 * There are three cases to handle:
289 *
290 * 1) Two Integers concatenated to produce a new Buffer
291 * 2) Two Strings concatenated to produce a new String
292 * 3) Two Buffers concatenated to produce a new Buffer
293 */
Len Brown4be44fc2005-08-05 00:44:28 -0400294 switch (ACPI_GET_OBJECT_TYPE(operand0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 case ACPI_TYPE_INTEGER:
296
297 /* Result of two Integers is a Buffer */
298 /* Need enough buffer space for two integers */
299
Len Brown4be44fc2005-08-05 00:44:28 -0400300 return_desc = acpi_ut_create_buffer_object((acpi_size)
301 ACPI_MUL_2
302 (acpi_gbl_integer_byte_width));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 if (!return_desc) {
304 status = AE_NO_MEMORY;
305 goto cleanup;
306 }
307
Len Brown4be44fc2005-08-05 00:44:28 -0400308 new_buf = (char *)return_desc->buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
310 /* Copy the first integer, LSB first */
311
Len Brown4be44fc2005-08-05 00:44:28 -0400312 ACPI_MEMCPY(new_buf,
313 &operand0->integer.value,
314 acpi_gbl_integer_byte_width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
316 /* Copy the second integer (LSB first) after the first */
317
Len Brown4be44fc2005-08-05 00:44:28 -0400318 ACPI_MEMCPY(new_buf + acpi_gbl_integer_byte_width,
319 &local_operand1->integer.value,
320 acpi_gbl_integer_byte_width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 break;
322
323 case ACPI_TYPE_STRING:
324
325 /* Result of two Strings is a String */
326
327 new_length = (acpi_size) operand0->string.length +
Len Brown4be44fc2005-08-05 00:44:28 -0400328 (acpi_size) local_operand1->string.length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 if (new_length > ACPI_MAX_STRING_CONVERSION) {
330 status = AE_AML_STRING_LIMIT;
331 goto cleanup;
332 }
333
Len Brown4be44fc2005-08-05 00:44:28 -0400334 return_desc = acpi_ut_create_string_object(new_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 if (!return_desc) {
336 status = AE_NO_MEMORY;
337 goto cleanup;
338 }
339
340 new_buf = return_desc->string.pointer;
341
342 /* Concatenate the strings */
343
Len Brown4be44fc2005-08-05 00:44:28 -0400344 ACPI_STRCPY(new_buf, operand0->string.pointer);
345 ACPI_STRCPY(new_buf + operand0->string.length,
346 local_operand1->string.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 break;
348
349 case ACPI_TYPE_BUFFER:
350
351 /* Result of two Buffers is a Buffer */
352
Len Brown4be44fc2005-08-05 00:44:28 -0400353 return_desc = acpi_ut_create_buffer_object((acpi_size)
354 operand0->buffer.
355 length +
356 (acpi_size)
357 local_operand1->
358 buffer.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 if (!return_desc) {
360 status = AE_NO_MEMORY;
361 goto cleanup;
362 }
363
Len Brown4be44fc2005-08-05 00:44:28 -0400364 new_buf = (char *)return_desc->buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
366 /* Concatenate the buffers */
367
Len Brown4be44fc2005-08-05 00:44:28 -0400368 ACPI_MEMCPY(new_buf,
369 operand0->buffer.pointer, operand0->buffer.length);
370 ACPI_MEMCPY(new_buf + operand0->buffer.length,
371 local_operand1->buffer.pointer,
372 local_operand1->buffer.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 break;
374
375 default:
376
377 /* Invalid object type, should not happen here */
378
Len Brown4be44fc2005-08-05 00:44:28 -0400379 ACPI_REPORT_ERROR(("Concatenate - Invalid object type: %X\n",
380 ACPI_GET_OBJECT_TYPE(operand0)));
381 status = AE_AML_INTERNAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 goto cleanup;
383 }
384
385 *actual_return_desc = return_desc;
386
Len Brown4be44fc2005-08-05 00:44:28 -0400387 cleanup:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 if (local_operand1 != operand1) {
Len Brown4be44fc2005-08-05 00:44:28 -0400389 acpi_ut_remove_reference(local_operand1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 }
Len Brown4be44fc2005-08-05 00:44:28 -0400391 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392}
393
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394/*******************************************************************************
395 *
396 * FUNCTION: acpi_ex_do_math_op
397 *
398 * PARAMETERS: Opcode - AML opcode
399 * Integer0 - Integer operand #0
400 * Integer1 - Integer operand #1
401 *
402 * RETURN: Integer result of the operation
403 *
404 * DESCRIPTION: Execute a math AML opcode. The purpose of having all of the
405 * math functions here is to prevent a lot of pointer dereferencing
406 * to obtain the operands.
407 *
408 ******************************************************************************/
409
410acpi_integer
Len Brown4be44fc2005-08-05 00:44:28 -0400411acpi_ex_do_math_op(u16 opcode, acpi_integer integer0, acpi_integer integer1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412{
413
Len Brown4be44fc2005-08-05 00:44:28 -0400414 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
416 switch (opcode) {
Len Brown4be44fc2005-08-05 00:44:28 -0400417 case AML_ADD_OP: /* Add (Integer0, Integer1, Result) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
419 return (integer0 + integer1);
420
Len Brown4be44fc2005-08-05 00:44:28 -0400421 case AML_BIT_AND_OP: /* And (Integer0, Integer1, Result) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
423 return (integer0 & integer1);
424
Len Brown4be44fc2005-08-05 00:44:28 -0400425 case AML_BIT_NAND_OP: /* NAnd (Integer0, Integer1, Result) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
427 return (~(integer0 & integer1));
428
Len Brown4be44fc2005-08-05 00:44:28 -0400429 case AML_BIT_OR_OP: /* Or (Integer0, Integer1, Result) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
431 return (integer0 | integer1);
432
Len Brown4be44fc2005-08-05 00:44:28 -0400433 case AML_BIT_NOR_OP: /* NOr (Integer0, Integer1, Result) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
435 return (~(integer0 | integer1));
436
Len Brown4be44fc2005-08-05 00:44:28 -0400437 case AML_BIT_XOR_OP: /* XOr (Integer0, Integer1, Result) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
439 return (integer0 ^ integer1);
440
Len Brown4be44fc2005-08-05 00:44:28 -0400441 case AML_MULTIPLY_OP: /* Multiply (Integer0, Integer1, Result) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442
443 return (integer0 * integer1);
444
Len Brown4be44fc2005-08-05 00:44:28 -0400445 case AML_SHIFT_LEFT_OP: /* shift_left (Operand, shift_count, Result) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
447 return (integer0 << integer1);
448
Len Brown4be44fc2005-08-05 00:44:28 -0400449 case AML_SHIFT_RIGHT_OP: /* shift_right (Operand, shift_count, Result) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
451 return (integer0 >> integer1);
452
Len Brown4be44fc2005-08-05 00:44:28 -0400453 case AML_SUBTRACT_OP: /* Subtract (Integer0, Integer1, Result) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
455 return (integer0 - integer1);
456
457 default:
458
459 return (0);
460 }
461}
462
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463/*******************************************************************************
464 *
465 * FUNCTION: acpi_ex_do_logical_numeric_op
466 *
467 * PARAMETERS: Opcode - AML opcode
468 * Integer0 - Integer operand #0
469 * Integer1 - Integer operand #1
470 * logical_result - TRUE/FALSE result of the operation
471 *
472 * RETURN: Status
473 *
474 * DESCRIPTION: Execute a logical "Numeric" AML opcode. For these Numeric
475 * operators (LAnd and LOr), both operands must be integers.
476 *
477 * Note: cleanest machine code seems to be produced by the code
478 * below, rather than using statements of the form:
479 * Result = (Integer0 && Integer1);
480 *
481 ******************************************************************************/
482
483acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400484acpi_ex_do_logical_numeric_op(u16 opcode,
485 acpi_integer integer0,
486 acpi_integer integer1, u8 * logical_result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487{
Len Brown4be44fc2005-08-05 00:44:28 -0400488 acpi_status status = AE_OK;
489 u8 local_result = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Len Brown4be44fc2005-08-05 00:44:28 -0400491 ACPI_FUNCTION_TRACE("ex_do_logical_numeric_op");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
493 switch (opcode) {
Len Brown4be44fc2005-08-05 00:44:28 -0400494 case AML_LAND_OP: /* LAnd (Integer0, Integer1) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
496 if (integer0 && integer1) {
497 local_result = TRUE;
498 }
499 break;
500
Len Brown4be44fc2005-08-05 00:44:28 -0400501 case AML_LOR_OP: /* LOr (Integer0, Integer1) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
503 if (integer0 || integer1) {
504 local_result = TRUE;
505 }
506 break;
507
508 default:
509 status = AE_AML_INTERNAL;
510 break;
511 }
512
513 /* Return the logical result and status */
514
515 *logical_result = local_result;
Len Brown4be44fc2005-08-05 00:44:28 -0400516 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517}
518
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519/*******************************************************************************
520 *
521 * FUNCTION: acpi_ex_do_logical_op
522 *
523 * PARAMETERS: Opcode - AML opcode
524 * Operand0 - operand #0
525 * Operand1 - operand #1
526 * logical_result - TRUE/FALSE result of the operation
527 *
528 * RETURN: Status
529 *
530 * DESCRIPTION: Execute a logical AML opcode. The purpose of having all of the
531 * functions here is to prevent a lot of pointer dereferencing
532 * to obtain the operands and to simplify the generation of the
533 * logical value. For the Numeric operators (LAnd and LOr), both
534 * operands must be integers. For the other logical operators,
535 * operands can be any combination of Integer/String/Buffer. The
536 * first operand determines the type to which the second operand
537 * will be converted.
538 *
539 * Note: cleanest machine code seems to be produced by the code
540 * below, rather than using statements of the form:
541 * Result = (Operand0 == Operand1);
542 *
543 ******************************************************************************/
544
545acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400546acpi_ex_do_logical_op(u16 opcode,
547 union acpi_operand_object *operand0,
548 union acpi_operand_object *operand1, u8 * logical_result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549{
Len Brown4be44fc2005-08-05 00:44:28 -0400550 union acpi_operand_object *local_operand1 = operand1;
551 acpi_integer integer0;
552 acpi_integer integer1;
553 u32 length0;
554 u32 length1;
555 acpi_status status = AE_OK;
556 u8 local_result = FALSE;
557 int compare;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
Len Brown4be44fc2005-08-05 00:44:28 -0400559 ACPI_FUNCTION_TRACE("ex_do_logical_op");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
561 /*
562 * Convert the second operand if necessary. The first operand
563 * determines the type of the second operand, (See the Data Types
564 * section of the ACPI 3.0+ specification.) Both object types are
565 * guaranteed to be either Integer/String/Buffer by the operand
566 * resolution mechanism.
567 */
Len Brown4be44fc2005-08-05 00:44:28 -0400568 switch (ACPI_GET_OBJECT_TYPE(operand0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 case ACPI_TYPE_INTEGER:
Len Brown4be44fc2005-08-05 00:44:28 -0400570 status =
571 acpi_ex_convert_to_integer(operand1, &local_operand1, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 break;
573
574 case ACPI_TYPE_STRING:
Len Brown4be44fc2005-08-05 00:44:28 -0400575 status = acpi_ex_convert_to_string(operand1, &local_operand1,
576 ACPI_IMPLICIT_CONVERT_HEX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 break;
578
579 case ACPI_TYPE_BUFFER:
Len Brown4be44fc2005-08-05 00:44:28 -0400580 status = acpi_ex_convert_to_buffer(operand1, &local_operand1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 break;
582
583 default:
584 status = AE_AML_INTERNAL;
585 break;
586 }
587
Len Brown4be44fc2005-08-05 00:44:28 -0400588 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 goto cleanup;
590 }
591
592 /*
593 * Two cases: 1) Both Integers, 2) Both Strings or Buffers
594 */
Len Brown4be44fc2005-08-05 00:44:28 -0400595 if (ACPI_GET_OBJECT_TYPE(operand0) == ACPI_TYPE_INTEGER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 /*
597 * 1) Both operands are of type integer
598 * Note: local_operand1 may have changed above
599 */
600 integer0 = operand0->integer.value;
601 integer1 = local_operand1->integer.value;
602
603 switch (opcode) {
Len Brown4be44fc2005-08-05 00:44:28 -0400604 case AML_LEQUAL_OP: /* LEqual (Operand0, Operand1) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
606 if (integer0 == integer1) {
607 local_result = TRUE;
608 }
609 break;
610
Len Brown4be44fc2005-08-05 00:44:28 -0400611 case AML_LGREATER_OP: /* LGreater (Operand0, Operand1) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612
613 if (integer0 > integer1) {
614 local_result = TRUE;
615 }
616 break;
617
Len Brown4be44fc2005-08-05 00:44:28 -0400618 case AML_LLESS_OP: /* LLess (Operand0, Operand1) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
620 if (integer0 < integer1) {
621 local_result = TRUE;
622 }
623 break;
624
625 default:
626 status = AE_AML_INTERNAL;
627 break;
628 }
Len Brown4be44fc2005-08-05 00:44:28 -0400629 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 /*
631 * 2) Both operands are Strings or both are Buffers
632 * Note: Code below takes advantage of common Buffer/String
633 * object fields. local_operand1 may have changed above. Use
634 * memcmp to handle nulls in buffers.
635 */
636 length0 = operand0->buffer.length;
637 length1 = local_operand1->buffer.length;
638
639 /* Lexicographic compare: compare the data bytes */
640
Bob Moore08978312005-10-21 00:00:00 -0400641 compare = ACPI_MEMCMP(operand0->buffer.pointer,
642 local_operand1->buffer.pointer,
Len Brown4be44fc2005-08-05 00:44:28 -0400643 (length0 > length1) ? length1 : length0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644
645 switch (opcode) {
Len Brown4be44fc2005-08-05 00:44:28 -0400646 case AML_LEQUAL_OP: /* LEqual (Operand0, Operand1) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
648 /* Length and all bytes must be equal */
649
Len Brown4be44fc2005-08-05 00:44:28 -0400650 if ((length0 == length1) && (compare == 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 /* Length and all bytes match ==> TRUE */
652
653 local_result = TRUE;
654 }
655 break;
656
Len Brown4be44fc2005-08-05 00:44:28 -0400657 case AML_LGREATER_OP: /* LGreater (Operand0, Operand1) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
659 if (compare > 0) {
660 local_result = TRUE;
Len Brown4be44fc2005-08-05 00:44:28 -0400661 goto cleanup; /* TRUE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 }
663 if (compare < 0) {
Len Brown4be44fc2005-08-05 00:44:28 -0400664 goto cleanup; /* FALSE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 }
666
667 /* Bytes match (to shortest length), compare lengths */
668
669 if (length0 > length1) {
670 local_result = TRUE;
671 }
672 break;
673
Len Brown4be44fc2005-08-05 00:44:28 -0400674 case AML_LLESS_OP: /* LLess (Operand0, Operand1) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
676 if (compare > 0) {
Len Brown4be44fc2005-08-05 00:44:28 -0400677 goto cleanup; /* FALSE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 }
679 if (compare < 0) {
680 local_result = TRUE;
Len Brown4be44fc2005-08-05 00:44:28 -0400681 goto cleanup; /* TRUE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 }
683
684 /* Bytes match (to shortest length), compare lengths */
685
686 if (length0 < length1) {
687 local_result = TRUE;
688 }
689 break;
690
691 default:
692 status = AE_AML_INTERNAL;
693 break;
694 }
695 }
696
Len Brown4be44fc2005-08-05 00:44:28 -0400697 cleanup:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
699 /* New object was created if implicit conversion performed - delete */
700
701 if (local_operand1 != operand1) {
Len Brown4be44fc2005-08-05 00:44:28 -0400702 acpi_ut_remove_reference(local_operand1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 }
704
705 /* Return the logical result and status */
706
707 *logical_result = local_result;
Len Brown4be44fc2005-08-05 00:44:28 -0400708 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709}