1
2 /******************************************************************************
3 *
4 * Module Name: exmisc - ACPI AML (p-code) execution - specific opcodes
5 *
6 *****************************************************************************/
7
8 /*
9 * Copyright (C) 2000 - 2011, Intel Corp.
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.
99 */
100 switch (ObjDesc->Reference.Class)
101 {
102 case ACPI_REFCLASS_LOCAL:
103 case ACPI_REFCLASS_ARG:
104 case ACPI_REFCLASS_DEBUG:
105
106 /* The referenced object is the pseudo-node for the local/arg */
107
108 ReferencedObj = ObjDesc->Reference.Object;
109 break;
110
111 default:
112
113 ACPI_ERROR ((AE_INFO, "Unknown Reference Class 0x%2.2X",
114 ObjDesc->Reference.Class));
115 return_ACPI_STATUS (AE_AML_INTERNAL);
116 }
117 break;
118
119
120 case ACPI_DESC_TYPE_NAMED:
121
122 /*
123 * A named reference that has already been resolved to a Node
124 */
125 ReferencedObj = ObjDesc;
126 break;
127
128
129 default:
130
131 ACPI_ERROR ((AE_INFO, "Invalid descriptor type 0x%X",
132 ACPI_GET_DESCRIPTOR_TYPE (ObjDesc)));
133 return_ACPI_STATUS (AE_TYPE);
134 }
135
136
137 /* Create a new reference object */
138
139 ReferenceObj = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
140 if (!ReferenceObj)
141 {
142 return_ACPI_STATUS (AE_NO_MEMORY);
143 }
144
145 ReferenceObj->Reference.Class = ACPI_REFCLASS_REFOF;
146 ReferenceObj->Reference.Object = ReferencedObj;
147 *ReturnDesc = ReferenceObj;
148
270 {
271 ACPI_OPERAND_OBJECT *LocalOperand1 = Operand1;
272 ACPI_OPERAND_OBJECT *ReturnDesc;
273 char *NewBuf;
274 ACPI_STATUS Status;
275
276
277 ACPI_FUNCTION_TRACE (ExDoConcatenate);
278
279
280 /*
281 * Convert the second operand if necessary. The first operand
282 * determines the type of the second operand, (See the Data Types
283 * section of the ACPI specification.) Both object types are
284 * guaranteed to be either Integer/String/Buffer by the operand
285 * resolution mechanism.
286 */
287 switch (Operand0->Common.Type)
288 {
289 case ACPI_TYPE_INTEGER:
290 Status = AcpiExConvertToInteger (Operand1, &LocalOperand1, 16);
291 break;
292
293 case ACPI_TYPE_STRING:
294 Status = AcpiExConvertToString (Operand1, &LocalOperand1,
295 ACPI_IMPLICIT_CONVERT_HEX);
296 break;
297
298 case ACPI_TYPE_BUFFER:
299 Status = AcpiExConvertToBuffer (Operand1, &LocalOperand1);
300 break;
301
302 default:
303 ACPI_ERROR ((AE_INFO, "Invalid object type: 0x%X",
304 Operand0->Common.Type));
305 Status = AE_AML_INTERNAL;
306 }
307
308 if (ACPI_FAILURE (Status))
309 {
310 goto Cleanup;
311 }
312
313 /*
314 * Both operands are now known to be the same object type
315 * (Both are Integer, String, or Buffer), and we can now perform the
316 * concatenation.
317 */
318
319 /*
320 * There are three cases to handle:
321 *
322 * 1) Two Integers concatenated to produce a new Buffer
434 * to obtain the operands.
435 *
436 ******************************************************************************/
437
438 UINT64
439 AcpiExDoMathOp (
440 UINT16 Opcode,
441 UINT64 Integer0,
442 UINT64 Integer1)
443 {
444
445 ACPI_FUNCTION_ENTRY ();
446
447
448 switch (Opcode)
449 {
450 case AML_ADD_OP: /* Add (Integer0, Integer1, Result) */
451
452 return (Integer0 + Integer1);
453
454
455 case AML_BIT_AND_OP: /* And (Integer0, Integer1, Result) */
456
457 return (Integer0 & Integer1);
458
459
460 case AML_BIT_NAND_OP: /* NAnd (Integer0, Integer1, Result) */
461
462 return (~(Integer0 & Integer1));
463
464
465 case AML_BIT_OR_OP: /* Or (Integer0, Integer1, Result) */
466
467 return (Integer0 | Integer1);
468
469
470 case AML_BIT_NOR_OP: /* NOr (Integer0, Integer1, Result) */
471
472 return (~(Integer0 | Integer1));
473
474
475 case AML_BIT_XOR_OP: /* XOr (Integer0, Integer1, Result) */
476
477 return (Integer0 ^ Integer1);
478
479
480 case AML_MULTIPLY_OP: /* Multiply (Integer0, Integer1, Result) */
481
482 return (Integer0 * Integer1);
483
484
485 case AML_SHIFT_LEFT_OP: /* ShiftLeft (Operand, ShiftCount, Result)*/
486
487 /*
488 * We need to check if the shiftcount is larger than the integer bit
489 * width since the behavior of this is not well-defined in the C language.
490 */
491 if (Integer1 >= AcpiGbl_IntegerBitWidth)
492 {
493 return (0);
494 }
495 return (Integer0 << Integer1);
496
497
498 case AML_SHIFT_RIGHT_OP: /* ShiftRight (Operand, ShiftCount, Result) */
499
500 /*
501 * We need to check if the shiftcount is larger than the integer bit
502 * width since the behavior of this is not well-defined in the C language.
503 */
504 if (Integer1 >= AcpiGbl_IntegerBitWidth)
505 {
506 return (0);
507 }
508 return (Integer0 >> Integer1);
509
510
511 case AML_SUBTRACT_OP: /* Subtract (Integer0, Integer1, Result) */
512
513 return (Integer0 - Integer1);
514
515 default:
516
517 return (0);
518 }
519 }
520
521
522 /*******************************************************************************
523 *
524 * FUNCTION: AcpiExDoLogicalNumericOp
525 *
526 * PARAMETERS: Opcode - AML opcode
527 * Integer0 - Integer operand #0
528 * Integer1 - Integer operand #1
529 * LogicalResult - TRUE/FALSE result of the operation
530 *
555
556 switch (Opcode)
557 {
558 case AML_LAND_OP: /* LAnd (Integer0, Integer1) */
559
560 if (Integer0 && Integer1)
561 {
562 LocalResult = TRUE;
563 }
564 break;
565
566 case AML_LOR_OP: /* LOr (Integer0, Integer1) */
567
568 if (Integer0 || Integer1)
569 {
570 LocalResult = TRUE;
571 }
572 break;
573
574 default:
575 Status = AE_AML_INTERNAL;
576 break;
577 }
578
579 /* Return the logical result and status */
580
581 *LogicalResult = LocalResult;
582 return_ACPI_STATUS (Status);
583 }
584
585
586 /*******************************************************************************
587 *
588 * FUNCTION: AcpiExDoLogicalOp
589 *
590 * PARAMETERS: Opcode - AML opcode
591 * Operand0 - operand #0
592 * Operand1 - operand #1
593 * LogicalResult - TRUE/FALSE result of the operation
594 *
622 UINT32 Length0;
623 UINT32 Length1;
624 ACPI_STATUS Status = AE_OK;
625 BOOLEAN LocalResult = FALSE;
626 int Compare;
627
628
629 ACPI_FUNCTION_TRACE (ExDoLogicalOp);
630
631
632 /*
633 * Convert the second operand if necessary. The first operand
634 * determines the type of the second operand, (See the Data Types
635 * section of the ACPI 3.0+ specification.) Both object types are
636 * guaranteed to be either Integer/String/Buffer by the operand
637 * resolution mechanism.
638 */
639 switch (Operand0->Common.Type)
640 {
641 case ACPI_TYPE_INTEGER:
642 Status = AcpiExConvertToInteger (Operand1, &LocalOperand1, 16);
643 break;
644
645 case ACPI_TYPE_STRING:
646 Status = AcpiExConvertToString (Operand1, &LocalOperand1,
647 ACPI_IMPLICIT_CONVERT_HEX);
648 break;
649
650 case ACPI_TYPE_BUFFER:
651 Status = AcpiExConvertToBuffer (Operand1, &LocalOperand1);
652 break;
653
654 default:
655 Status = AE_AML_INTERNAL;
656 break;
657 }
658
659 if (ACPI_FAILURE (Status))
660 {
661 goto Cleanup;
662 }
663
664 /*
665 * Two cases: 1) Both Integers, 2) Both Strings or Buffers
666 */
667 if (Operand0->Common.Type == ACPI_TYPE_INTEGER)
668 {
669 /*
670 * 1) Both operands are of type integer
671 * Note: LocalOperand1 may have changed above
672 */
673 Integer0 = Operand0->Integer.Value;
674 Integer1 = LocalOperand1->Integer.Value;
683 }
684 break;
685
686 case AML_LGREATER_OP: /* LGreater (Operand0, Operand1) */
687
688 if (Integer0 > Integer1)
689 {
690 LocalResult = TRUE;
691 }
692 break;
693
694 case AML_LLESS_OP: /* LLess (Operand0, Operand1) */
695
696 if (Integer0 < Integer1)
697 {
698 LocalResult = TRUE;
699 }
700 break;
701
702 default:
703 Status = AE_AML_INTERNAL;
704 break;
705 }
706 }
707 else
708 {
709 /*
710 * 2) Both operands are Strings or both are Buffers
711 * Note: Code below takes advantage of common Buffer/String
712 * object fields. LocalOperand1 may have changed above. Use
713 * memcmp to handle nulls in buffers.
714 */
715 Length0 = Operand0->Buffer.Length;
716 Length1 = LocalOperand1->Buffer.Length;
717
718 /* Lexicographic compare: compare the data bytes */
719
720 Compare = ACPI_MEMCMP (Operand0->Buffer.Pointer,
721 LocalOperand1->Buffer.Pointer,
722 (Length0 > Length1) ? Length1 : Length0);
760
761 if (Compare > 0)
762 {
763 goto Cleanup; /* FALSE */
764 }
765 if (Compare < 0)
766 {
767 LocalResult = TRUE;
768 goto Cleanup; /* TRUE */
769 }
770
771 /* Bytes match (to shortest length), compare lengths */
772
773 if (Length0 < Length1)
774 {
775 LocalResult = TRUE;
776 }
777 break;
778
779 default:
780 Status = AE_AML_INTERNAL;
781 break;
782 }
783 }
784
785 Cleanup:
786
787 /* New object was created if implicit conversion performed - delete */
788
789 if (LocalOperand1 != Operand1)
790 {
791 AcpiUtRemoveReference (LocalOperand1);
792 }
793
794 /* Return the logical result and status */
795
796 *LogicalResult = LocalResult;
797 return_ACPI_STATUS (Status);
798 }
799
800
|
1 /******************************************************************************
2 *
3 * Module Name: exmisc - ACPI AML (p-code) execution - specific opcodes
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2014, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
98 */
99 switch (ObjDesc->Reference.Class)
100 {
101 case ACPI_REFCLASS_LOCAL:
102 case ACPI_REFCLASS_ARG:
103 case ACPI_REFCLASS_DEBUG:
104
105 /* The referenced object is the pseudo-node for the local/arg */
106
107 ReferencedObj = ObjDesc->Reference.Object;
108 break;
109
110 default:
111
112 ACPI_ERROR ((AE_INFO, "Unknown Reference Class 0x%2.2X",
113 ObjDesc->Reference.Class));
114 return_ACPI_STATUS (AE_AML_INTERNAL);
115 }
116 break;
117
118 case ACPI_DESC_TYPE_NAMED:
119 /*
120 * A named reference that has already been resolved to a Node
121 */
122 ReferencedObj = ObjDesc;
123 break;
124
125 default:
126
127 ACPI_ERROR ((AE_INFO, "Invalid descriptor type 0x%X",
128 ACPI_GET_DESCRIPTOR_TYPE (ObjDesc)));
129 return_ACPI_STATUS (AE_TYPE);
130 }
131
132
133 /* Create a new reference object */
134
135 ReferenceObj = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
136 if (!ReferenceObj)
137 {
138 return_ACPI_STATUS (AE_NO_MEMORY);
139 }
140
141 ReferenceObj->Reference.Class = ACPI_REFCLASS_REFOF;
142 ReferenceObj->Reference.Object = ReferencedObj;
143 *ReturnDesc = ReferenceObj;
144
266 {
267 ACPI_OPERAND_OBJECT *LocalOperand1 = Operand1;
268 ACPI_OPERAND_OBJECT *ReturnDesc;
269 char *NewBuf;
270 ACPI_STATUS Status;
271
272
273 ACPI_FUNCTION_TRACE (ExDoConcatenate);
274
275
276 /*
277 * Convert the second operand if necessary. The first operand
278 * determines the type of the second operand, (See the Data Types
279 * section of the ACPI specification.) Both object types are
280 * guaranteed to be either Integer/String/Buffer by the operand
281 * resolution mechanism.
282 */
283 switch (Operand0->Common.Type)
284 {
285 case ACPI_TYPE_INTEGER:
286
287 Status = AcpiExConvertToInteger (Operand1, &LocalOperand1, 16);
288 break;
289
290 case ACPI_TYPE_STRING:
291
292 Status = AcpiExConvertToString (Operand1, &LocalOperand1,
293 ACPI_IMPLICIT_CONVERT_HEX);
294 break;
295
296 case ACPI_TYPE_BUFFER:
297
298 Status = AcpiExConvertToBuffer (Operand1, &LocalOperand1);
299 break;
300
301 default:
302
303 ACPI_ERROR ((AE_INFO, "Invalid object type: 0x%X",
304 Operand0->Common.Type));
305 Status = AE_AML_INTERNAL;
306 }
307
308 if (ACPI_FAILURE (Status))
309 {
310 goto Cleanup;
311 }
312
313 /*
314 * Both operands are now known to be the same object type
315 * (Both are Integer, String, or Buffer), and we can now perform the
316 * concatenation.
317 */
318
319 /*
320 * There are three cases to handle:
321 *
322 * 1) Two Integers concatenated to produce a new Buffer
434 * to obtain the operands.
435 *
436 ******************************************************************************/
437
438 UINT64
439 AcpiExDoMathOp (
440 UINT16 Opcode,
441 UINT64 Integer0,
442 UINT64 Integer1)
443 {
444
445 ACPI_FUNCTION_ENTRY ();
446
447
448 switch (Opcode)
449 {
450 case AML_ADD_OP: /* Add (Integer0, Integer1, Result) */
451
452 return (Integer0 + Integer1);
453
454 case AML_BIT_AND_OP: /* And (Integer0, Integer1, Result) */
455
456 return (Integer0 & Integer1);
457
458 case AML_BIT_NAND_OP: /* NAnd (Integer0, Integer1, Result) */
459
460 return (~(Integer0 & Integer1));
461
462 case AML_BIT_OR_OP: /* Or (Integer0, Integer1, Result) */
463
464 return (Integer0 | Integer1);
465
466 case AML_BIT_NOR_OP: /* NOr (Integer0, Integer1, Result) */
467
468 return (~(Integer0 | Integer1));
469
470 case AML_BIT_XOR_OP: /* XOr (Integer0, Integer1, Result) */
471
472 return (Integer0 ^ Integer1);
473
474 case AML_MULTIPLY_OP: /* Multiply (Integer0, Integer1, Result) */
475
476 return (Integer0 * Integer1);
477
478 case AML_SHIFT_LEFT_OP: /* ShiftLeft (Operand, ShiftCount, Result)*/
479
480 /*
481 * We need to check if the shiftcount is larger than the integer bit
482 * width since the behavior of this is not well-defined in the C language.
483 */
484 if (Integer1 >= AcpiGbl_IntegerBitWidth)
485 {
486 return (0);
487 }
488 return (Integer0 << Integer1);
489
490 case AML_SHIFT_RIGHT_OP: /* ShiftRight (Operand, ShiftCount, Result) */
491
492 /*
493 * We need to check if the shiftcount is larger than the integer bit
494 * width since the behavior of this is not well-defined in the C language.
495 */
496 if (Integer1 >= AcpiGbl_IntegerBitWidth)
497 {
498 return (0);
499 }
500 return (Integer0 >> Integer1);
501
502 case AML_SUBTRACT_OP: /* Subtract (Integer0, Integer1, Result) */
503
504 return (Integer0 - Integer1);
505
506 default:
507
508 return (0);
509 }
510 }
511
512
513 /*******************************************************************************
514 *
515 * FUNCTION: AcpiExDoLogicalNumericOp
516 *
517 * PARAMETERS: Opcode - AML opcode
518 * Integer0 - Integer operand #0
519 * Integer1 - Integer operand #1
520 * LogicalResult - TRUE/FALSE result of the operation
521 *
546
547 switch (Opcode)
548 {
549 case AML_LAND_OP: /* LAnd (Integer0, Integer1) */
550
551 if (Integer0 && Integer1)
552 {
553 LocalResult = TRUE;
554 }
555 break;
556
557 case AML_LOR_OP: /* LOr (Integer0, Integer1) */
558
559 if (Integer0 || Integer1)
560 {
561 LocalResult = TRUE;
562 }
563 break;
564
565 default:
566
567 Status = AE_AML_INTERNAL;
568 break;
569 }
570
571 /* Return the logical result and status */
572
573 *LogicalResult = LocalResult;
574 return_ACPI_STATUS (Status);
575 }
576
577
578 /*******************************************************************************
579 *
580 * FUNCTION: AcpiExDoLogicalOp
581 *
582 * PARAMETERS: Opcode - AML opcode
583 * Operand0 - operand #0
584 * Operand1 - operand #1
585 * LogicalResult - TRUE/FALSE result of the operation
586 *
614 UINT32 Length0;
615 UINT32 Length1;
616 ACPI_STATUS Status = AE_OK;
617 BOOLEAN LocalResult = FALSE;
618 int Compare;
619
620
621 ACPI_FUNCTION_TRACE (ExDoLogicalOp);
622
623
624 /*
625 * Convert the second operand if necessary. The first operand
626 * determines the type of the second operand, (See the Data Types
627 * section of the ACPI 3.0+ specification.) Both object types are
628 * guaranteed to be either Integer/String/Buffer by the operand
629 * resolution mechanism.
630 */
631 switch (Operand0->Common.Type)
632 {
633 case ACPI_TYPE_INTEGER:
634
635 Status = AcpiExConvertToInteger (Operand1, &LocalOperand1, 16);
636 break;
637
638 case ACPI_TYPE_STRING:
639
640 Status = AcpiExConvertToString (Operand1, &LocalOperand1,
641 ACPI_IMPLICIT_CONVERT_HEX);
642 break;
643
644 case ACPI_TYPE_BUFFER:
645
646 Status = AcpiExConvertToBuffer (Operand1, &LocalOperand1);
647 break;
648
649 default:
650
651 Status = AE_AML_INTERNAL;
652 break;
653 }
654
655 if (ACPI_FAILURE (Status))
656 {
657 goto Cleanup;
658 }
659
660 /*
661 * Two cases: 1) Both Integers, 2) Both Strings or Buffers
662 */
663 if (Operand0->Common.Type == ACPI_TYPE_INTEGER)
664 {
665 /*
666 * 1) Both operands are of type integer
667 * Note: LocalOperand1 may have changed above
668 */
669 Integer0 = Operand0->Integer.Value;
670 Integer1 = LocalOperand1->Integer.Value;
679 }
680 break;
681
682 case AML_LGREATER_OP: /* LGreater (Operand0, Operand1) */
683
684 if (Integer0 > Integer1)
685 {
686 LocalResult = TRUE;
687 }
688 break;
689
690 case AML_LLESS_OP: /* LLess (Operand0, Operand1) */
691
692 if (Integer0 < Integer1)
693 {
694 LocalResult = TRUE;
695 }
696 break;
697
698 default:
699
700 Status = AE_AML_INTERNAL;
701 break;
702 }
703 }
704 else
705 {
706 /*
707 * 2) Both operands are Strings or both are Buffers
708 * Note: Code below takes advantage of common Buffer/String
709 * object fields. LocalOperand1 may have changed above. Use
710 * memcmp to handle nulls in buffers.
711 */
712 Length0 = Operand0->Buffer.Length;
713 Length1 = LocalOperand1->Buffer.Length;
714
715 /* Lexicographic compare: compare the data bytes */
716
717 Compare = ACPI_MEMCMP (Operand0->Buffer.Pointer,
718 LocalOperand1->Buffer.Pointer,
719 (Length0 > Length1) ? Length1 : Length0);
757
758 if (Compare > 0)
759 {
760 goto Cleanup; /* FALSE */
761 }
762 if (Compare < 0)
763 {
764 LocalResult = TRUE;
765 goto Cleanup; /* TRUE */
766 }
767
768 /* Bytes match (to shortest length), compare lengths */
769
770 if (Length0 < Length1)
771 {
772 LocalResult = TRUE;
773 }
774 break;
775
776 default:
777
778 Status = AE_AML_INTERNAL;
779 break;
780 }
781 }
782
783 Cleanup:
784
785 /* New object was created if implicit conversion performed - delete */
786
787 if (LocalOperand1 != Operand1)
788 {
789 AcpiUtRemoveReference (LocalOperand1);
790 }
791
792 /* Return the logical result and status */
793
794 *LogicalResult = LocalResult;
795 return_ACPI_STATUS (Status);
796 }
|