[ACPI] ACPICA 20051117
[deliverable/linux.git] / drivers / acpi / executer / exmisc.c
CommitLineData
1da177e4
LT
1
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
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 51ACPI_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 67acpi_status
4be44fcd
LB
68acpi_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
4be44fcd 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
4be44fcd
LB
101 ACPI_REPORT_ERROR(("Unknown Reference opcode in get_reference %X\n", obj_desc->reference.opcode));
102 return_ACPI_STATUS(AE_AML_INTERNAL);
1da177e4
LT
103 }
104 break;
105
1da177e4
LT
106 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
1da177e4
LT
114 default:
115
4be44fcd
LB
116 ACPI_REPORT_ERROR(("Invalid descriptor type in get_reference: %X\n", ACPI_GET_DESCRIPTOR_TYPE(obj_desc)));
117 return_ACPI_STATUS(AE_TYPE);
1da177e4
LT
118 }
119
1da177e4
LT
120 /* Create a new reference object */
121
4be44fcd
LB
122 reference_obj =
123 acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_REFERENCE);
1da177e4 124 if (!reference_obj) {
4be44fcd 125 return_ACPI_STATUS(AE_NO_MEMORY);
1da177e4
LT
126 }
127
128 reference_obj->reference.opcode = AML_REF_OF_OP;
129 reference_obj->reference.object = referenced_obj;
130 *return_desc = reference_obj;
131
4be44fcd
LB
132 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));
1da177e4 136
4be44fcd 137 return_ACPI_STATUS(AE_OK);
1da177e4
LT
138}
139
1da177e4
LT
140/*******************************************************************************
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
4be44fcd
LB
156acpi_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)
1da177e4 160{
96db255c 161 acpi_status status;
4be44fcd
LB
162 union acpi_operand_object *return_desc;
163 u8 *new_buf;
96db255c
BM
164 u8 *end_tag;
165 acpi_size length0;
4be44fcd 166 acpi_size length1;
1da177e4 167
4be44fcd 168 ACPI_FUNCTION_TRACE("ex_concat_template");
1da177e4 169
96db255c
BM
170 /*
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);
179 }
180
181 length0 = ACPI_PTR_DIFF(end_tag, operand0->buffer.pointer);
1da177e4 182
96db255c
BM
183 status = acpi_ut_get_resource_end_tag(operand1, &end_tag);
184 if (ACPI_FAILURE(status)) {
185 return_ACPI_STATUS(status);
1da177e4
LT
186 }
187
96db255c 188 /* Include the end_tag in the second template length */
1da177e4 189
96db255c
BM
190 length1 = ACPI_PTR_DIFF(end_tag, operand1->buffer.pointer) +
191 sizeof(struct aml_resource_end_tag);
1da177e4
LT
192
193 /* Create a new buffer object for the result */
194
96db255c 195 return_desc = acpi_ut_create_buffer_object(length0 + length1);
1da177e4 196 if (!return_desc) {
4be44fcd 197 return_ACPI_STATUS(AE_NO_MEMORY);
1da177e4
LT
198 }
199
96db255c
BM
200 /*
201 * Copy the templates to the new buffer, 0 first, then 1 follows. One
202 * end_tag descriptor is copied from Operand1.
203 */
1da177e4 204 new_buf = return_desc->buffer.pointer;
96db255c
BM
205 ACPI_MEMCPY(new_buf, operand0->buffer.pointer, length0);
206 ACPI_MEMCPY(new_buf + length0, operand1->buffer.pointer, length1);
1da177e4 207
c51a4de8 208 /* Set the end_tag checksum to zero, means "ignore checksum" */
1da177e4 209
c51a4de8 210 new_buf[return_desc->buffer.length - 1] = 0;
1da177e4 211
96db255c 212 /* Return the completed resource template */
1da177e4
LT
213
214 *actual_return_desc = return_desc;
4be44fcd 215 return_ACPI_STATUS(AE_OK);
1da177e4
LT
216}
217
1da177e4
LT
218/*******************************************************************************
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
4be44fcd
LB
234acpi_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)
1da177e4 238{
4be44fcd
LB
239 union acpi_operand_object *local_operand1 = operand1;
240 union acpi_operand_object *return_desc;
241 char *new_buf;
242 acpi_status status;
1da177e4 243
4be44fcd 244 ACPI_FUNCTION_TRACE("ex_do_concatenate");
1da177e4
LT
245
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 */
4be44fcd 253 switch (ACPI_GET_OBJECT_TYPE(operand0)) {
1da177e4 254 case ACPI_TYPE_INTEGER:
4be44fcd
LB
255 status =
256 acpi_ex_convert_to_integer(operand1, &local_operand1, 16);
1da177e4
LT
257 break;
258
259 case ACPI_TYPE_STRING:
4be44fcd
LB
260 status = acpi_ex_convert_to_string(operand1, &local_operand1,
261 ACPI_IMPLICIT_CONVERT_HEX);
1da177e4
LT
262 break;
263
264 case ACPI_TYPE_BUFFER:
4be44fcd 265 status = acpi_ex_convert_to_buffer(operand1, &local_operand1);
1da177e4
LT
266 break;
267
268 default:
c51a4de8 269 ACPI_REPORT_ERROR(("Concatanate - invalid object type: %X\n",
4be44fcd 270 ACPI_GET_OBJECT_TYPE(operand0)));
1da177e4
LT
271 status = AE_AML_INTERNAL;
272 }
273
4be44fcd 274 if (ACPI_FAILURE(status)) {
1da177e4
LT
275 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 */
4be44fcd 291 switch (ACPI_GET_OBJECT_TYPE(operand0)) {
1da177e4
LT
292 case ACPI_TYPE_INTEGER:
293
294 /* Result of two Integers is a Buffer */
295 /* Need enough buffer space for two integers */
296
4be44fcd
LB
297 return_desc = acpi_ut_create_buffer_object((acpi_size)
298 ACPI_MUL_2
299 (acpi_gbl_integer_byte_width));
1da177e4
LT
300 if (!return_desc) {
301 status = AE_NO_MEMORY;
302 goto cleanup;
303 }
304
4be44fcd 305 new_buf = (char *)return_desc->buffer.pointer;
1da177e4
LT
306
307 /* Copy the first integer, LSB first */
308
c51a4de8 309 ACPI_MEMCPY(new_buf, &operand0->integer.value,
4be44fcd 310 acpi_gbl_integer_byte_width);
1da177e4
LT
311
312 /* Copy the second integer (LSB first) after the first */
313
4be44fcd
LB
314 ACPI_MEMCPY(new_buf + acpi_gbl_integer_byte_width,
315 &local_operand1->integer.value,
316 acpi_gbl_integer_byte_width);
1da177e4
LT
317 break;
318
319 case ACPI_TYPE_STRING:
320
321 /* Result of two Strings is a String */
322
c51a4de8
BM
323 return_desc = acpi_ut_create_string_object((acpi_size)
324 (operand0->string.
325 length +
326 local_operand1->
327 string.length));
1da177e4
LT
328 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
4be44fcd
LB
337 ACPI_STRCPY(new_buf, operand0->string.pointer);
338 ACPI_STRCPY(new_buf + operand0->string.length,
339 local_operand1->string.pointer);
1da177e4
LT
340 break;
341
342 case ACPI_TYPE_BUFFER:
343
344 /* Result of two Buffers is a Buffer */
345
4be44fcd 346 return_desc = acpi_ut_create_buffer_object((acpi_size)
c51a4de8
BM
347 (operand0->buffer.
348 length +
349 local_operand1->
350 buffer.length));
1da177e4
LT
351 if (!return_desc) {
352 status = AE_NO_MEMORY;
353 goto cleanup;
354 }
355
4be44fcd 356 new_buf = (char *)return_desc->buffer.pointer;
1da177e4
LT
357
358 /* Concatenate the buffers */
359
c51a4de8
BM
360 ACPI_MEMCPY(new_buf, operand0->buffer.pointer,
361 operand0->buffer.length);
4be44fcd
LB
362 ACPI_MEMCPY(new_buf + operand0->buffer.length,
363 local_operand1->buffer.pointer,
364 local_operand1->buffer.length);
1da177e4
LT
365 break;
366
367 default:
368
369 /* Invalid object type, should not happen here */
370
4be44fcd
LB
371 ACPI_REPORT_ERROR(("Concatenate - Invalid object type: %X\n",
372 ACPI_GET_OBJECT_TYPE(operand0)));
373 status = AE_AML_INTERNAL;
1da177e4
LT
374 goto cleanup;
375 }
376
377 *actual_return_desc = return_desc;
378
4be44fcd 379 cleanup:
1da177e4 380 if (local_operand1 != operand1) {
4be44fcd 381 acpi_ut_remove_reference(local_operand1);
1da177e4 382 }
4be44fcd 383 return_ACPI_STATUS(status);
1da177e4
LT
384}
385
1da177e4
LT
386/*******************************************************************************
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
4be44fcd 403acpi_ex_do_math_op(u16 opcode, acpi_integer integer0, acpi_integer integer1)
1da177e4
LT
404{
405
4be44fcd 406 ACPI_FUNCTION_ENTRY();
1da177e4
LT
407
408 switch (opcode) {
4be44fcd 409 case AML_ADD_OP: /* Add (Integer0, Integer1, Result) */
1da177e4
LT
410
411 return (integer0 + integer1);
412
4be44fcd 413 case AML_BIT_AND_OP: /* And (Integer0, Integer1, Result) */
1da177e4
LT
414
415 return (integer0 & integer1);
416
4be44fcd 417 case AML_BIT_NAND_OP: /* NAnd (Integer0, Integer1, Result) */
1da177e4
LT
418
419 return (~(integer0 & integer1));
420
4be44fcd 421 case AML_BIT_OR_OP: /* Or (Integer0, Integer1, Result) */
1da177e4
LT
422
423 return (integer0 | integer1);
424
4be44fcd 425 case AML_BIT_NOR_OP: /* NOr (Integer0, Integer1, Result) */
1da177e4
LT
426
427 return (~(integer0 | integer1));
428
4be44fcd 429 case AML_BIT_XOR_OP: /* XOr (Integer0, Integer1, Result) */
1da177e4
LT
430
431 return (integer0 ^ integer1);
432
4be44fcd 433 case AML_MULTIPLY_OP: /* Multiply (Integer0, Integer1, Result) */
1da177e4
LT
434
435 return (integer0 * integer1);
436
4be44fcd 437 case AML_SHIFT_LEFT_OP: /* shift_left (Operand, shift_count, Result) */
1da177e4
LT
438
439 return (integer0 << integer1);
440
4be44fcd 441 case AML_SHIFT_RIGHT_OP: /* shift_right (Operand, shift_count, Result) */
1da177e4
LT
442
443 return (integer0 >> integer1);
444
4be44fcd 445 case AML_SUBTRACT_OP: /* Subtract (Integer0, Integer1, Result) */
1da177e4
LT
446
447 return (integer0 - integer1);
448
449 default:
450
451 return (0);
452 }
453}
454
1da177e4
LT
455/*******************************************************************************
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
4be44fcd
LB
476acpi_ex_do_logical_numeric_op(u16 opcode,
477 acpi_integer integer0,
478 acpi_integer integer1, u8 * logical_result)
1da177e4 479{
4be44fcd
LB
480 acpi_status status = AE_OK;
481 u8 local_result = FALSE;
1da177e4 482
4be44fcd 483 ACPI_FUNCTION_TRACE("ex_do_logical_numeric_op");
1da177e4
LT
484
485 switch (opcode) {
4be44fcd 486 case AML_LAND_OP: /* LAnd (Integer0, Integer1) */
1da177e4
LT
487
488 if (integer0 && integer1) {
489 local_result = TRUE;
490 }
491 break;
492
4be44fcd 493 case AML_LOR_OP: /* LOr (Integer0, Integer1) */
1da177e4
LT
494
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;
4be44fcd 508 return_ACPI_STATUS(status);
1da177e4
LT
509}
510
1da177e4
LT
511/*******************************************************************************
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
4be44fcd
LB
538acpi_ex_do_logical_op(u16 opcode,
539 union acpi_operand_object *operand0,
540 union acpi_operand_object *operand1, u8 * logical_result)
1da177e4 541{
4be44fcd
LB
542 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;
1da177e4 550
4be44fcd 551 ACPI_FUNCTION_TRACE("ex_do_logical_op");
1da177e4
LT
552
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 */
4be44fcd 560 switch (ACPI_GET_OBJECT_TYPE(operand0)) {
1da177e4 561 case ACPI_TYPE_INTEGER:
4be44fcd
LB
562 status =
563 acpi_ex_convert_to_integer(operand1, &local_operand1, 16);
1da177e4
LT
564 break;
565
566 case ACPI_TYPE_STRING:
4be44fcd
LB
567 status = acpi_ex_convert_to_string(operand1, &local_operand1,
568 ACPI_IMPLICIT_CONVERT_HEX);
1da177e4
LT
569 break;
570
571 case ACPI_TYPE_BUFFER:
4be44fcd 572 status = acpi_ex_convert_to_buffer(operand1, &local_operand1);
1da177e4
LT
573 break;
574
575 default:
576 status = AE_AML_INTERNAL;
577 break;
578 }
579
4be44fcd 580 if (ACPI_FAILURE(status)) {
1da177e4
LT
581 goto cleanup;
582 }
583
584 /*
585 * Two cases: 1) Both Integers, 2) Both Strings or Buffers
586 */
4be44fcd 587 if (ACPI_GET_OBJECT_TYPE(operand0) == ACPI_TYPE_INTEGER) {
1da177e4
LT
588 /*
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) {
4be44fcd 596 case AML_LEQUAL_OP: /* LEqual (Operand0, Operand1) */
1da177e4
LT
597
598 if (integer0 == integer1) {
599 local_result = TRUE;
600 }
601 break;
602
4be44fcd 603 case AML_LGREATER_OP: /* LGreater (Operand0, Operand1) */
1da177e4
LT
604
605 if (integer0 > integer1) {
606 local_result = TRUE;
607 }
608 break;
609
4be44fcd 610 case AML_LLESS_OP: /* LLess (Operand0, Operand1) */
1da177e4
LT
611
612 if (integer0 < integer1) {
613 local_result = TRUE;
614 }
615 break;
616
617 default:
618 status = AE_AML_INTERNAL;
619 break;
620 }
4be44fcd 621 } else {
1da177e4
LT
622 /*
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
0897831b
BM
633 compare = ACPI_MEMCMP(operand0->buffer.pointer,
634 local_operand1->buffer.pointer,
4be44fcd 635 (length0 > length1) ? length1 : length0);
1da177e4
LT
636
637 switch (opcode) {
4be44fcd 638 case AML_LEQUAL_OP: /* LEqual (Operand0, Operand1) */
1da177e4
LT
639
640 /* Length and all bytes must be equal */
641
4be44fcd 642 if ((length0 == length1) && (compare == 0)) {
1da177e4
LT
643 /* Length and all bytes match ==> TRUE */
644
645 local_result = TRUE;
646 }
647 break;
648
4be44fcd 649 case AML_LGREATER_OP: /* LGreater (Operand0, Operand1) */
1da177e4
LT
650
651 if (compare > 0) {
652 local_result = TRUE;
4be44fcd 653 goto cleanup; /* TRUE */
1da177e4
LT
654 }
655 if (compare < 0) {
4be44fcd 656 goto cleanup; /* FALSE */
1da177e4
LT
657 }
658
659 /* Bytes match (to shortest length), compare lengths */
660
661 if (length0 > length1) {
662 local_result = TRUE;
663 }
664 break;
665
4be44fcd 666 case AML_LLESS_OP: /* LLess (Operand0, Operand1) */
1da177e4
LT
667
668 if (compare > 0) {
4be44fcd 669 goto cleanup; /* FALSE */
1da177e4
LT
670 }
671 if (compare < 0) {
672 local_result = TRUE;
4be44fcd 673 goto cleanup; /* TRUE */
1da177e4
LT
674 }
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
4be44fcd 689 cleanup:
1da177e4
LT
690
691 /* New object was created if implicit conversion performed - delete */
692
693 if (local_operand1 != operand1) {
4be44fcd 694 acpi_ut_remove_reference(local_operand1);
1da177e4
LT
695 }
696
697 /* Return the logical result and status */
698
699 *logical_result = local_result;
4be44fcd 700 return_ACPI_STATUS(status);
1da177e4 701}
This page took 0.078247 seconds and 5 git commands to generate.