blob: 0778bff632bf10a4a4c080adcd79d4d7f6d1b282 [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
Bob Moorec51a4de2005-11-17 13:07:00 -0500208 /* Set the end_tag checksum to zero, means "ignore checksum" */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
Bob Moorec51a4de2005-11-17 13:07:00 -0500210 new_buf[return_desc->buffer.length - 1] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Bob Moore96db2552005-11-02 00:00:00 -0500212 /* Return the completed resource template */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
214 *actual_return_desc = return_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400215 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216}
217
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218/*******************************************************************************
219 *
220 * FUNCTION: acpi_ex_do_concatenate
221 *
222 * PARAMETERS: Operand0 - First source object
223 * Operand1 - Second source object
224 * actual_return_desc - Where to place the return object
225 * walk_state - Current walk state
226 *
227 * RETURN: Status
228 *
229 * DESCRIPTION: Concatenate two objects OF THE SAME TYPE.
230 *
231 ******************************************************************************/
232
233acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400234acpi_ex_do_concatenate(union acpi_operand_object *operand0,
235 union acpi_operand_object *operand1,
236 union acpi_operand_object **actual_return_desc,
237 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238{
Len Brown4be44fc2005-08-05 00:44:28 -0400239 union acpi_operand_object *local_operand1 = operand1;
240 union acpi_operand_object *return_desc;
241 char *new_buf;
242 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
Len Brown4be44fc2005-08-05 00:44:28 -0400244 ACPI_FUNCTION_TRACE("ex_do_concatenate");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
246 /*
247 * Convert the second operand if necessary. The first operand
248 * determines the type of the second operand, (See the Data Types
249 * section of the ACPI specification.) Both object types are
250 * guaranteed to be either Integer/String/Buffer by the operand
251 * resolution mechanism.
252 */
Len Brown4be44fc2005-08-05 00:44:28 -0400253 switch (ACPI_GET_OBJECT_TYPE(operand0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 case ACPI_TYPE_INTEGER:
Len Brown4be44fc2005-08-05 00:44:28 -0400255 status =
256 acpi_ex_convert_to_integer(operand1, &local_operand1, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 break;
258
259 case ACPI_TYPE_STRING:
Len Brown4be44fc2005-08-05 00:44:28 -0400260 status = acpi_ex_convert_to_string(operand1, &local_operand1,
261 ACPI_IMPLICIT_CONVERT_HEX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 break;
263
264 case ACPI_TYPE_BUFFER:
Len Brown4be44fc2005-08-05 00:44:28 -0400265 status = acpi_ex_convert_to_buffer(operand1, &local_operand1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 break;
267
268 default:
Bob Moorec51a4de2005-11-17 13:07:00 -0500269 ACPI_REPORT_ERROR(("Concatanate - invalid object type: %X\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400270 ACPI_GET_OBJECT_TYPE(operand0)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 status = AE_AML_INTERNAL;
272 }
273
Len Brown4be44fc2005-08-05 00:44:28 -0400274 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 goto cleanup;
276 }
277
278 /*
279 * Both operands are now known to be the same object type
280 * (Both are Integer, String, or Buffer), and we can now perform the
281 * concatenation.
282 */
283
284 /*
285 * There are three cases to handle:
286 *
287 * 1) Two Integers concatenated to produce a new Buffer
288 * 2) Two Strings concatenated to produce a new String
289 * 3) Two Buffers concatenated to produce a new Buffer
290 */
Len Brown4be44fc2005-08-05 00:44:28 -0400291 switch (ACPI_GET_OBJECT_TYPE(operand0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 case ACPI_TYPE_INTEGER:
293
294 /* Result of two Integers is a Buffer */
295 /* Need enough buffer space for two integers */
296
Len Brown4be44fc2005-08-05 00:44:28 -0400297 return_desc = acpi_ut_create_buffer_object((acpi_size)
298 ACPI_MUL_2
299 (acpi_gbl_integer_byte_width));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 if (!return_desc) {
301 status = AE_NO_MEMORY;
302 goto cleanup;
303 }
304
Len Brown4be44fc2005-08-05 00:44:28 -0400305 new_buf = (char *)return_desc->buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
307 /* Copy the first integer, LSB first */
308
Bob Moorec51a4de2005-11-17 13:07:00 -0500309 ACPI_MEMCPY(new_buf, &operand0->integer.value,
Len Brown4be44fc2005-08-05 00:44:28 -0400310 acpi_gbl_integer_byte_width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
312 /* Copy the second integer (LSB first) after the first */
313
Len Brown4be44fc2005-08-05 00:44:28 -0400314 ACPI_MEMCPY(new_buf + acpi_gbl_integer_byte_width,
315 &local_operand1->integer.value,
316 acpi_gbl_integer_byte_width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 break;
318
319 case ACPI_TYPE_STRING:
320
321 /* Result of two Strings is a String */
322
Bob Moorec51a4de2005-11-17 13:07:00 -0500323 return_desc = acpi_ut_create_string_object((acpi_size)
324 (operand0->string.
325 length +
326 local_operand1->
327 string.length));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 if (!return_desc) {
329 status = AE_NO_MEMORY;
330 goto cleanup;
331 }
332
333 new_buf = return_desc->string.pointer;
334
335 /* Concatenate the strings */
336
Len Brown4be44fc2005-08-05 00:44:28 -0400337 ACPI_STRCPY(new_buf, operand0->string.pointer);
338 ACPI_STRCPY(new_buf + operand0->string.length,
339 local_operand1->string.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 break;
341
342 case ACPI_TYPE_BUFFER:
343
344 /* Result of two Buffers is a Buffer */
345
Len Brown4be44fc2005-08-05 00:44:28 -0400346 return_desc = acpi_ut_create_buffer_object((acpi_size)
Bob Moorec51a4de2005-11-17 13:07:00 -0500347 (operand0->buffer.
348 length +
349 local_operand1->
350 buffer.length));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 if (!return_desc) {
352 status = AE_NO_MEMORY;
353 goto cleanup;
354 }
355
Len Brown4be44fc2005-08-05 00:44:28 -0400356 new_buf = (char *)return_desc->buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
358 /* Concatenate the buffers */
359
Bob Moorec51a4de2005-11-17 13:07:00 -0500360 ACPI_MEMCPY(new_buf, operand0->buffer.pointer,
361 operand0->buffer.length);
Len Brown4be44fc2005-08-05 00:44:28 -0400362 ACPI_MEMCPY(new_buf + operand0->buffer.length,
363 local_operand1->buffer.pointer,
364 local_operand1->buffer.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 break;
366
367 default:
368
369 /* Invalid object type, should not happen here */
370
Len Brown4be44fc2005-08-05 00:44:28 -0400371 ACPI_REPORT_ERROR(("Concatenate - Invalid object type: %X\n",
372 ACPI_GET_OBJECT_TYPE(operand0)));
373 status = AE_AML_INTERNAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 goto cleanup;
375 }
376
377 *actual_return_desc = return_desc;
378
Len Brown4be44fc2005-08-05 00:44:28 -0400379 cleanup:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 if (local_operand1 != operand1) {
Len Brown4be44fc2005-08-05 00:44:28 -0400381 acpi_ut_remove_reference(local_operand1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 }
Len Brown4be44fc2005-08-05 00:44:28 -0400383 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384}
385
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386/*******************************************************************************
387 *
388 * FUNCTION: acpi_ex_do_math_op
389 *
390 * PARAMETERS: Opcode - AML opcode
391 * Integer0 - Integer operand #0
392 * Integer1 - Integer operand #1
393 *
394 * RETURN: Integer result of the operation
395 *
396 * DESCRIPTION: Execute a math AML opcode. The purpose of having all of the
397 * math functions here is to prevent a lot of pointer dereferencing
398 * to obtain the operands.
399 *
400 ******************************************************************************/
401
402acpi_integer
Len Brown4be44fc2005-08-05 00:44:28 -0400403acpi_ex_do_math_op(u16 opcode, acpi_integer integer0, acpi_integer integer1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404{
405
Len Brown4be44fc2005-08-05 00:44:28 -0400406 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
408 switch (opcode) {
Len Brown4be44fc2005-08-05 00:44:28 -0400409 case AML_ADD_OP: /* Add (Integer0, Integer1, Result) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
411 return (integer0 + integer1);
412
Len Brown4be44fc2005-08-05 00:44:28 -0400413 case AML_BIT_AND_OP: /* And (Integer0, Integer1, Result) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
415 return (integer0 & integer1);
416
Len Brown4be44fc2005-08-05 00:44:28 -0400417 case AML_BIT_NAND_OP: /* NAnd (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_OR_OP: /* Or (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_NOR_OP: /* NOr (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_XOR_OP: /* XOr (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_MULTIPLY_OP: /* Multiply (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_SHIFT_LEFT_OP: /* shift_left (Operand, shift_count, Result) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
439 return (integer0 << integer1);
440
Len Brown4be44fc2005-08-05 00:44:28 -0400441 case AML_SHIFT_RIGHT_OP: /* shift_right (Operand, shift_count, Result) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442
443 return (integer0 >> integer1);
444
Len Brown4be44fc2005-08-05 00:44:28 -0400445 case AML_SUBTRACT_OP: /* Subtract (Integer0, Integer1, Result) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
447 return (integer0 - integer1);
448
449 default:
450
451 return (0);
452 }
453}
454
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455/*******************************************************************************
456 *
457 * FUNCTION: acpi_ex_do_logical_numeric_op
458 *
459 * PARAMETERS: Opcode - AML opcode
460 * Integer0 - Integer operand #0
461 * Integer1 - Integer operand #1
462 * logical_result - TRUE/FALSE result of the operation
463 *
464 * RETURN: Status
465 *
466 * DESCRIPTION: Execute a logical "Numeric" AML opcode. For these Numeric
467 * operators (LAnd and LOr), both operands must be integers.
468 *
469 * Note: cleanest machine code seems to be produced by the code
470 * below, rather than using statements of the form:
471 * Result = (Integer0 && Integer1);
472 *
473 ******************************************************************************/
474
475acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400476acpi_ex_do_logical_numeric_op(u16 opcode,
477 acpi_integer integer0,
478 acpi_integer integer1, u8 * logical_result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479{
Len Brown4be44fc2005-08-05 00:44:28 -0400480 acpi_status status = AE_OK;
481 u8 local_result = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
Len Brown4be44fc2005-08-05 00:44:28 -0400483 ACPI_FUNCTION_TRACE("ex_do_logical_numeric_op");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
485 switch (opcode) {
Len Brown4be44fc2005-08-05 00:44:28 -0400486 case AML_LAND_OP: /* LAnd (Integer0, Integer1) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
488 if (integer0 && integer1) {
489 local_result = TRUE;
490 }
491 break;
492
Len Brown4be44fc2005-08-05 00:44:28 -0400493 case AML_LOR_OP: /* LOr (Integer0, Integer1) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
495 if (integer0 || integer1) {
496 local_result = TRUE;
497 }
498 break;
499
500 default:
501 status = AE_AML_INTERNAL;
502 break;
503 }
504
505 /* Return the logical result and status */
506
507 *logical_result = local_result;
Len Brown4be44fc2005-08-05 00:44:28 -0400508 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509}
510
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511/*******************************************************************************
512 *
513 * FUNCTION: acpi_ex_do_logical_op
514 *
515 * PARAMETERS: Opcode - AML opcode
516 * Operand0 - operand #0
517 * Operand1 - operand #1
518 * logical_result - TRUE/FALSE result of the operation
519 *
520 * RETURN: Status
521 *
522 * DESCRIPTION: Execute a logical AML opcode. The purpose of having all of the
523 * functions here is to prevent a lot of pointer dereferencing
524 * to obtain the operands and to simplify the generation of the
525 * logical value. For the Numeric operators (LAnd and LOr), both
526 * operands must be integers. For the other logical operators,
527 * operands can be any combination of Integer/String/Buffer. The
528 * first operand determines the type to which the second operand
529 * will be converted.
530 *
531 * Note: cleanest machine code seems to be produced by the code
532 * below, rather than using statements of the form:
533 * Result = (Operand0 == Operand1);
534 *
535 ******************************************************************************/
536
537acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400538acpi_ex_do_logical_op(u16 opcode,
539 union acpi_operand_object *operand0,
540 union acpi_operand_object *operand1, u8 * logical_result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541{
Len Brown4be44fc2005-08-05 00:44:28 -0400542 union acpi_operand_object *local_operand1 = operand1;
543 acpi_integer integer0;
544 acpi_integer integer1;
545 u32 length0;
546 u32 length1;
547 acpi_status status = AE_OK;
548 u8 local_result = FALSE;
549 int compare;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
Len Brown4be44fc2005-08-05 00:44:28 -0400551 ACPI_FUNCTION_TRACE("ex_do_logical_op");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
553 /*
554 * Convert the second operand if necessary. The first operand
555 * determines the type of the second operand, (See the Data Types
556 * section of the ACPI 3.0+ specification.) Both object types are
557 * guaranteed to be either Integer/String/Buffer by the operand
558 * resolution mechanism.
559 */
Len Brown4be44fc2005-08-05 00:44:28 -0400560 switch (ACPI_GET_OBJECT_TYPE(operand0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 case ACPI_TYPE_INTEGER:
Len Brown4be44fc2005-08-05 00:44:28 -0400562 status =
563 acpi_ex_convert_to_integer(operand1, &local_operand1, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 break;
565
566 case ACPI_TYPE_STRING:
Len Brown4be44fc2005-08-05 00:44:28 -0400567 status = acpi_ex_convert_to_string(operand1, &local_operand1,
568 ACPI_IMPLICIT_CONVERT_HEX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 break;
570
571 case ACPI_TYPE_BUFFER:
Len Brown4be44fc2005-08-05 00:44:28 -0400572 status = acpi_ex_convert_to_buffer(operand1, &local_operand1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 break;
574
575 default:
576 status = AE_AML_INTERNAL;
577 break;
578 }
579
Len Brown4be44fc2005-08-05 00:44:28 -0400580 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 goto cleanup;
582 }
583
584 /*
585 * Two cases: 1) Both Integers, 2) Both Strings or Buffers
586 */
Len Brown4be44fc2005-08-05 00:44:28 -0400587 if (ACPI_GET_OBJECT_TYPE(operand0) == ACPI_TYPE_INTEGER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 /*
589 * 1) Both operands are of type integer
590 * Note: local_operand1 may have changed above
591 */
592 integer0 = operand0->integer.value;
593 integer1 = local_operand1->integer.value;
594
595 switch (opcode) {
Len Brown4be44fc2005-08-05 00:44:28 -0400596 case AML_LEQUAL_OP: /* LEqual (Operand0, Operand1) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
598 if (integer0 == integer1) {
599 local_result = TRUE;
600 }
601 break;
602
Len Brown4be44fc2005-08-05 00:44:28 -0400603 case AML_LGREATER_OP: /* LGreater (Operand0, Operand1) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
605 if (integer0 > integer1) {
606 local_result = TRUE;
607 }
608 break;
609
Len Brown4be44fc2005-08-05 00:44:28 -0400610 case AML_LLESS_OP: /* LLess (Operand0, Operand1) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
612 if (integer0 < integer1) {
613 local_result = TRUE;
614 }
615 break;
616
617 default:
618 status = AE_AML_INTERNAL;
619 break;
620 }
Len Brown4be44fc2005-08-05 00:44:28 -0400621 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 /*
623 * 2) Both operands are Strings or both are Buffers
624 * Note: Code below takes advantage of common Buffer/String
625 * object fields. local_operand1 may have changed above. Use
626 * memcmp to handle nulls in buffers.
627 */
628 length0 = operand0->buffer.length;
629 length1 = local_operand1->buffer.length;
630
631 /* Lexicographic compare: compare the data bytes */
632
Bob Moore08978312005-10-21 00:00:00 -0400633 compare = ACPI_MEMCMP(operand0->buffer.pointer,
634 local_operand1->buffer.pointer,
Len Brown4be44fc2005-08-05 00:44:28 -0400635 (length0 > length1) ? length1 : length0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
637 switch (opcode) {
Len Brown4be44fc2005-08-05 00:44:28 -0400638 case AML_LEQUAL_OP: /* LEqual (Operand0, Operand1) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639
640 /* Length and all bytes must be equal */
641
Len Brown4be44fc2005-08-05 00:44:28 -0400642 if ((length0 == length1) && (compare == 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 /* Length and all bytes match ==> TRUE */
644
645 local_result = TRUE;
646 }
647 break;
648
Len Brown4be44fc2005-08-05 00:44:28 -0400649 case AML_LGREATER_OP: /* LGreater (Operand0, Operand1) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
651 if (compare > 0) {
652 local_result = TRUE;
Len Brown4be44fc2005-08-05 00:44:28 -0400653 goto cleanup; /* TRUE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 }
655 if (compare < 0) {
Len Brown4be44fc2005-08-05 00:44:28 -0400656 goto cleanup; /* FALSE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 }
658
659 /* Bytes match (to shortest length), compare lengths */
660
661 if (length0 > length1) {
662 local_result = TRUE;
663 }
664 break;
665
Len Brown4be44fc2005-08-05 00:44:28 -0400666 case AML_LLESS_OP: /* LLess (Operand0, Operand1) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667
668 if (compare > 0) {
Len Brown4be44fc2005-08-05 00:44:28 -0400669 goto cleanup; /* FALSE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 }
671 if (compare < 0) {
672 local_result = TRUE;
Len Brown4be44fc2005-08-05 00:44:28 -0400673 goto cleanup; /* TRUE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 }
675
676 /* Bytes match (to shortest length), compare lengths */
677
678 if (length0 < length1) {
679 local_result = TRUE;
680 }
681 break;
682
683 default:
684 status = AE_AML_INTERNAL;
685 break;
686 }
687 }
688
Len Brown4be44fc2005-08-05 00:44:28 -0400689 cleanup:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
691 /* New object was created if implicit conversion performed - delete */
692
693 if (local_operand1 != operand1) {
Len Brown4be44fc2005-08-05 00:44:28 -0400694 acpi_ut_remove_reference(local_operand1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 }
696
697 /* Return the logical result and status */
698
699 *logical_result = local_result;
Len Brown4be44fc2005-08-05 00:44:28 -0400700 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701}