Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | |
2 | /****************************************************************************** | |
3 | * | |
4 | * Module Name: exmisc - ACPI AML (p-code) execution - specific opcodes | |
5 | * | |
6 | *****************************************************************************/ | |
7 | ||
8 | /* | |
75a44ce0 | 9 | * Copyright (C) 2000 - 2008, Intel Corp. |
1da177e4 LT |
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 | ||
1da177e4 LT |
45 | #include <acpi/acpi.h> |
46 | #include <acpi/acinterp.h> | |
47 | #include <acpi/amlcode.h> | |
96db255c | 48 | #include <acpi/amlresrc.h> |
1da177e4 | 49 | |
1da177e4 | 50 | #define _COMPONENT ACPI_EXECUTER |
4be44fcd | 51 | ACPI_MODULE_NAME("exmisc") |
1da177e4 LT |
52 | |
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 | ******************************************************************************/ | |
1da177e4 | 67 | acpi_status |
4be44fcd LB |
68 | acpi_ex_get_object_reference(union acpi_operand_object *obj_desc, |
69 | union acpi_operand_object **return_desc, | |
70 | struct acpi_walk_state *walk_state) | |
1da177e4 | 71 | { |
4be44fcd LB |
72 | union acpi_operand_object *reference_obj; |
73 | union acpi_operand_object *referenced_obj; | |
1da177e4 | 74 | |
b229cf92 | 75 | ACPI_FUNCTION_TRACE_PTR(ex_get_object_reference, obj_desc); |
1da177e4 LT |
76 | |
77 | *return_desc = NULL; | |
78 | ||
4be44fcd | 79 | switch (ACPI_GET_DESCRIPTOR_TYPE(obj_desc)) { |
1da177e4 LT |
80 | case ACPI_DESC_TYPE_OPERAND: |
81 | ||
4be44fcd LB |
82 | if (ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_LOCAL_REFERENCE) { |
83 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); | |
1da177e4 LT |
84 | } |
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 | ||
b8e4d893 BM |
101 | ACPI_ERROR((AE_INFO, "Unknown Reference opcode %X", |
102 | obj_desc->reference.opcode)); | |
4be44fcd | 103 | return_ACPI_STATUS(AE_AML_INTERNAL); |
1da177e4 LT |
104 | } |
105 | break; | |
106 | ||
1da177e4 LT |
107 | case ACPI_DESC_TYPE_NAMED: |
108 | ||
109 | /* | |
110 | * A named reference that has already been resolved to a Node | |
111 | */ | |
112 | referenced_obj = obj_desc; | |
113 | break; | |
114 | ||
1da177e4 LT |
115 | default: |
116 | ||
b8e4d893 BM |
117 | ACPI_ERROR((AE_INFO, "Invalid descriptor type %X", |
118 | ACPI_GET_DESCRIPTOR_TYPE(obj_desc))); | |
4be44fcd | 119 | return_ACPI_STATUS(AE_TYPE); |
1da177e4 LT |
120 | } |
121 | ||
1da177e4 LT |
122 | /* Create a new reference object */ |
123 | ||
4be44fcd LB |
124 | reference_obj = |
125 | acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_REFERENCE); | |
1da177e4 | 126 | if (!reference_obj) { |
4be44fcd | 127 | return_ACPI_STATUS(AE_NO_MEMORY); |
1da177e4 LT |
128 | } |
129 | ||
130 | reference_obj->reference.opcode = AML_REF_OF_OP; | |
131 | reference_obj->reference.object = referenced_obj; | |
132 | *return_desc = reference_obj; | |
133 | ||
4be44fcd LB |
134 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
135 | "Object %p Type [%s], returning Reference %p\n", | |
136 | obj_desc, acpi_ut_get_object_type_name(obj_desc), | |
137 | *return_desc)); | |
1da177e4 | 138 | |
4be44fcd | 139 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
140 | } |
141 | ||
1da177e4 LT |
142 | /******************************************************************************* |
143 | * | |
144 | * FUNCTION: acpi_ex_concat_template | |
145 | * | |
146 | * PARAMETERS: Operand0 - First source object | |
147 | * Operand1 - Second source object | |
148 | * actual_return_desc - Where to place the return object | |
149 | * walk_state - Current walk state | |
150 | * | |
151 | * RETURN: Status | |
152 | * | |
153 | * DESCRIPTION: Concatenate two resource templates | |
154 | * | |
155 | ******************************************************************************/ | |
156 | ||
157 | acpi_status | |
4be44fcd LB |
158 | acpi_ex_concat_template(union acpi_operand_object *operand0, |
159 | union acpi_operand_object *operand1, | |
160 | union acpi_operand_object **actual_return_desc, | |
161 | struct acpi_walk_state *walk_state) | |
1da177e4 | 162 | { |
96db255c | 163 | acpi_status status; |
4be44fcd LB |
164 | union acpi_operand_object *return_desc; |
165 | u8 *new_buf; | |
96db255c BM |
166 | u8 *end_tag; |
167 | acpi_size length0; | |
4be44fcd | 168 | acpi_size length1; |
b8e4d893 | 169 | acpi_size new_length; |
1da177e4 | 170 | |
b229cf92 | 171 | ACPI_FUNCTION_TRACE(ex_concat_template); |
1da177e4 | 172 | |
96db255c BM |
173 | /* |
174 | * Find the end_tag descriptor in each resource template. | |
b8e4d893 BM |
175 | * Note1: returned pointers point TO the end_tag, not past it. |
176 | * Note2: zero-length buffers are allowed; treated like one end_tag | |
96db255c | 177 | */ |
b8e4d893 BM |
178 | |
179 | /* Get the length of the first resource template */ | |
180 | ||
96db255c BM |
181 | status = acpi_ut_get_resource_end_tag(operand0, &end_tag); |
182 | if (ACPI_FAILURE(status)) { | |
183 | return_ACPI_STATUS(status); | |
184 | } | |
185 | ||
186 | length0 = ACPI_PTR_DIFF(end_tag, operand0->buffer.pointer); | |
1da177e4 | 187 | |
b8e4d893 BM |
188 | /* Get the length of the second resource template */ |
189 | ||
96db255c BM |
190 | status = acpi_ut_get_resource_end_tag(operand1, &end_tag); |
191 | if (ACPI_FAILURE(status)) { | |
192 | return_ACPI_STATUS(status); | |
1da177e4 LT |
193 | } |
194 | ||
b8e4d893 BM |
195 | length1 = ACPI_PTR_DIFF(end_tag, operand1->buffer.pointer); |
196 | ||
197 | /* Combine both lengths, minimum size will be 2 for end_tag */ | |
1da177e4 | 198 | |
b8e4d893 | 199 | new_length = length0 + length1 + sizeof(struct aml_resource_end_tag); |
1da177e4 | 200 | |
b8e4d893 | 201 | /* Create a new buffer object for the result (with one end_tag) */ |
1da177e4 | 202 | |
b8e4d893 | 203 | return_desc = acpi_ut_create_buffer_object(new_length); |
1da177e4 | 204 | if (!return_desc) { |
4be44fcd | 205 | return_ACPI_STATUS(AE_NO_MEMORY); |
1da177e4 LT |
206 | } |
207 | ||
96db255c BM |
208 | /* |
209 | * Copy the templates to the new buffer, 0 first, then 1 follows. One | |
210 | * end_tag descriptor is copied from Operand1. | |
211 | */ | |
1da177e4 | 212 | new_buf = return_desc->buffer.pointer; |
96db255c BM |
213 | ACPI_MEMCPY(new_buf, operand0->buffer.pointer, length0); |
214 | ACPI_MEMCPY(new_buf + length0, operand1->buffer.pointer, length1); | |
1da177e4 | 215 | |
b8e4d893 | 216 | /* Insert end_tag and set the checksum to zero, means "ignore checksum" */ |
1da177e4 | 217 | |
b8e4d893 BM |
218 | new_buf[new_length - 1] = 0; |
219 | new_buf[new_length - 2] = ACPI_RESOURCE_NAME_END_TAG | 1; | |
1da177e4 | 220 | |
96db255c | 221 | /* Return the completed resource template */ |
1da177e4 LT |
222 | |
223 | *actual_return_desc = return_desc; | |
4be44fcd | 224 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
225 | } |
226 | ||
1da177e4 LT |
227 | /******************************************************************************* |
228 | * | |
229 | * FUNCTION: acpi_ex_do_concatenate | |
230 | * | |
231 | * PARAMETERS: Operand0 - First source object | |
232 | * Operand1 - Second source object | |
233 | * actual_return_desc - Where to place the return object | |
234 | * walk_state - Current walk state | |
235 | * | |
236 | * RETURN: Status | |
237 | * | |
238 | * DESCRIPTION: Concatenate two objects OF THE SAME TYPE. | |
239 | * | |
240 | ******************************************************************************/ | |
241 | ||
242 | acpi_status | |
4be44fcd LB |
243 | acpi_ex_do_concatenate(union acpi_operand_object *operand0, |
244 | union acpi_operand_object *operand1, | |
245 | union acpi_operand_object **actual_return_desc, | |
246 | struct acpi_walk_state *walk_state) | |
1da177e4 | 247 | { |
4be44fcd LB |
248 | union acpi_operand_object *local_operand1 = operand1; |
249 | union acpi_operand_object *return_desc; | |
250 | char *new_buf; | |
251 | acpi_status status; | |
1da177e4 | 252 | |
b229cf92 | 253 | ACPI_FUNCTION_TRACE(ex_do_concatenate); |
1da177e4 LT |
254 | |
255 | /* | |
256 | * Convert the second operand if necessary. The first operand | |
257 | * determines the type of the second operand, (See the Data Types | |
258 | * section of the ACPI specification.) Both object types are | |
259 | * guaranteed to be either Integer/String/Buffer by the operand | |
260 | * resolution mechanism. | |
261 | */ | |
4be44fcd | 262 | switch (ACPI_GET_OBJECT_TYPE(operand0)) { |
1da177e4 | 263 | case ACPI_TYPE_INTEGER: |
4be44fcd LB |
264 | status = |
265 | acpi_ex_convert_to_integer(operand1, &local_operand1, 16); | |
1da177e4 LT |
266 | break; |
267 | ||
268 | case ACPI_TYPE_STRING: | |
4be44fcd LB |
269 | status = acpi_ex_convert_to_string(operand1, &local_operand1, |
270 | ACPI_IMPLICIT_CONVERT_HEX); | |
1da177e4 LT |
271 | break; |
272 | ||
273 | case ACPI_TYPE_BUFFER: | |
4be44fcd | 274 | status = acpi_ex_convert_to_buffer(operand1, &local_operand1); |
1da177e4 LT |
275 | break; |
276 | ||
277 | default: | |
b8e4d893 BM |
278 | ACPI_ERROR((AE_INFO, "Invalid object type: %X", |
279 | ACPI_GET_OBJECT_TYPE(operand0))); | |
1da177e4 LT |
280 | status = AE_AML_INTERNAL; |
281 | } | |
282 | ||
4be44fcd | 283 | if (ACPI_FAILURE(status)) { |
1da177e4 LT |
284 | goto cleanup; |
285 | } | |
286 | ||
287 | /* | |
288 | * Both operands are now known to be the same object type | |
289 | * (Both are Integer, String, or Buffer), and we can now perform the | |
290 | * concatenation. | |
291 | */ | |
292 | ||
293 | /* | |
294 | * There are three cases to handle: | |
295 | * | |
296 | * 1) Two Integers concatenated to produce a new Buffer | |
297 | * 2) Two Strings concatenated to produce a new String | |
298 | * 3) Two Buffers concatenated to produce a new Buffer | |
299 | */ | |
4be44fcd | 300 | switch (ACPI_GET_OBJECT_TYPE(operand0)) { |
1da177e4 LT |
301 | case ACPI_TYPE_INTEGER: |
302 | ||
303 | /* Result of two Integers is a Buffer */ | |
304 | /* Need enough buffer space for two integers */ | |
305 | ||
4be44fcd LB |
306 | return_desc = acpi_ut_create_buffer_object((acpi_size) |
307 | ACPI_MUL_2 | |
308 | (acpi_gbl_integer_byte_width)); | |
1da177e4 LT |
309 | if (!return_desc) { |
310 | status = AE_NO_MEMORY; | |
311 | goto cleanup; | |
312 | } | |
313 | ||
4be44fcd | 314 | new_buf = (char *)return_desc->buffer.pointer; |
1da177e4 LT |
315 | |
316 | /* Copy the first integer, LSB first */ | |
317 | ||
c51a4de8 | 318 | ACPI_MEMCPY(new_buf, &operand0->integer.value, |
4be44fcd | 319 | acpi_gbl_integer_byte_width); |
1da177e4 LT |
320 | |
321 | /* Copy the second integer (LSB first) after the first */ | |
322 | ||
4be44fcd LB |
323 | ACPI_MEMCPY(new_buf + acpi_gbl_integer_byte_width, |
324 | &local_operand1->integer.value, | |
325 | acpi_gbl_integer_byte_width); | |
1da177e4 LT |
326 | break; |
327 | ||
328 | case ACPI_TYPE_STRING: | |
329 | ||
330 | /* Result of two Strings is a String */ | |
331 | ||
c51a4de8 BM |
332 | return_desc = acpi_ut_create_string_object((acpi_size) |
333 | (operand0->string. | |
334 | length + | |
335 | local_operand1-> | |
336 | string.length)); | |
1da177e4 LT |
337 | if (!return_desc) { |
338 | status = AE_NO_MEMORY; | |
339 | goto cleanup; | |
340 | } | |
341 | ||
342 | new_buf = return_desc->string.pointer; | |
343 | ||
344 | /* Concatenate the strings */ | |
345 | ||
4be44fcd LB |
346 | ACPI_STRCPY(new_buf, operand0->string.pointer); |
347 | ACPI_STRCPY(new_buf + operand0->string.length, | |
348 | local_operand1->string.pointer); | |
1da177e4 LT |
349 | break; |
350 | ||
351 | case ACPI_TYPE_BUFFER: | |
352 | ||
353 | /* Result of two Buffers is a Buffer */ | |
354 | ||
4be44fcd | 355 | return_desc = acpi_ut_create_buffer_object((acpi_size) |
c51a4de8 BM |
356 | (operand0->buffer. |
357 | length + | |
358 | local_operand1-> | |
359 | buffer.length)); | |
1da177e4 LT |
360 | if (!return_desc) { |
361 | status = AE_NO_MEMORY; | |
362 | goto cleanup; | |
363 | } | |
364 | ||
4be44fcd | 365 | new_buf = (char *)return_desc->buffer.pointer; |
1da177e4 LT |
366 | |
367 | /* Concatenate the buffers */ | |
368 | ||
c51a4de8 BM |
369 | ACPI_MEMCPY(new_buf, operand0->buffer.pointer, |
370 | operand0->buffer.length); | |
4be44fcd LB |
371 | ACPI_MEMCPY(new_buf + operand0->buffer.length, |
372 | local_operand1->buffer.pointer, | |
373 | local_operand1->buffer.length); | |
1da177e4 LT |
374 | break; |
375 | ||
376 | default: | |
377 | ||
378 | /* Invalid object type, should not happen here */ | |
379 | ||
b8e4d893 BM |
380 | ACPI_ERROR((AE_INFO, "Invalid object type: %X", |
381 | ACPI_GET_OBJECT_TYPE(operand0))); | |
4be44fcd | 382 | status = AE_AML_INTERNAL; |
1da177e4 LT |
383 | goto cleanup; |
384 | } | |
385 | ||
386 | *actual_return_desc = return_desc; | |
387 | ||
4be44fcd | 388 | cleanup: |
1da177e4 | 389 | if (local_operand1 != operand1) { |
4be44fcd | 390 | acpi_ut_remove_reference(local_operand1); |
1da177e4 | 391 | } |
4be44fcd | 392 | return_ACPI_STATUS(status); |
1da177e4 LT |
393 | } |
394 | ||
1da177e4 LT |
395 | /******************************************************************************* |
396 | * | |
397 | * FUNCTION: acpi_ex_do_math_op | |
398 | * | |
399 | * PARAMETERS: Opcode - AML opcode | |
400 | * Integer0 - Integer operand #0 | |
401 | * Integer1 - Integer operand #1 | |
402 | * | |
403 | * RETURN: Integer result of the operation | |
404 | * | |
405 | * DESCRIPTION: Execute a math AML opcode. The purpose of having all of the | |
406 | * math functions here is to prevent a lot of pointer dereferencing | |
407 | * to obtain the operands. | |
408 | * | |
409 | ******************************************************************************/ | |
410 | ||
411 | acpi_integer | |
4be44fcd | 412 | acpi_ex_do_math_op(u16 opcode, acpi_integer integer0, acpi_integer integer1) |
1da177e4 LT |
413 | { |
414 | ||
4be44fcd | 415 | ACPI_FUNCTION_ENTRY(); |
1da177e4 LT |
416 | |
417 | switch (opcode) { | |
4be44fcd | 418 | case AML_ADD_OP: /* Add (Integer0, Integer1, Result) */ |
1da177e4 LT |
419 | |
420 | return (integer0 + integer1); | |
421 | ||
4be44fcd | 422 | case AML_BIT_AND_OP: /* And (Integer0, Integer1, Result) */ |
1da177e4 LT |
423 | |
424 | return (integer0 & integer1); | |
425 | ||
4be44fcd | 426 | case AML_BIT_NAND_OP: /* NAnd (Integer0, Integer1, Result) */ |
1da177e4 LT |
427 | |
428 | return (~(integer0 & integer1)); | |
429 | ||
4be44fcd | 430 | case AML_BIT_OR_OP: /* Or (Integer0, Integer1, Result) */ |
1da177e4 LT |
431 | |
432 | return (integer0 | integer1); | |
433 | ||
4be44fcd | 434 | case AML_BIT_NOR_OP: /* NOr (Integer0, Integer1, Result) */ |
1da177e4 LT |
435 | |
436 | return (~(integer0 | integer1)); | |
437 | ||
4be44fcd | 438 | case AML_BIT_XOR_OP: /* XOr (Integer0, Integer1, Result) */ |
1da177e4 LT |
439 | |
440 | return (integer0 ^ integer1); | |
441 | ||
4be44fcd | 442 | case AML_MULTIPLY_OP: /* Multiply (Integer0, Integer1, Result) */ |
1da177e4 LT |
443 | |
444 | return (integer0 * integer1); | |
445 | ||
4be44fcd | 446 | case AML_SHIFT_LEFT_OP: /* shift_left (Operand, shift_count, Result) */ |
1da177e4 | 447 | |
4119532c BM |
448 | /* |
449 | * We need to check if the shiftcount is larger than the integer bit | |
450 | * width since the behavior of this is not well-defined in the C language. | |
451 | */ | |
452 | if (integer1 >= acpi_gbl_integer_bit_width) { | |
453 | return (0); | |
454 | } | |
1da177e4 LT |
455 | return (integer0 << integer1); |
456 | ||
4be44fcd | 457 | case AML_SHIFT_RIGHT_OP: /* shift_right (Operand, shift_count, Result) */ |
1da177e4 | 458 | |
4119532c BM |
459 | /* |
460 | * We need to check if the shiftcount is larger than the integer bit | |
461 | * width since the behavior of this is not well-defined in the C language. | |
462 | */ | |
463 | if (integer1 >= acpi_gbl_integer_bit_width) { | |
464 | return (0); | |
465 | } | |
1da177e4 LT |
466 | return (integer0 >> integer1); |
467 | ||
4be44fcd | 468 | case AML_SUBTRACT_OP: /* Subtract (Integer0, Integer1, Result) */ |
1da177e4 LT |
469 | |
470 | return (integer0 - integer1); | |
471 | ||
472 | default: | |
473 | ||
474 | return (0); | |
475 | } | |
476 | } | |
477 | ||
1da177e4 LT |
478 | /******************************************************************************* |
479 | * | |
480 | * FUNCTION: acpi_ex_do_logical_numeric_op | |
481 | * | |
482 | * PARAMETERS: Opcode - AML opcode | |
483 | * Integer0 - Integer operand #0 | |
484 | * Integer1 - Integer operand #1 | |
485 | * logical_result - TRUE/FALSE result of the operation | |
486 | * | |
487 | * RETURN: Status | |
488 | * | |
489 | * DESCRIPTION: Execute a logical "Numeric" AML opcode. For these Numeric | |
490 | * operators (LAnd and LOr), both operands must be integers. | |
491 | * | |
492 | * Note: cleanest machine code seems to be produced by the code | |
493 | * below, rather than using statements of the form: | |
494 | * Result = (Integer0 && Integer1); | |
495 | * | |
496 | ******************************************************************************/ | |
497 | ||
498 | acpi_status | |
4be44fcd LB |
499 | acpi_ex_do_logical_numeric_op(u16 opcode, |
500 | acpi_integer integer0, | |
501 | acpi_integer integer1, u8 * logical_result) | |
1da177e4 | 502 | { |
4be44fcd LB |
503 | acpi_status status = AE_OK; |
504 | u8 local_result = FALSE; | |
1da177e4 | 505 | |
b229cf92 | 506 | ACPI_FUNCTION_TRACE(ex_do_logical_numeric_op); |
1da177e4 LT |
507 | |
508 | switch (opcode) { | |
4be44fcd | 509 | case AML_LAND_OP: /* LAnd (Integer0, Integer1) */ |
1da177e4 LT |
510 | |
511 | if (integer0 && integer1) { | |
512 | local_result = TRUE; | |
513 | } | |
514 | break; | |
515 | ||
4be44fcd | 516 | case AML_LOR_OP: /* LOr (Integer0, Integer1) */ |
1da177e4 LT |
517 | |
518 | if (integer0 || integer1) { | |
519 | local_result = TRUE; | |
520 | } | |
521 | break; | |
522 | ||
523 | default: | |
524 | status = AE_AML_INTERNAL; | |
525 | break; | |
526 | } | |
527 | ||
528 | /* Return the logical result and status */ | |
529 | ||
530 | *logical_result = local_result; | |
4be44fcd | 531 | return_ACPI_STATUS(status); |
1da177e4 LT |
532 | } |
533 | ||
1da177e4 LT |
534 | /******************************************************************************* |
535 | * | |
536 | * FUNCTION: acpi_ex_do_logical_op | |
537 | * | |
538 | * PARAMETERS: Opcode - AML opcode | |
539 | * Operand0 - operand #0 | |
540 | * Operand1 - operand #1 | |
541 | * logical_result - TRUE/FALSE result of the operation | |
542 | * | |
543 | * RETURN: Status | |
544 | * | |
545 | * DESCRIPTION: Execute a logical AML opcode. The purpose of having all of the | |
546 | * functions here is to prevent a lot of pointer dereferencing | |
547 | * to obtain the operands and to simplify the generation of the | |
548 | * logical value. For the Numeric operators (LAnd and LOr), both | |
549 | * operands must be integers. For the other logical operators, | |
550 | * operands can be any combination of Integer/String/Buffer. The | |
551 | * first operand determines the type to which the second operand | |
552 | * will be converted. | |
553 | * | |
554 | * Note: cleanest machine code seems to be produced by the code | |
555 | * below, rather than using statements of the form: | |
556 | * Result = (Operand0 == Operand1); | |
557 | * | |
558 | ******************************************************************************/ | |
559 | ||
560 | acpi_status | |
4be44fcd LB |
561 | acpi_ex_do_logical_op(u16 opcode, |
562 | union acpi_operand_object *operand0, | |
563 | union acpi_operand_object *operand1, u8 * logical_result) | |
1da177e4 | 564 | { |
4be44fcd LB |
565 | union acpi_operand_object *local_operand1 = operand1; |
566 | acpi_integer integer0; | |
567 | acpi_integer integer1; | |
568 | u32 length0; | |
569 | u32 length1; | |
570 | acpi_status status = AE_OK; | |
571 | u8 local_result = FALSE; | |
572 | int compare; | |
1da177e4 | 573 | |
b229cf92 | 574 | ACPI_FUNCTION_TRACE(ex_do_logical_op); |
1da177e4 LT |
575 | |
576 | /* | |
577 | * Convert the second operand if necessary. The first operand | |
578 | * determines the type of the second operand, (See the Data Types | |
579 | * section of the ACPI 3.0+ specification.) Both object types are | |
580 | * guaranteed to be either Integer/String/Buffer by the operand | |
581 | * resolution mechanism. | |
582 | */ | |
4be44fcd | 583 | switch (ACPI_GET_OBJECT_TYPE(operand0)) { |
1da177e4 | 584 | case ACPI_TYPE_INTEGER: |
4be44fcd LB |
585 | status = |
586 | acpi_ex_convert_to_integer(operand1, &local_operand1, 16); | |
1da177e4 LT |
587 | break; |
588 | ||
589 | case ACPI_TYPE_STRING: | |
4be44fcd LB |
590 | status = acpi_ex_convert_to_string(operand1, &local_operand1, |
591 | ACPI_IMPLICIT_CONVERT_HEX); | |
1da177e4 LT |
592 | break; |
593 | ||
594 | case ACPI_TYPE_BUFFER: | |
4be44fcd | 595 | status = acpi_ex_convert_to_buffer(operand1, &local_operand1); |
1da177e4 LT |
596 | break; |
597 | ||
598 | default: | |
599 | status = AE_AML_INTERNAL; | |
600 | break; | |
601 | } | |
602 | ||
4be44fcd | 603 | if (ACPI_FAILURE(status)) { |
1da177e4 LT |
604 | goto cleanup; |
605 | } | |
606 | ||
607 | /* | |
608 | * Two cases: 1) Both Integers, 2) Both Strings or Buffers | |
609 | */ | |
4be44fcd | 610 | if (ACPI_GET_OBJECT_TYPE(operand0) == ACPI_TYPE_INTEGER) { |
1da177e4 LT |
611 | /* |
612 | * 1) Both operands are of type integer | |
613 | * Note: local_operand1 may have changed above | |
614 | */ | |
615 | integer0 = operand0->integer.value; | |
616 | integer1 = local_operand1->integer.value; | |
617 | ||
618 | switch (opcode) { | |
4be44fcd | 619 | case AML_LEQUAL_OP: /* LEqual (Operand0, Operand1) */ |
1da177e4 LT |
620 | |
621 | if (integer0 == integer1) { | |
622 | local_result = TRUE; | |
623 | } | |
624 | break; | |
625 | ||
4be44fcd | 626 | case AML_LGREATER_OP: /* LGreater (Operand0, Operand1) */ |
1da177e4 LT |
627 | |
628 | if (integer0 > integer1) { | |
629 | local_result = TRUE; | |
630 | } | |
631 | break; | |
632 | ||
4be44fcd | 633 | case AML_LLESS_OP: /* LLess (Operand0, Operand1) */ |
1da177e4 LT |
634 | |
635 | if (integer0 < integer1) { | |
636 | local_result = TRUE; | |
637 | } | |
638 | break; | |
639 | ||
640 | default: | |
641 | status = AE_AML_INTERNAL; | |
642 | break; | |
643 | } | |
4be44fcd | 644 | } else { |
1da177e4 LT |
645 | /* |
646 | * 2) Both operands are Strings or both are Buffers | |
647 | * Note: Code below takes advantage of common Buffer/String | |
648 | * object fields. local_operand1 may have changed above. Use | |
649 | * memcmp to handle nulls in buffers. | |
650 | */ | |
651 | length0 = operand0->buffer.length; | |
652 | length1 = local_operand1->buffer.length; | |
653 | ||
654 | /* Lexicographic compare: compare the data bytes */ | |
655 | ||
0897831b BM |
656 | compare = ACPI_MEMCMP(operand0->buffer.pointer, |
657 | local_operand1->buffer.pointer, | |
4be44fcd | 658 | (length0 > length1) ? length1 : length0); |
1da177e4 LT |
659 | |
660 | switch (opcode) { | |
4be44fcd | 661 | case AML_LEQUAL_OP: /* LEqual (Operand0, Operand1) */ |
1da177e4 LT |
662 | |
663 | /* Length and all bytes must be equal */ | |
664 | ||
4be44fcd | 665 | if ((length0 == length1) && (compare == 0)) { |
52fc0b02 | 666 | |
1da177e4 LT |
667 | /* Length and all bytes match ==> TRUE */ |
668 | ||
669 | local_result = TRUE; | |
670 | } | |
671 | break; | |
672 | ||
4be44fcd | 673 | case AML_LGREATER_OP: /* LGreater (Operand0, Operand1) */ |
1da177e4 LT |
674 | |
675 | if (compare > 0) { | |
676 | local_result = TRUE; | |
4be44fcd | 677 | goto cleanup; /* TRUE */ |
1da177e4 LT |
678 | } |
679 | if (compare < 0) { | |
4be44fcd | 680 | goto cleanup; /* FALSE */ |
1da177e4 LT |
681 | } |
682 | ||
683 | /* Bytes match (to shortest length), compare lengths */ | |
684 | ||
685 | if (length0 > length1) { | |
686 | local_result = TRUE; | |
687 | } | |
688 | break; | |
689 | ||
4be44fcd | 690 | case AML_LLESS_OP: /* LLess (Operand0, Operand1) */ |
1da177e4 LT |
691 | |
692 | if (compare > 0) { | |
4be44fcd | 693 | goto cleanup; /* FALSE */ |
1da177e4 LT |
694 | } |
695 | if (compare < 0) { | |
696 | local_result = TRUE; | |
4be44fcd | 697 | goto cleanup; /* TRUE */ |
1da177e4 LT |
698 | } |
699 | ||
700 | /* Bytes match (to shortest length), compare lengths */ | |
701 | ||
702 | if (length0 < length1) { | |
703 | local_result = TRUE; | |
704 | } | |
705 | break; | |
706 | ||
707 | default: | |
708 | status = AE_AML_INTERNAL; | |
709 | break; | |
710 | } | |
711 | } | |
712 | ||
4be44fcd | 713 | cleanup: |
1da177e4 LT |
714 | |
715 | /* New object was created if implicit conversion performed - delete */ | |
716 | ||
717 | if (local_operand1 != operand1) { | |
4be44fcd | 718 | acpi_ut_remove_reference(local_operand1); |
1da177e4 LT |
719 | } |
720 | ||
721 | /* Return the logical result and status */ | |
722 | ||
723 | *logical_result = local_result; | |
4be44fcd | 724 | return_ACPI_STATUS(status); |
1da177e4 | 725 | } |